Hi,
I'm consuming a REST API that only accepts x-www-form-urlencoded.
I'm trying to request an object:
id={
"number":"500",
"month":"12",
"year":"20",
}
I understand: number=500&month=12&year=20; the API also requires 'id'.
How would the 'id' be included?
Thanks,
Brad
You might not need to send an id field at all, but if the API specifies that this is required, this StackOverflow describes how to correctly nest form parameters:
id[number]=500&id[month]=12&id[year]=20
Thank you. I tried but did not work. OutSystems converted to 'text/plain'.
I also tried %5b/%5d; referenced in StackOverflow, this was also converted to 'text/plain'.
I confirmed, API requires the id field; the API will take different id fields for example id, accessid, tokenid, etc. and provide a response.
Any additional thoughts?
That sounds like an incorrect Content-Type in your API call.
Try adding a Content-Type Request Header as an input to your REST call, and set its value to the required type to avoid sending plaintext.
application/x-www-form-urlencoded
I added the content-type.
When running a test in API window; it works fine, but when running in web emulator and OutSystems Now I get an error (400 bad request).
In checking the API service; the 'card' has dropped from the post body.
Thoughts?
Thanks!
That's very strange, but probably not related to your API implementation anymore.
Run the code through the built-in debugger and make you're passing all required inputs to the API call.
APIs are always invoked server-side (IIS, Wildfly, or other) so calling it from the web emulator and OutSystems Now shouldn't make a difference here.
Fixed it. Thank you for the help.
When using Content-Type input parameter; few things I did.
I didn't realize the above.
Thank you again for the help and coaching! Much Appreciated!
Great to hear!
A little late, but just discovered this guide as well: https://www.outsystems.com/forums/discussion/36156/guide-consume-rest-api-with-form-url-encoded-request/
Leaving it here for future reference.
This topic (referenced from the topic above) is perhaps a better reference.