Square brackets in JSON makeWebRequest parameters? Is it possible?

Former Member
Former Member

Hi community!

The API im using requires enclosing square brackets.

Example: 

[{"name" : "fredrick"}, ...]


But when i try this:

var params = [{"name"=>"fredrick"}];

it fails and gives me a -201 error. (INVALID_HTTP_BODY_IN_REQUEST = -201)

 

How can this be fixed?

(var params = {"name"=>"fredrick"}; works fine but returns an expected errogenous response from the server)

Top Replies

All Replies

  • an expected errogenous response

    I would have expected that to be very unexpected.

  • Former Member
    Former Member over 5 years ago in reply to dpawlyk

    maybe but thats the way the API is written:

    http://api.turfgame.com/v4#users

    THROWS (Status: 400 Bad Request)

    //If POST string is invalid
    { "errorMessage" : "Invalid JSON string" , "errorCode" : 0xBAD0001 }
  • "Erroneous"  (maybe). Not "erogenous" (look it up).

  • The documentation for makeWebRequest specifies that the parameters parameter must be a Dictionary of keys and values or null. There is no option for generating a request with a JSON body that is not a JSON object (you can't send a body that is a JSON array, string, number, true, false, or null).

    This is a case where I'd seriously consider standing up a service proxy that will accept requests in the format provided by ConnectIQ that will re-format the request to something accepted by the service. i.e., your ConnectIQ app would use this:

    var params = {
        "payload" => [
            {
                "name" : "fredrick"
            },
            {
                "email" : "[email protected]"
            },
            {
                "id" : 1803
            },
            ...
        ]
    };

    The service would grab the payload value from the object, and forward it on to api.turfgame.com.

    Note that some of the responses sent by the TurfGame service are returning JSON arrays instead of JSON objects. If I remember correctly, ConnectIQ requires that the JSON body be a JSON object as well, so you'd need to read those responses from api.turfgame.com and then re-package them similar to what was done for the request.

  • Former Member
    Former Member over 5 years ago in reply to dpawlyk

    Woo, sorry then. Not a native speaker. Just trying to get help here

  • Former Member
    Former Member over 5 years ago in reply to Travis.ConnectIQ

    Thanks, will try it!