Massimo Caroccia
Massimo Caroccia

Reputation: 447

Parse: fetch relation items with REST API

In Parse I've two classes with a many-to-many relation, for example items and categories. I've created in the class items a relation with categories and all work fine with querying and updating. My problem is when I need to change the items relation with linked categories.

As far as I know, if I need to change the relation of items with categories, I first need to delete all categories relation with RemoveRelation and later re-add them with AddRelation. To do that I need to fetch all categories objectId from my item.

How can I do that with a REST API call?

Upvotes: 0

Views: 323

Answers (1)

Mo Nazemi
Mo Nazemi

Reputation: 2717

I assume you have an item with objectId of xyz in your Items class. In that class you have a Relation field called categories which holds a list of objects from Category class. To get all the category objects from that relationship, you can do the following REST call using curl:

curl -X GET -H "X-Parse-Application-Id: xxx"   -H "X-Parse-REST-API-  Key: xxx" -H "Content-Type: application/json"  
-G --data-urlencode 'where={"$relatedTo":{"object":{"__type":"Pointer","className":"Items","objectId":"xyz"},
"key":"categories"}}' https://api.parse.com/1/classes/Category

Upvotes: 1

Related Questions