# Help with Twilio REST API POST Function

**URL:** https://community.thunkable.com/t/help-with-twilio-rest-api-post-function/1516637
**Category:** Questions about Thunkable X
**Created:** [September 20, 2021, 7:05pm UTC](https://community.thunkable.com/t/help-with-twilio-rest-api-post-function/1516637 "2021-09-20T19:05:17Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![arty3mm](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@arty3mm](https://community.thunkable.com/u/arty3mm)
#### Post date: [September 20, 2021, 7:05pm UTC](https://community.thunkable.com/t/help-with-twilio-rest-api-post-function/1516637/1 "2021-09-20T19:05:17Z")

</div>

Hello,

I have difficulty in creating the blocks for a Twilio POST Function as suggested from their Documentation listed below:

curl -X POST [https://api.twilio.com/2010-04-01/Accounts/$TWILIO\_ACCOUNT\_SID/Messages.json](https://api.twilio.com/2010-04-01/Accounts/%24TWILIO_ACCOUNT_SID/Messages.json)   
–data-urlencode “Body=Hi there”   
–data-urlencode “From=+15017122661”   
–data-urlencode “To=+15558675310”   
-u $TWILIO\_ACCOUNT\_SID:$TWILIO\_AUTH\_TOKEN

Should I set the webAPI Body as a string joining the Body, From and To?  
Body=Hi there  
From=+15017122661  
To=+15558675310

Should I have Headers like :  
Content-type: application/x-www-form-urlencoded  
Authorization : Bearer $TWILIO\_AUTH\_TOKEN

Where to place the Username and Password ?  
$TWILIO\_ACCOUNT\_SID:$TWILIO\_AUTH\_TOKEN

These are the Blocks I used  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/3/3/33da7961d2f4134478e5e538b3a237b038dba4c2.png)

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/c/1c5b8ec9b955b90bc124b7da013a4081cb87b901.png)

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/f/1f889dfa541aeefa6c59f0d182052f5a03e5d3b4.png)

I have “Network Request Failed Error” on my android device and “undefined” in my iPhone device

Same error if I used the following:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/a/4ac38f51d4f2ac1325d3e86e70c5c7c93a89369c.png)

I appreciate much your help on this. Thank you in advance.

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [September 21, 2021, 6:22am UTC](https://community.thunkable.com/t/help-with-twilio-rest-api-post-function/1516637/2 "2021-09-21T06:22:51Z")

</div>

What is in your `Headers` block?

Can you show the complete blocks of the `body`?

In your `Post` block you are only displaying `error` block but not `status` or `response`. What do they contain?

---

<div class="post-metadata">

### Author: ![arty3mm](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@arty3mm](https://community.thunkable.com/u/arty3mm)
#### Post date: [September 21, 2021, 9:43pm UTC](https://community.thunkable.com/t/help-with-twilio-rest-api-post-function/1516637/3 "2021-09-21T21:43:31Z")

</div>

Hi Muneer,

Here are my answers to your questions:

What is in your `Headers` block?

- I asked about the Headers in my post above although I tried the following below :  
Content-type: application/x-www-form-urlencoded  
Authorization : Bearer $TWILIO\_AUTH\_TOKEN

Can you show the complete blocks of the `body`?

- The Body block is also posted above. Please make suggestions if I am wrong . I reposted here below:  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/c/1c5b8ec9b955b90bc124b7da013a4081cb87b901.png)

In your `Post` block you are only displaying `error` block but not `status` or `response`. What do they contain?

- I have 400 in android and 401 in Apple device for their respective statuses.

Again, I need help because I don’t know what Headers, Query Parameters (if there are) and Objects should I initialize and put into my Blocks. I also need help with the -u $TWILIO\_ACCOUNT\_SID:$TWILIO\_AUTH\_TOKEN too. Where to initialize them.

