Skip to main content

Create a WhatsApp connection

With this endpoint, you will be able to create a new QR-code based WhatsApp connection in your account.

Parameters

These parameters should be sent as a JSON payload in the request body.

FieldDescriptionExample values
phone_numberThe number you want to connect to 2Chat+18647351567
friendly_nameA name or alias for the numberMy business number

Invocation

curl -X POST --location 'https://api.p.2chat.io/open/whatsapp/channel/create' \
--header 'Content-Type: application/json' \
--header 'X-User-API-Key: your_api_key_here' \
--data '{
"phone_number": "+18647351567",
"friendly_name": "Testing number creation"
}'

Response

If the number didn't exist and the creation was successful, you will see the following output and immediately after the number will try to connect and generate a QR code that you will need to scan.

To get that QR code information you need to call the Channel Status Endpoint using the UUID value (WPNf3ea6c85-0dca-4d8a-a9a6-2b918f59cc97) you obtained in this step.

tip

You can also get the UUID of a number you want to manipulate with the List Numbers Endpoint.

{
"success": true,
"channel": {
"id": "WPNf3ea6c85-0dca-4d8a-a9a6-2b918f59cc97",
"uuid": "WPNf3ea6c85-0dca-4d8a-a9a6-2b918f59cc97",
"friendly_name": "Testing number creation now",
"phone_number": "+18647351566",
"iso_country_code": "US",
"pushname": null,
"server": null,
"platform": null,
"connection_status": "D",
"enabled": true,
"is_business_profile": false,
"channel_type": "WW",
"sync_contacts": false,
"timezone": "America/New_York",
"lang": "en",
"created_at": "2023-10-12T17:43:58Z",
"updated_at": null
}
}

Getting the QR Code to connect the number

Once the channel is created, the connect command will be executed immediately getting the number ready for establishing a QR code connection.

You have 2 options to get the QR code:

  1. Subscribe to the Channel Status Webhook and get the QR code value in real-time.
  2. Explicitly obtain the latest QR code received using the following endpoint:

Invocation

Using the UUID (WPNf3ea6c85-0dca-4d8a-a9a6-2b918f59cc97) we obtained after creating the connection, we will use it to get the QR code value.

tip

You can poll for new QR code values every 5 seconds as that's the minimum time it can take for it to be updated.

curl -X GET --location 'https://api.p.2chat.io/open/whatsapp/channel/WPNf3ea6c85-0dca-4d8a-a9a6-2b918f59cc97/qr-code' \
--header 'Content-Type: application/json' \
--header 'X-User-API-Key: your_api_key_here'

Response

FieldDescription
qr_codeThe QR code value, set to null when no connect command was executed
qr_code_image_urlThe URL of the QR code image
warningA message indicating why the QR code is not present when that's the case
channelThe channel details
{
"success": true,
"qr_code": "2@X2gWRMVmfb5UuQPonVzwgKrULbaH9tXWUZ4T22EQVMJLozt4p4+tVWn579wftoOoHhVjXRUEl5Qovycbhvhg/nmb/nBeKOBdCWI=,HLoV1HJt1holPlRG+uP444TTXysWR7tymHmVafklz24=,u3A10kNHhj2d9xZDw06ANBbWfHHZ5MTqRjHgFDz4IFg=,IEZNp3uawofMm9Mwn+Tc99vgSH3Ck7GlXQAKEhvvRyA=,1",
"qr_code_image_url": "https://.../ACC91be87af-5a29-4034-b599-342f2aeb5d52/tmp/WPNf8a36be9-508e-4715-a1ce-9a2352baef1d/qrcode-429de06f7f9d25591f765fe5ab32aa3c.png",
"channel": {
"id": "WPNf3ea6c85-0dca-4d8a-a9a6-2b918f59cc97",
"uuid": "WPNf3ea6c85-0dca-4d8a-a9a6-2b918f59cc97",
"friendly_name": "Testing number creation now",
"phone_number": "+18647351566",
"iso_country_code": "US",
"pushname": null,
"server": null,
"platform": null,
"connection_status": "D",
"enabled": true,
"is_business_profile": false,
"channel_type": "WW",
"sync_contacts": false,
"timezone": "America/New_York",
"lang": "en",
"created_at": "2023-10-12T17:43:58Z",
"updated_at": null
}
}