REST API (application / x-www-form-urlencoded)

Hi all!
I need to call an API that has the following characteristics:

  • Content-Type: application / x-www-form-urlencoded
  • Authorization: (with a "Bearer" token)

In the body the information is given through the form data.

I can not find documentation on how to make this call and how to get the answer (JSON).

Could you help with an example?

Thank you

  • 0
  • 0
  • 68
  • 0
  • 1

Answers

You don't indicate which product you are using (IRIS, Cache, Ensemble) which may impact on some details.  However the basic code to load the form data and execute the Post call is going to be  the same.

You need an instance of %Net.HTTPRequest.  If you are in Ensemble then you would work through the adapter.  For Cache or IRIS create an instance of this class and configure it for the server end point.

Add your form data to the request by calling the InsertFormData method.

ex. req.InsertFormData("NameFld", "NameValue")

To cause the request to be performed call the Post method

ex.  set status = req.Post(REST resource URL)

If you assign the server and port properties of the request then do not include them in the URL here.  

You can access the response in the HTTPResponse property of the request.  This will be an instance of the %Net.HTTPResponse class.

You can read more on the %Net.Request class in the class reference at https://docs.intersystems.com/latest/csp/documatic/%25CSP.Documatic.cls