×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

REST API HOW TO PASS PARAMETER AS BODY

REST API HOW TO PASS PARAMETER AS BODY

REST API HOW TO PASS PARAMETER AS BODY

(OP)
Hello,

Following is my visual foxpro code and i want to pass parameters as body how to do?

loHttp = CreateObject('Msxml2.ServerXMLHTTP.6.0')

loRequest = loHTTP.open('POST',"https://clientbasic.mastersindia.co/oauth/access_t...")

loHttp.setRequestHeader("Content-Type", "text/json")
loHttp.SetRequestHeader("username","testeway@mastersindia.co")
loHttp.SetRequestHeader("password","!@#Demo!@#123")
loHttp.SetRequestHeader("client_id","fIXefFyxGNfDWOcCWnj")
loHttp.SetRequestHeader("client_secret","QFd6dZvCGqckabKxTapfZgJc")
loHttp.SetRequestHeader("grant_type","password")

loHttp.Send( )

Above code not working in visual foxpro
and create error in response
{"error":"invalid_request","error_description":"Invalid grant_type parameter or parameter missing"}

But when I am using POSTMAN and put all parameter in BODY section these api is working.
I dont know how to pass parameter as body
kindly guide me


RE: REST API HOW TO PASS PARAMETER AS BODY

The send method has body as its parameter. So prepare the body into a variable lcBody, for example, and pass it in at the line

CODE

loHttp.send(lcBody) 

Chriss

RE: REST API HOW TO PASS PARAMETER AS BODY

Hi Jinesh,

The API documentation will specify parameters that are expected/accepted by the Header and parameters that are expected/accepted in the Body of the request. Please verify the documentation. Anyway, when you say that if you pass parameters in body using Postman and the API works, those are expected to be passed in the Body.

For example, if the 'grant_type' is a Body parameter, your input json for Body would be as below and you can have a variable to store like this:

lcJsonBody = '{"grant_type":"password"}'
..and then..
loHttp.send(lcJsonBody)

Suppose you have 2 more parameters to be passed in the Body json, it would be something like this:

lcJsonBody = '{"grant_type":"password", "Element1":"ValueForElement1", "Element2":"ValueForElement2"}'
loHttp.send(lcJsonBody)

The documentation will tell the correct way of passing the parameters. Different APIs will have their own policy in implementing/accepting user values into the API.

A suggestion: I am not sure the values you have provided here are real ones or just some random samples. Anyway, it's always better not to mention your actually Access keys, usernames, passwords etc in public forums not only here but any forum.

Rajesh



Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close