Example of sending JSON in REST API Put request

Example of sending JSON in REST API Put request

  

I am in the process of creating my first REST API (Consume) connector in the OutSystems environment.   I am successfully authenticating, logging out, and reading data from the service's endpoints.  Now I am trying to update data.

I need to format and send JSON in the body of the request and the Request Format type should be JSON.  I would really appreciate a little guidance.  Here is the request:

I'm pretty sure that isn't correct and what the service actually wants in the body of the request is {"Status":"Inactive"}


However, here is my question.  When I change the Request Format from text to JSON it tells me the Request input value should be a structure or a list.  What kind of structure or list? Pretty dumb question but I'm still a newbie at this.  

Thanks,


Dave Schuler

Hi Dave,

JSON objects are surrounded by curly braces {} and are written in key/value pairs. Eg:  {"name":"Mary", "age":25 }

Have you read your REST producer's documentation about what kind of structure should be send to it?


All the best

Yes.  I understand what they want and I know how to format JSON.  That is not my question.

My question is about how to configure the OutSystems REST request to achieve the objectives I need to accomplish.  The request must be a Put. It must be JSON format.  When I select JSON in the Request Format property of the REST request, it tell me I need to provide an input value that is a structure or a list.  I can create a key-value structure that contains just the key and the value that I need to send.  Is that what OutSystems is looking for?

Hi David,

If you are consuming the rest API you need ask API documentation to from API owner in order to get Input JSON request and output JSON request and you need to simply paste these JSON`s in respective placeholder then plateform will automatically create structures to handle these Input/output JSON`s.


Regards

-SK-

Hello David,

As Shashi told, is only necessary to copy the JSON input example from the API Documentation and paste it. The platform will automatically create the structure.

All the best,


Sadly, there is no example in the API documentation.  I have put in a support request to them asking for just that.

Solution

Hi David,

This sentence of yours: "When I change the Request Format from text to JSON it tells me the Request input value should be a structure or a list." - I assume that it is Service Studio telling you this? This is because in OutSystems, JSON is represented by Structures, or a List of Structures. So if you specify JSON as the Request Input Value, you need to have an Input Parameter that is in fact a Structure or a List of Structures.

Note that if you put the Request JSON in the Body (as in your image), Service Studio will create a suitable Structure for you. However, if you have already specified an Input Parameter, then change the type, you can get errors like you experienced.

Solution

Kilian:

Thank you very much for that explanation.  It was exactly what I needed.  With that guidance I was able to coax my problem one step closer to completion (most of my problems are with the service I'm trying to implement--their documentation is practically non-existent).

Hi David,

Glad I could be of help. And I feel your pain about trying to integrate a service with practically-non-existent documentation, been there done that :). Good luck!