Table of content
- Table of content
- šĀ Getting Started With ChatDaddy API
- Step 1: Authenticating the APIs
- Step 2: Obtaining a refresh token
- Step 3: Generating access tokens
- Step 4 : Accessing the API via Stoplight
- Other Cases
šĀ Getting Started With ChatDaddy API
Read full REST API docs by clicking HERE
This is a language-neutral tutorial and the same requests can be incorporated into any framework using REST API calls. If you are using NodeJS or the browser, weād recommend using the official typescript client, which you can find here
Step 1: Authenticating the APIs
Our API utilizes the refresh token/access token flow, very similar to o-auth. Refresh tokens are long-lived tokens & are immune to password changes, they prevent you from ever needing to enter the password in plaintext or store it in your code.
Note: The refresh token automatically becomes invalid afterĀ 14 Days of inactivity.
Using the refresh token, one can generate access tokens. These are JWT tokens and are valid for 1 hour. All of ChatDaddy's APIs can be accessed using this short-lived JWT access token. The access token's schema can be read aboutĀ here.
āFAQ
Step 2: Obtaining a refresh token
A refresh token can be generated using the API using your phone number & password, which you can find here. If you do not want to use the API, you can generate the refresh token from the ChatDaddy app too:
- Login & open ChatDaddy App fromĀ
https://app.chatdaddy.tech
- Navigate toĀ `App Store & API` and then `API`, or you can click here
- Click the āGenerate Refresh Tokenā button
- Enter your password in the modal and you should see your new refresh token. It would look something like:
2fe11749-5e25-45b6-b679-d4395bcb2252
- Also, make note of the team ID on the page ā you will need it to generate access tokens. It would like
f52fc4a7-e27d-40dc-abb8-b601ec45gf4e
You can store this refresh token as a secret in your project, and use it to generate access tokens for all your ChatDaddy API calls now
Step 3: Generating access tokens
With your refresh token & team ID, you can now make a request to the ChatDaddy servers and generate an access token:
curl --request POST \
--url https://api-teams.chatdaddy.tech/token \
--header 'Content-Type: application/json' \
--data '{
"refreshToken": "2fe11749-5e25-45b6-b679-d4395bcb2252",
"teamId": "f52fc4a7-e27d-40dc-abb8-b601ec45gf4e"
}'
Of course, you would replace the ārefreshTokenā & āteamIdā fields here with your own
The response would look something like:
{
"access_token": "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJzY2..."
}
This access token can now be used to access the APIs, the token will last for a short while before you will have to generate a new token.
Step 4 : Accessing the API via Stoplight
- Using the access token, you can make API calls via Stoplight or use cURL or any framework of your choice
- Letās look at how to send a message via stoplight
- Navigate to the āSend a messageā page, or click here
- In the Auth section, input āTokenā as āBearer <access token here>ā
- Now, weāll fill in the other parameters, the important parameters are:
- accountId: ChatDaddy allows multiple WhatsApp channels in a single team, this account ID takes in the ID of the channel you want to send the message from. Set to ārandomā to use any channel in your account.
- To find the ID of a channel, go to https://app.chatdaddy.tech
- Expand the nav bar & click on your name in the top right corner; Click āManage Channelsā
- You will find all the channels there and can copy the ID from there. The ID of the channel would look like
acc_23552c45-7bbd-5033-c1_0000
- Alternatively, you can use the API to fetch all channels in your account. See here for the API
- chatId: ID of the person you want to send the message to, which can be a phone number. Country code required
- Body: In the request body, a sample āHello thereā text has been provided. Feel free to change to something of your choice. The full message request schema can be found on the API page itself
An example request looks like this:
Other Cases
- I have more than 1 channel