cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1199
Views
13
Helpful
5
Replies

Correct Format for using REST Client

Hi All,

I am struggling to get the format correct for my POST using the CVP REST Client (CVP 11).  I am just using the API to send an SMS message and had it working in Postman immediately but cannot seem to get the correct format in CVP.  I am getting a response but I am missing one of the required parameters. I have tried this API using both JSON and XML by changing the content type in the header and I can see the response coming back in both formats as I change the header type..  I have tried putting these values in both the parameter field and the body field in the CVP element with no success.  I always get the same response  as shown below which is ' a From phone number is required'

The API is expecting a from and a to phone number in E.164 format

10.XXX.XX.31.1525133209662.198.TEST1,05/01/2018 10:06:51.298,POST_Rest_Client_01,custom,log return,<?xml version='1.0' encoding='UTF-8'?>

<TwilioResponse><RestException><Code>21603</Code><Message>A 'From' phone number is required.</Message><MoreInfo>https://www.twilio.com/docs/errors/21603</MoreInfo><Status>400</Status></RestException></TwilioResponse>

My question is where should I be focusing?  Is it in the parameters field of the CVP element or the body?  ( I have tried many variations like simply using From and the phone number or trying to use the xml form such as this  <From>+61XXXXXXXXX</From>  I have also tried the JSON format {"From": "+61xxxxxxxxx)"

I have also tried all of this just in the body parameter of the element - so far with no success.  Any help would be appreciated such as examples of use of sending JSON and/or XML using this element. I am just adding the values in statically until I get it working and will change them to session data later.  I have seen one other example on the forum of the google geolocater API and that works and I can see that is uses the parameter field.  That was GET rather than POST so I am just wondering if there is any difference with POST

I have attached my current settings of the element

Thanks in advance!

Cathal


1 Accepted Solution

Accepted Solutions

Hi everyone

I am pleased to say this is finally working.  The issue was that the API would only accept form data in key-value pairs and the trick was to get the raw data (string)  to create this form data.  The way to do is to use" ="

In the example above to create the "From", you use From=xxxxxxxx. To create a second field you need to use"&"

I needed 3 parameters in total for this POST request so I had to use From=xxxxxxx &To=xxxxxxx &Body=xxxxxxxxx

Another issue I ran in to was that you could not send "+" which was required as I needed the phone number in  E164  format.  To get around this you have to use the Hex equivalent of the ASCII "+"  which is 2b. To use this in the sting it has to be %2b

The final solution was to use the body field in the REST Client and not the parameters. This is what you need to use. The 61 was just for the Australian country code and the leading 0 in the phone number had been stripped from the session variable using Set Value element.

working_settings.PNG

The full view of the working settings are shown below

Rest_client settings.PNG

Hopefully this saves someone some headaches in the future!

View solution in original post

5 Replies 5

janinegraves
Spotlight
Spotlight

When you did this in PostMan, where did you configure the From phone

number? As a parameter? Or a header? or in the body of the post?

Hi Janine

In Postman I configured it as a field in the body as below.  Thanks!

Twilio_PostmanJPG.JPG

Hi All

I am still working on this. I know now however that I need to use key-value pairs using x-www-form-urlencoded. This is the only format that will need accepted. I have set the content type correctly in the header but am wondering if key-value pairs is supported using this element?

In parallel, I have it working in eclipse so am working on a custom element. Is a custom action element the way to go?

Thanks

Hi everyone

I am pleased to say this is finally working.  The issue was that the API would only accept form data in key-value pairs and the trick was to get the raw data (string)  to create this form data.  The way to do is to use" ="

In the example above to create the "From", you use From=xxxxxxxx. To create a second field you need to use"&"

I needed 3 parameters in total for this POST request so I had to use From=xxxxxxx &To=xxxxxxx &Body=xxxxxxxxx

Another issue I ran in to was that you could not send "+" which was required as I needed the phone number in  E164  format.  To get around this you have to use the Hex equivalent of the ASCII "+"  which is 2b. To use this in the sting it has to be %2b

The final solution was to use the body field in the REST Client and not the parameters. This is what you need to use. The 61 was just for the Australian country code and the leading 0 in the phone number had been stripped from the session variable using Set Value element.

working_settings.PNG

The full view of the working settings are shown below

Rest_client settings.PNG

Hopefully this saves someone some headaches in the future!

Thank you for posting your final solution!

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: