REST IA not posting correctly

So I have been writing a RESTful IA that posts to a API that only takes 2 parameters. My issue is one of the parameters is a combination of various values.

What it is expecting:
https:/www.somewebsite/api?type=submit&req={“evt_uid”:“8760”&“badge_id”:“5100356”&“check”:“C”&“token”:“b0883f925af870786df58ffc4105d107”}

What I am sending:
https:/www.somewebsite/api?type=submit&evt_uid=8760&badge_id=5100356&check=C&token=b0883f925af870786df58ffc4105d107

Notice the contents of “req” in the first example has the same content as what I am submitting in the second.

I realize I should be submitting just a parameter called “type” and a parameter called “req” but how do I reference, insert, hide, and “stringify” the other parameters to get submitted inside of req while still having access to them inside Intuiface?

Any help would be HIGHLY appreciated.

Just to add a but more on this.

Currently I am submitting all parameters in the name=value format.
I need to embed these into a parameter called req and display them in a "name":"value" format inside of req.

Hi Patrick,

I discussed your issue with a colleague from the product team and we have a question for you: are you sure you want to post this JSON object as a parameter of the request URL and not as the body of the POST request?

Something like that:

If this is the case, you’ll find your answer in this article
You need to define the schema of your “request object” that will be sent as the body of the POST. You will then have access to each member of this object in the associated action in Composer.

Hey, thanks for the response. I can’t post it in the body as each time i do this I get an error from the API saying {"error_code":101,"error_message":"Missing argument 'req' expected"}. When I analyze the call being sent it seems the difference between a successful call and a failed one is nesting the parameters in a req = { }. This leads me to believe I need to figure out a way to nest parameters inside of a parameter called req and have them stringify their values to display inside of req and display themselves like “name”:“value” instead of name=value.

Then you can tell the guy who wrote this API that it’s not the cleanest way in the world :wink:

In this case, the solution will be the following: create a JavaScript Interface Asset. Create a method that will take 4 parameters as an input and will create the string version that you need in the req. Before calling your POST method, call this Javascript IA method to generate the POST parameter that you need.

You can find an example in the Grocery Promotion sample of our market place. In its files/InterfaceAssets folder you will find a GroceryMailSender with a FormatMail method.

Wow, well it’s not pretty but it worked. Thanks so much for all the advice!

1 Like