Page 1 of 2

Passing ARRAY types as Request Parameters in a REST Service?

Posted: Fri Aug 17, 2012 7:45 pm
by Jason Cochran

In regards to REST services, how do you give a request parameter of type of ARRAY?
I am trying to add a relation between Parse.com's Users class and my own class. You have to be able to pass it an array of object parameters.

==== PARSE.COM DOCUMENTATION =================================

In order to update Relation types, Parse provides special operators to atomically add and remove objects to a relation. So, we can add an object to a relation like so:

curl -X PUT \
-H "X-Parse-Application-Id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-H "X-Parse-REST-API-Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"opponents":{"op":"AddRelation","objects":[{"type":"Pointer","className":"Player","objectId":"Vx4nudeWn"}]}}' \
https://api.parse.com/1/classes/GameS...

================================================================

ref: https://www.parse.com/docs/rest#objec... - look at the "Relations" section

It is expecting the "objects" parameter to be an array and not a string.

I get back the following error:

Server response:
{
"error": "relation operations take array arguments, got a String instead",
"code": 111
}


Passing ARRAY types as Request Parameters in a REST Service?

Posted: Fri Aug 17, 2012 10:04 pm
by maxkatz

There is an example how to do it here: http://help.tiggzi.com/documentation/...

Let me know if that helps...


Passing ARRAY types as Request Parameters in a REST Service?

Posted: Thu Sep 13, 2012 4:19 am
by Jean-Marc Naud

I have the exact same question and I do not understand how the documenttion helps. For REST Seivces "Respond Parameters" there is an ARRAY checkbox to indicate that the parameter is an array. In the "Request Parameters" panel, there is no such checkbox.

So how can one make a REST API call where the Request requires an array as one of the parameters?

Thx.


Passing ARRAY types as Request Parameters in a REST Service?

Posted: Thu Sep 13, 2012 4:36 am
by maxkatz

Set the Method to post/push, Content Type to json, and you will get an option to create an array in request parameters.

You can also create a single request parameter, and set it to json array:

items = [the entire array]


Passing ARRAY types as Request Parameters in a REST Service?

Posted: Thu Sep 13, 2012 6:31 am
by Jean-Marc Naud

Thx Max; I've used the 2nd choice of a single parameters into which I write the full array; somehow the 1st solution does not work for me as I still do not see the option to make a request parameter an array when putting the settings you are suggesting.


Passing ARRAY types as Request Parameters in a REST Service?

Posted: Thu Sep 13, 2012 3:56 pm
by maxkatz

Passing ARRAY types as Request Parameters in a REST Service?

Posted: Thu Sep 13, 2012 4:45 pm
by Jean-Marc Naud

Thx Max; I do have the "Add Level" button which I've used to add Nested Objects but the only way I've found to make these nested objects for Request Parameters into Arrays is to use Additional JavaScript code attached to the service. On the Response Parameters panel, in addition to the "Add Level" button there is also an Array checkbox. In any case, using the JavaScript ways works for me. Thx.


Passing ARRAY types as Request Parameters in a REST Service?

Posted: Thu Jun 06, 2013 9:13 am
by Angelo Keirsebilck

Can you give an example of how you did this?


Passing ARRAY types as Request Parameters in a REST Service?

Posted: Thu Jun 06, 2013 11:28 am
by Maryna Brodina

Passing ARRAY types as Request Parameters in a REST Service?

Posted: Wed May 27, 2015 5:53 pm
by Alvi

How can I test a service that takes in array ?
(All array elements are greyed out in request and test section of rest api definition ).

Image