cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Passing Body Content in Post Snap

jsmith141
New Contributor III

Hi,

This is a very novice question, but I am having trouble with a post request snap. This is just to authenticate with the RingCentral platform to receive a token for API consumption. I am able to successfully retrieve an access token when calling the oauth/token endpoint in Postman. The issue arises when I try to move this post call into SnapLogic. The call requires certain parameters to be passed through the body and I am not sure how to duplicate this in SnapLogic post snap. Please see the screenshot of the Postman call Body tab below.

image

I have created a basic account in SnapLogic to store the username and password and my post snap references that account. I am also aware that the credentials of a basic account can be accessed using the โ€œAccount.Usernameโ€ and Account.Password" of the respective referenced account within the snap.

I am just not sure how to build out the body section in the โ€œx-www-form-urlencodedโ€ format as shown in the screenshot? The error I get back when validating this post snap is just a 400: Bad Request.

Any insight/help that anyone could provide would be greatly appreciated. Please let me know if additional information is needed to provide assistance.

Thanks,
James

48 REPLIES 48

d_talevski
New Contributor

Hi @jsmith141 ,

When the content type is x-www-form-urlencoded then the format of the body should be the same as the query string:

parameter1=value1&parameter2=value2

In SnapLogic you can send the request body in the HTTP entity field of the REST Post snap.
Example expression:

โ€œparam1=โ€+encodeURIComponent($param1)+โ€œ&param2=โ€+encodeURIComponent($param2)

Best Regards,
Dragan Talevski

jsmith141
New Contributor III

Hi Dragan,

Thank you for your reply. I have implemented the encodeURIComponent call as you describe but I am getting the same 400 error. Please see the exact line belowโ€ฆ

โ€œgrant_type=โ€+encodeURIComponent(โ€œpasswordโ€)+โ€œ&username=โ€+encodeURIComponent(account.username)+โ€œ&password=โ€+encodeURIComponent(account.password)

I have the Upload body type fields set to โ€œMultipart form-dataโ€. Does this need to be changed, or is there another setting on this snap that may need to be adjusted?

Thanks,
James

encodeURIComponent(โ€œpasswordโ€) is just password (thereโ€™s nothing that needs to be encoded), so you could simplify that to just "grant_type=password&username=" + ...

But I still donโ€™t understand how youโ€™re able to get account.username and account.password to resolve.

Upload body type isnโ€™t used here. But you do need to add a row to the โ€œHTTP headerโ€ table with Content-Type application/x-www-form-urlencoded, as I showed in the screenshot from my last reply.

Ah! I just looked at that other Community post you linked. I wasnโ€™t aware of that hack. But Iโ€™m pretty sure it only works in an expression used in the Value column of the HTTP Headers table, not anywhere else. I donโ€™t think youโ€™ll be able to use it for the request body.