Forum Discussion
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¶meter2=value2
In SnapLogic you can send the request body in the HTTP entity field of the REST Post snap.
Example expression:
“param1=”+encodeURIComponent($param1)+“¶m2=”+encodeURIComponent($param2)
Best Regards,
Dragan Talevski
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
- d_talevski4 years agoNew Contributor
@jsmith141 You can try removing the account from the REST Post snap and send the account username and password through pipelines parameters to check if it’s working.
- jsmith1414 years agoNew Contributor III
I think we can, but first I want to ask, would passing the credentials as pipeline parameters expose them to be intercepted by unwanted parties?
- jsmith1414 years agoNew Contributor III
We went ahead and tried it, since it is a sandbox account and it worked, but where do we go from here?
- ptaylor4 years agoEmployee
encodeURIComponent(“password”)
is justpassword
(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.- ptaylor4 years agoEmployee
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.
- jsmith1414 years agoNew Contributor III
Oh I apologize for the confusion, I already had that specific header in place We are successfully using the account.username and account.password in another pipeline i.e. in the HTTP entity field of the POST snap.