Thanks.

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [September 22, 2021, 5:15am UTC](https://community.thunkable.com/t/help-with-twilio-rest-api-post-function/1516637/4 "2021-09-22T05:15:59Z")

</div>

Thank you for the reply.

I only asked the questions after I went through your post and rewriting the same info will not help at all.

> [@arty3mm](#):
>
> What is in your `Headers` block?
> 
> - I asked about the Headers in my post above although I tried the following below :  
> Content-type: application/x-www-form-urlencoded  
> Authorization : Bearer $TWILIO\_AUTH\_TOKEN

I need to know is this part of the `Web API` component setup or in a `Headers` code block. If it is part of the code, then show the image. You can of course redact the sensitive information. Is it an object or a text?

> [@arty3mm](#):
>
> Can you show the complete blocks of the `body`?
> 
> - The Body block is also posted above. Please make suggestions if I am wrong . I reposted here below:

I asked for the **complete** and you provided exactly what was there. If it was sufficient I wouldn’t have asked for a better image.

What is available after the **From=+44393…**? Is there any other thing after the complete number? I’m asking about special characters used in formatting.

From the `status` of 400 the most possible cause is the format of your data. One common format used in API calls is to mimic the URL parameter format which means separating parameters by **&** sign. Try it and see if it solves the issue.

> [@arty3mm](#):
>
> In your `Post` block you are only displaying `error` block but not `status` or `response`. What do they contain?
> 
> - I have 400 in android and 401 in Apple device for their respective statuses.

- 400 means the format of the information is wrong. This is connected with the information you supplied in the `body` section. Unfortunately, you decided not to show the **complete** block to see if you are following a specific format.

- 401 is authorization problem.

---

<div class="post-metadata">

### Author: ![arty3mm](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@arty3mm](https://community.thunkable.com/u/arty3mm)
#### Post date: [September 22, 2021, 3:29pm UTC](https://community.thunkable.com/t/help-with-twilio-rest-api-post-function/1516637/5 "2021-09-22T15:29:40Z")

</div>

Hi muneer,

Thank you for your response.

Right from the start, I admitted that I need help in putting the POST for this Twilio curl command. I don’t know how to put them into Thunkable Blocks, I don’t know what should I put as Headers or Query Parameters, or even the Body Parameters. The Blocks that I used are just my tries, and of course, because they are wrong, they are giving me errors, 400 and 401 statuses.

I’m sure, you are a Thunkable Expert, so, could you please show me your Thunkable Blocks for the following :  
curl -X POST [https://api.twilio.com/2010-04-01/Accounts/$TWILIO\_ACCOUNT\_SID/Messages.json](https://api.twilio.com/2010-04-01/Accounts/%24TWILIO_ACCOUNT_SID/Messages.json)  
–data-urlencode “Body=Hi there”  
–data-urlencode “From=+15017122661”  
–data-urlencode “To=+15558675310”  
-u $TWILIO\_ACCOUNT\_SID:$TWILIO\_AUTH\_TOKEN

I got this from this link : [Make an HTTP Request to Twilio - Twilio](https://www.twilio.com/docs/usage/requests-to-twilio)

Thank you again.

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [September 22, 2021, 5:25pm UTC](https://community.thunkable.com/t/help-with-twilio-rest-api-post-function/1516637/6 "2021-09-22T17:25:23Z")

</div>

> [@arty3mm](#):
>
> –data-urlencode “Body=Hi there”  
> –data-urlencode “From=+15017122661”  
> –data-urlencode “To=+15558675310”

Usually this goes into the `body` section but with the following format.  
“Body=Hi%20there&From=+15017122661&To=+15558675310”  
Use the same header that you used already.

For the first test, use all hard-coded in the `body` section. Once you see it working then you can use the variables to fill-in user data.

---

<div class="post-metadata">

### Author: ![arty3mm](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@arty3mm](https://community.thunkable.com/u/arty3mm)
#### Post date: [September 23, 2021, 2:03am UTC](https://community.thunkable.com/t/help-with-twilio-rest-api-post-function/1516637/7 "2021-09-23T02:03:22Z")

</div>

Hi muneer,

I followed your suggestions:

Headers  
Content-type: application/x-www-form-urlencoded  
Authorization : Bearer $TWILIO\_AUTH\_TOKEN

URL  
[https://api.twilio.com/2010-04-01/Accounts/$TWILIO\_ACCOUNT\_SID/Messages.json](https://api.twilio.com/2010-04-01/Accounts/%24TWILIO_ACCOUNT_SID/Messages.json)

Body  
Body=Hi%20there&From=+15017122661&To=+15558675310

Status  
401

Error  
Undefined

If you could tell me how to transform this → -u $TWILIO\_ACCOUNT\_SID:$TWILIO\_AUTH\_TOKEN into the webAPI, I think this will solved the 401 status.

Thanks.

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [September 23, 2021, 9:59am UTC](https://community.thunkable.com/t/help-with-twilio-rest-api-post-function/1516637/8 "2021-09-23T09:59:52Z")

</div>

> [@arty3mm](#):
>
> If you could tell me how to transform this → -u $TWILIO\_ACCOUNT\_SID:$TWILIO\_AUTH\_TOKEN into the webAPI, I think this will solved the 401 status.

This **Authorization : Bearer $TWILIO\_AUTH\_TOKEN** is supposed to be the encrypted version of this **$TWILIO\_ACCOUNT\_SID:$TWILIO\_AUTH\_TOKEN**.

Another way is to code it this way:  
https://$TWILIO\_ACCOUNT\_SID:$TWILIO\_AUTH\_TOKEN@api.twilio.com/2010-04-01/Accounts/$TWILIO\_ACCOUNT\_SID/Messages.json

---

<div class="post-metadata">

### Author: ![arty3mm](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@arty3mm](https://community.thunkable.com/u/arty3mm)
#### Post date: [September 23, 2021, 1:33pm UTC](https://community.thunkable.com/t/help-with-twilio-rest-api-post-function/1516637/10 "2021-09-23T13:33:45Z")

</div>

Hi muneer,

I have tried both of your suggestions for **$TWILIO\_ACCOUNT\_SID:$TWILIO\_AUTH\_TOKEN**

This : https://$TWILIO\_ACCOUNT\_SID:$TWILIO\_AUTH\_TOKEN@api.twilio.com/2010-04-01/Accounts/$TWILIO\_ACCOUNT\_SID/Messages.json

and this : **Authorization : Bearer $TWILIO\_AUTH\_TOKEN**

and the Body is : **Body  
Body=Hi%20there&From=+15017122661&To=+15558675310**

Any comment on my **Content-type: application/x-www-form-urlencoded** This is also on my Headers. Do you think this has an effect on the result?

Yes, I admit, I forgot to mention. This was initialized in the Simple Settings of webAPI Object. I didn’t use Blocks for the Headers.

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [September 23, 2021, 1:44pm UTC](https://community.thunkable.com/t/help-with-twilio-rest-api-post-function/1516637/11 "2021-09-23T13:44:23Z")

</div>

If you get 401 then the **$TWILIO\_AUTH\_TOKEN** is not correct. You need to check with your account details in Twilio and get the correct code.

Content-Type is correct as far as the examples in the documentation provides.

See this from the documentation of Twilio  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/f/7f61063f8e49658b42e21c1a2dc7766972c3fc9a.png)

This is the full [example URL](https://username:password@api.twilio.com/2010-04-01/your_desired_path)

Another suggestion in the documentation to use `Basic` instead of `Bearer`  
**Authorization: Basic**

---

<div class="post-metadata">

### Author: ![arty3mm](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@arty3mm](https://community.thunkable.com/u/arty3mm)
#### Post date: [September 23, 2021, 2:00pm UTC](https://community.thunkable.com/t/help-with-twilio-rest-api-post-function/1516637/12 "2021-09-23T14:00:05Z")

</div>

I will try the Authorization: Basic

Thanks.

---

<div class="post-metadata">

### Author: ![arty3mm](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@arty3mm](https://community.thunkable.com/u/arty3mm)
#### Post date: [September 24, 2021, 3:55am UTC](https://community.thunkable.com/t/help-with-twilio-rest-api-post-function/1516637/13 "2021-09-24T03:55:54Z")

</div>

Hi @muneer,

This is now my working Blocks.  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/9/59247b66732c38ca1b04cf6f035385ea8f7b13b4.png)

I read an article about [postman.com](http://postman.com), I used the curl statement Twilio provided, put them each in their corresponding places. The most important thing is in the Authorization Tab, I selected Basic Auth and typed my $TWILIO\_ACCOUNT\_SID in the Username Entry and $TWILIO\_AUTH\_TOKEN in the Password Entry. After that, I opened the Headers Tab including the Hidden Auto-generated Headers, I saw the base64 encoded Authorization. This is in the form of **Basic set-of-random-characters** different from the $TWILIO\_ACCOUNT\_SID:$TWILIO\_AUTH\_TOKEN. This is what you are referring about encrypted **$TWILIO\_ACCOUNT\_SID:$TWILIO\_AUTH\_TOKEN**. I copied that and placed it in my Headers in Thunkable along side with my current Content-Type:application/x-www-form-urlencoded

There is no need to use **%2B** or **%20** for the Body, From and To in the Body Block. It has a 201 status and the SMS is sent to the Phone Number stored in my variable. Phone number formats should follow the format below:  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/0/40dd4ac0cd807c06b81dddbd6c84ed52b309fb16.png)

Thank you.

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [September 24, 2021, 4:09am UTC](https://community.thunkable.com/t/help-with-twilio-rest-api-post-function/1516637/14 "2021-09-24T04:09:20Z")

</div>

So I concluded from above that you were getting 401 because the **set-of-random-characters** were not the correct one. You had them generated by Postman and used it in your app and it worked.

Well done.

---

<div class="post-metadata">

### Author: ![arty3mm](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@arty3mm](https://community.thunkable.com/u/arty3mm)
#### Post date: [September 24, 2021, 4:23am UTC](https://community.thunkable.com/t/help-with-twilio-rest-api-post-function/1516637/15 "2021-09-24T04:23:20Z")

</div>

Basically, you stated the same name, so I assumed they are the same, and the encryption site I found first was not the right one.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/2/d2a5525591cfa5617229ea6f55bafb0e708ad0aa.png)

Anyways, I hope this will help others.

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [September 24, 2021, 9:30am UTC](https://community.thunkable.com/t/help-with-twilio-rest-api-post-function/1516637/16 "2021-09-24T09:30:49Z")

</div>

OK, sorry for that, it must by a typo mistake (more correctly, a copy/paste mistake). Should you have pointed it out at that time it would have been corrected on the spot.

Now, that the issue is solved, enjoy the app running as expected.

---

<div class="post-metadata">

### Author: ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)
#### Post date: [November 8, 2024, 1:15pm UTC](https://community.thunkable.com/t/help-with-twilio-rest-api-post-function/1516637/17 "2024-11-08T13:15:09Z")

</div>


