Jason Cochran
Posts: 0
Joined: Thu Aug 16, 2012 2:46 am

Passing ARRAY types as Request Parameters in a REST Service?

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
}

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Passing ARRAY types as Request Parameters in a REST Service?

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

Let me know if that helps...

Jean-Marc Naud
Posts: 0
Joined: Thu Sep 13, 2012 4:19 am

Passing ARRAY types as Request Parameters in a REST Service?

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.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Passing ARRAY types as Request Parameters in a REST Service?

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]

Jean-Marc Naud
Posts: 0
Joined: Thu Sep 13, 2012 4:19 am

Passing ARRAY types as Request Parameters in a REST Service?

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.

Jean-Marc Naud
Posts: 0
Joined: Thu Sep 13, 2012 4:19 am

Passing ARRAY types as Request Parameters in a REST Service?

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.

Angelo Keirsebilck
Posts: 0
Joined: Thu Jun 06, 2013 9:13 am

Passing ARRAY types as Request Parameters in a REST Service?

Can you give an example of how you did this?

Alvi
Posts: 0
Joined: Thu Apr 23, 2015 6:22 pm

Passing ARRAY types as Request Parameters in a REST Service?

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

Return to “Issues”