# Automatically Fix Phone Numbers with Country Code in DoubleTick

In today’s digital communication landscape, businesses rely heavily on WhatsApp to connect with customers quickly and efficiently.

However, WhatsApp requires phone numbers to be stored in a specific international format. If customer phone numbers are collected without a country code, message delivery can fail.

This guide explains how to use a Number Correction API in DoubleTick to automatically format phone numbers with the correct country code before sending WhatsApp messages or templates.

***

### Why Phone Number Formatting Matters

Customer phone numbers often enter the system through sources such as:

* Google Sheets
* Website forms
* Webhooks
* CRM integrations

In many cases, these numbers are stored like this:

```
7038896140
```

But WhatsApp requires numbers in E.164 international format, such as:

```
+917038896140
```

If the country code is missing, WhatsApp message delivery will not work.

***

### What is the Number Correction API?

The Number Correction API acts as an intermediary that:

* Receives an unformatted phone number
* Applies the correct country code
* Returns the number in WhatsApp-compatible format

This ensures that all customer data stored in DoubleTick is ready for WhatsApp communication.

***

### How the Number Correction API Works

The workflow is as follows:

#### Step 1: Receive Raw Customer Data

A new lead is received from Google Sheets, Webhook, or another integration. The phone number may not include a country code.

Example:

```
Phone: 7038896140
Country: India
```

***

#### Step 2: Call the Number Correction API

The bot sends the raw number and country information to the Number Correction API.

***

#### Step 3: API Formats the Number

The API converts the number into the correct E.164 format:

```
+917038896140
```

***

#### Step 4: Update the Corrected Number in DoubleTick

The formatted number is stored in DoubleTick and becomes ready for WhatsApp messaging.

***

#### Step 5: Send WhatsApp Templates Successfully

Once the number is corrected, templates and automated WhatsApp messages can be sent without interruption.

***

## Implementing Number Correction in DoubleTick Bot Studio

This section explains how to set up this automation step-by-step.

***

### Step 1: Identify Your Incoming Data Source

First, confirm where customer phone numbers are coming from:

| Source          | Trigger Example          |
| --------------- | ------------------------ |
| Google Sheets   | New row added            |
| Webhook         | Form submission received |
| CRM Integration | New contact created      |

The Number Correction API should be triggered every time a new lead enters DoubleTick.

***

### Step 2: Set Up the Bot Trigger in Bot Studio

Open **Bot Studio** in DoubleTick and select the appropriate starting trigger:

#### If leads come from Google Sheets

Choose:

**On New Row in Google Sheet**

This will trigger the bot whenever a new row is added.

***

#### If leads come from a Webhook

Choose:

**On Webhook**

This will trigger the bot whenever external data is received.

***

### Step 3: Call the Number Correction API

Once the bot starts, the next step is to correct the phone number.

<figure><img src="https://2303112206-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F53n17VnOICC1LtDqlENV%2Fuploads%2FAdcn34ahvq0BGo003KKF%2FScreenshot%202024-11-19%20at%2015.28.48.png?alt=media&#x26;token=14bac1e3-8735-400d-87dc-d98f819b9511" alt=""><figcaption></figcaption></figure>

#### A) Add a Call API Action

1. Click the **+** icon in the bot flow
2. Select **Call API**
3. Connect it to the trigger node

***

#### B) Create the Number Correction API

Inside the Call API block:

1. Click **+ Create New API**
2. Enter the following details:

***

<figure><img src="https://2303112206-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F53n17VnOICC1LtDqlENV%2Fuploads%2F6amSNgHnfSYZ1mjg3PYa%2FScreenshot%202024-11-19%20at%2015.33.09.png?alt=media&#x26;token=95b286af-4efa-43c6-a37e-800a6e706d6d" alt=""><figcaption></figcaption></figure>

**API Endpoint**

```
https://b1ge7k5vbf.execute-api.ap-south-1.amazonaws.com/prod
```

***

**Method**

POST

***

**Body Type**

JSON

***

**Request Body Example**

```json
{
  "defaultCountryCode": "IN",
  "numbers": [
    {
      "value": "7038896140"
    }
  ]
}
```

***

#### Explanation of Fields

| Field              | Description                         |
| ------------------ | ----------------------------------- |
| defaultCountryCode | Country code to apply automatically |
| IN                 | India                               |
| value              | Customer’s raw phone number         |

Save the API after entering these details.

***

### Step 4: Send the Corrected Number Back to DoubleTick Using Webhook

Now that the first API returns the corrected number, the next step is to store it inside DoubleTick.

***

<figure><img src="https://2303112206-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F53n17VnOICC1LtDqlENV%2Fuploads%2FFZnWHr2c1udsNZ1a7mqm%2FScreenshot%202024-11-19%20at%2015.36.42.png?alt=media&#x26;token=e7e04d61-953d-479b-b800-38f414608790" alt=""><figcaption></figcaption></figure>

#### A) Add a Second Call API Action

1. Click **+ Add Action**
2. Select **Call API** again

This second API will be used to send the corrected number forward.

***

#### B) Create a Webhook API

1. Click **+ Create New API**
2. Paste your webhook URL
3. Set the body type to JSON

***

**Sample JSON Body**

```json
{
  "phone": "+918356867936"
}
```

***

#### C) Map the Corrected Phone Number Automatically

Instead of typing a number manually:

1. Click inside the `"phone"` field
2. Select the response output from the first API call
3. Choose:

```
0.E164
```

This ensures the webhook always receives the corrected WhatsApp-ready phone number.

***

### Step 5: Capture Response

<figure><img src="https://2303112206-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F53n17VnOICC1LtDqlENV%2Fuploads%2F45z07LuLjFQKwdnDLW53%2FUntitleddesign13-ezgif.com-video-to-gif-converter.gif?alt=media&#x26;token=d3af38f9-59f3-4fc9-9236-3e59f1b01fdb" alt=""><figcaption></figcaption></figure>

To confirm the workflow is functioning correctly:

1. Open the second webhook Call API block
2. Click **Capture Response**

This will display the final phone number with the correct country code applied.

***

## Final Outcome

With this automation in place:

* Phone numbers coming from external sources are corrected automatically
* All customer data stored in DoubleTick becomes WhatsApp-ready
* Message and template delivery works without formatting errors

Example conversion:

```
7038896140
```

Becomes:

```
+917038896140
```

***

## Recommended Use Cases

This setup is useful when:

* Leads are imported from Google Sheets
* Forms collect numbers without country codes
* Businesses deal with multiple regions
* WhatsApp template sending must remain uninterrupted
