Multiple API Endpoints
How do I hit both Clerk API endpoint as well as my own application in Twilio?
Some clients who are on the API plan require to hit both Clerk endpoint as well as their internal application. There are multiple ways this can be achieved, but in this tutorial, we will be covering Twilio Studio.
As an example, we will be hitting Clerk API endpoint as well as Front App.
Navigate to Twilio Studio and create a new flow. When designing your flow select Make HTTP Requst Widget. Here is an example of the flow:

Clerk

Clerk API requires the following parameters to be set in order to work properly.
Request URL: https://api.clerk.chat/prod/twilio/events
HTTP Parameters:
1
To: {{trigger.message.To}}
2
From: {{trigger.message.From}}
3
Body: {{trigger.message.Body}}
Copied!

FrontApp

Request URL: https://webhook.frontapp.com/sms/*********
Request Body:
1
{
2
"SmsSid": "{{trigger.message.MessageSid}}",
3
"SmsMessageSid": "{{trigger.message.MessageSid}}",
4
"ToState": "{{trigger.message.ToState}}",
5
"From": "{{trigger.message.From}}",
6
"MessageSid": "{{trigger.message.MessageSid}}",
7
"AccountSid": "{{trigger.message.AccountSid}}",
8
"ToCity": "{{trigger.message.ToCity}}",
9
"FromCountry": "{{trigger.message.FromCountry}}",
10
"ToZip": "{{trigger.message.ToZip}}",
11
"FromCity": "{{trigger.message.FromCity}}",
12
"To": "{{trigger.message.To}}",
13
"FromZip": "{{trigger.message.FromZip}}",
14
"ToCountry": "{{trigger.message.ToCountry}}",
15
"Body": "{{trigger.message.Body}}",
16
"NumMedia": "{{trigger.message.NumMedia}}",
17
"FromState": "{{trigger.message.FromState}}"
18
}
Copied!
Here is an example of a Twilio Studio Flow JSON that you can import into your flow.
1
{
2
"description": "A New Flow",
3
"states": [
4
{
5
"name": "Trigger",
6
"type": "trigger",
7
"transitions": [
8
{
9
"next": "clerk-api",
10
"event": "incomingMessage"
11
},
12
{
13
"event": "incomingCall"
14
},
15
{
16
"event": "incomingRequest"
17
}
18
],
19
"properties": {
20
"offset": {
21
"x": 70,
22
"y": -30
23
}
24
}
25
},
26
{
27
"name": "clerk-api",
28
"type": "make-http-request",
29
"transitions": [
30
{
31
"next": "front-api",
32
"event": "success"
33
},
34
{
35
"event": "failed"
36
}
37
],
38
"properties": {
39
"offset": {
40
"x": -270,
41
"y": 240
42
},
43
"method": "POST",
44
"content_type": "application/x-www-form-urlencoded;charset=utf-8",
45
"parameters": [
46
{
47
"value": "{{trigger.message.To}}",
48
"key": "To"
49
},
50
{
51
"value": "{{trigger.message.From}}",
52
"key": "From"
53
},
54
{
55
"value": "{{trigger.message.Body}}",
56
"key": "Body"
57
}
58
],
59
"url": "https://api.clerk.chat/prod/twilio/events"
60
}
61
},
62
{
63
"name": "front-api",
64
"type": "make-http-request",
65
"transitions": [
66
{
67
"event": "success"
68
},
69
{
70
"event": "failed"
71
}
72
],
73
"properties": {
74
"offset": {
75
"x": -270,
76
"y": 560
77
},
78
"method": "POST",
79
"content_type": "application/json;charset=utf-8",
80
"body": "{\n \"SmsSid\": \"{{trigger.message.MessageSid}}\",\n \"SmsMessageSid\": \"{{trigger.message.MessageSid}}\",\n \"ToState\": \"{{trigger.message.ToState}}\",\n \"From\": \"{{trigger.message.From}}\",\n \"MessageSid\": \"{{trigger.message.MessageSid}}\",\n \"AccountSid\": \"{{trigger.message.AccountSid}}\",\n \"ToCity\": \"{{trigger.message.ToCity}}\",\n \"FromCountry\": \"{{trigger.message.FromCountry}}\",\n \"ToZip\": \"{{trigger.message.ToZip}}\",\n \"FromCity\": \"{{trigger.message.FromCity}}\",\n \"To\": \"{{trigger.message.To}}\",\n \"FromZip\": \"{{trigger.message.FromZip}}\",\n \"ToCountry\": \"{{trigger.message.ToCountry}}\",\n \"Body\": \"{{trigger.message.Body}}\",\n \"NumMedia\": \"{{trigger.message.NumMedia}}\",\n \"FromState\": \"{{trigger.message.FromState}}\" \n}",
81
"url": "https://webhook.frontapp.com/sms/613d990497926d56b2411e09489ce7221db1014b8f24f09c41c9b186d353f6d3b72c10a20f696f550850564044391b5d"
82
}
83
}
84
],
85
"initial_state": "Trigger",
86
"flags": {
87
"allow_concurrent_calls": true
88
}
89
}
Copied!
  • Anytime someone messages your number it will appear in both Clerk and in Front
  • Any outbound messages sent from Clerk will only be imported into Front after a new inbound message is received in the conversation. This is a Front limitation (refer to their docs).
Last modified 9mo ago
Copy link