WhatsApp Dynamic Flows

This guide helps you to create a WhatsApp Dynamic Flow

Step 1: Create a basic Flow

Begin by creating a flow with an endpoint using the Gupshup API. Since this involves a flow with an endpoint, ensure that you utilize the Gupshup Create Flow API and specify your endpoint in the endpoint_uri parameter within the API request. - LINK

curl --location --request POST 'https://partner.gupshup.io/partner/app/{{APP_ID}}/flows/' \
--header 'Authorization: {{PARTNER_APP_TOKEN}}' \
--header 'Content-Type: application/json' \
--data-raw '{
  "name": "{{FLOW_NAME}}",
  "categories": ["{{FLOW_CATEGORY}}"]
  "endpoint_uri" : {{endpoint url}}
}'

Step 2: Generating Keys

  • Code - Execute code as mentioned in the Readme.md file. Once done successfully you will receive your public and private key. - (Testing OR UAT) In PROD use your own code or tool and host it on a secure server.
  • Openssl - Please follow the steps and generate key.

The above methods of genrating a keys is recommended by Meta but please try it in UAT Env and use a tried and test method in your PROD Env.

ℹ️

Ensure when setting the business public key, it is a valid 2048-bit RSA public key in PEM format.

Step 3: Set Key

Having generated your public and private key pair, use the following API to set the public key with your WABA.

Set Public Key API

Overview

This API allows you to add a public key to META for WhatsApp flows. The customer is responsible for generating a public-private key pair, securely storing the private key, and sharing the public key with META using this passthrough API. The private key is utilized for decrypting data exchanged through META in dynamic flows.

Endpoint

POST https://api.gupshup.io/wa/app/:appId/flows/public\_key

Request Example

curl --location 'https://api.gupshup.io/wa/app/:appId/flows/public_key' \
--header 'apikey: {{api_key}}' \
--header 'Content-Type: application/json' \
--data '{
    "public_key": "{{public_key}}"
}'
ℹ️

Please make sure that the public key is correctly formated before it is send via the API request.

The format means that the line break should be replaced by \n.

Headers

AtrributeDescription
apikey: (string)The API key associated with the account where the application is registered.
Content-Type:Must be set to application/json.

Request Body

AtrributeDescription
public_key:(string) The public key to be added to the application.Constraint: Must be in a valid public key format.

Parameters

AtrributeDescription
appIdThe identifier of the application for which the public key needs to be set.

Response

Status CodeResponseComment
200{"status": "success"}success
400{"code": "code","details": "reason","status": "error"}error

Get Public Key API

This API retrieves the public key associated with your application's WhatsApp flows.

Endpoint

GET https://api.gupshup.io/wa/app/:appId/flows/public_key

Request Example

curl --location --globoff 'https://api.gupshup.io/wa/app/:appId/flows/public_key' \
--header 'apikey: {{api_key}}' \
--header 'Content-Type: application/json'

Headers

AtrributeDescription
apikey: (string)The API key associated with the account where the application is registered.
Content-Type:Must be set to application/json.

Parameters

AtrributeDescription
appIdThe identifier of the application for which the public key needs to be set.

Response

Status Code

Response

Comment

200

{

"encryption": {

"business_public_key": "public_key","business_public_key_signature_status": "public_key_status"},"status": "success"}

success

400

{"code": "code","details": "reason","status": "error"}

error

Step 4: Publish the Flow

Execute the Publish API to publish the flow. Once the flow is successfully published, you are ready to send flow messages.