Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 
ankitgaur
Level 7

How to pass request with body part in HTTP POST method api request ?

We are making following API Call in Postman successfully:

For try: Copy the below given code into a JSON file & IMPORT created json file in POSTMAN.
{
"id": "5e9021f6-02ea-9846-5380-5b3d58a55d04",
"name": "forgotpassword API on POSTMAN",
"requests": [
{
"id": "657318a8-70a5-065d-e9c5-1b7fac76bda7",
"headers": "Content-Type: application/json\n",
"url": " http://ec2-54-244-62-69.us-west-2.compute.amazonaws.com:80/v1/users/auth/password/reset/",
"pathVariables": {},
"preRequestScript": null,
"method": "POST",
"collectionId": "5e9021f6-02ea-9846-5380-5b3d58a55d04",
"data": [],
"dataMode": "raw",
"name": " http://ec2-54-244-62-69.us-west-2.compute.amazonaws.com:80/v1/users/auth/password/reset/",
"description": "",
"descriptionFormat": "html",
"time": 1489131187724,
"version": 2,
"responses": [],
"tests": null,
"currentHelper": "normal",
"helperAttributes": {},
"rawModeData": "{\"email\":\"abc@tudip.com\"}"
}
],
"order": [
"657318a8-70a5-065d-e9c5-1b7fac76bda7"
],
"timestamp": 1489131187724
}


Where "rawModeData": "{\"email\":\"abc@tudip.com\"}" is the BODY Part of the request.
How to make Above POSTMAN api (Above json is an Export of POSTMAN api call) call in ROKU ?.
0 Kudos
7 Replies
joetesta
Level 10

Re: How to pass request with body part in HTTP POST method api request ?

0 Kudos
ankitgaur
Level 7

Re: How to pass request with body part in HTTP POST method api request ?

0 Kudos
EnTerr
Level 9

Re: How to pass request with body part in HTTP POST method api request ?

"ankitgaur" wrote:
We are making following API Call in Postman successfully...

i have no idea what "Postman" is - nor do i need to know more about it^. Can you send your data successfully using cURL? If yes, post here the command line that works - though i suspect figuring out how to send it with curl will help you figure out yourself how to send it from Roku.

(^) i looked on wikipedia and for me not having an article makes it "not significant enough". yes, i also noticed existence of "getpostman.com" website which seems full of itself enough not to have an "About" page
0 Kudos
belltown
Level 7

Re: How to pass request with body part in HTTP POST method api request ?

"ankitgaur" wrote:
We are confused about What should be the Request in the PostFromString() function. Any Solution with an example will be very helpful.
So, Could you Please provide an Example for this Scenario.

The 'request' parameter is the query string, the exact string you'd send after the "?" if you were doing a GET request. The Roku OS internally converts the query string parameters into "body parts".
You must also ensure that the query parameters are url-encoded, if necessary, e.g. using ifUrTransfer.Escape()

E.g.:

ut = CreateObject("roUrlTransfer")
ut.SetUrl("http://myserver.com/myscript.php")
...
queryString = ut.Escape(stuff) + "&" + ut.Escape(username) + "&" + ut.Escape(password)
ut.AsyncPostFromString(queryString)
...
https://github.com/belltown/
0 Kudos
EnTerr
Level 9

Re: How to pass request with body part in HTTP POST method api request ?

"belltown" wrote:
The 'request' parameter is the query string, the exact string you'd send after the "?" if you were doing a GET request. The Roku OS internally converts the query string parameters into "body parts". ...

That's not quite true - in the sense that it's a perfectly valid http having a POST that has both a "?" query string and a body at the same time. We recently looked into that on account of PHP muddying the waters with its method names. On the particular case your advise seems correct though
0 Kudos
ankitgaur
Level 7

Re: How to pass request with body part in HTTP POST method api request ?

"EnTerr" wrote:
"belltown" wrote:
The 'request' parameter is the query string, the exact string you'd send after the "?" if you were doing a GET request. The Roku OS internally converts the query string parameters into "body parts". ...

That's not quite true - in the sense that it's a perfectly valid http having a POST that has both a "?" query string and a body at the same time. We recently looked into that on account of PHP muddying the waters with its method names. On the particular case your advise seems correct though


Hi EnTerr,

Following is the working CURL Command line URL for making API  call 

curl -X POST --data "email=abc@tudip.com" http://ec2-54-244-62-69.us-west-2.compu ... ord/reset/

Please provide way how to call above curl url in ROKU ?
0 Kudos
EnTerr
Level 9

Re: How to pass request with body part in HTTP POST method api request ?

"ankitgaur" wrote:
Following is the working CURL Command line URL for making API  call 

curl -X POST --data "email=abc@tudip.com" http://ec2-54-244-62-69.us-west-2.compu ... ord/reset/

Please provide way how to call above curl url in ROKU ?

Ok, so it's sent application/x-www-form-urlencoded in the body. Just do what @belltown said
0 Kudos