{ Community }
  • Academy
  • Docs
  • Developers
  • Resources
    • Community Articles
    • Apigee on GitHub
    • Code Samples
    • Videos & eBooks
    • Accelerator Methodology
  • Support
  • Ask a Question
  • Spaces
    • Product Announcements
    • General
    • Edge/API Management
    • Developer Portal (Drupal-based)
    • Developer Portal (Integrated)
    • API Design
    • APIM on Istio
    • Extensions
    • Business of APIs
    • Academy/Certification
    • Adapter for Envoy
    • Analytics
    • Events
    • Hybrid
    • Integration (AWS, PCF, Etc.)
    • Microgateway
    • Monetization
    • Private Cloud Deployment
    • 日本語コミュニティ
    • Insights
    • IoT Apigee Link
    • BaaS/Usergrid
    • BaaS Transition/Migration
    • Apigee-127
    • New Customers
    • Topics
    • Questions
    • Articles
    • Ideas
    • Leaderboard
    • Badges
  • Log in
  • Sign up

Get answers, ideas, and support from the Apigee Community

  • Home /
  • BaaS/Usergrid /
avatar image
0
Question by Hani Alghamdi · Apr 23, 2016 at 12:40 PM · 443 Views apigee edgebaascollections

Connection between two entities in BaaS?

I have created a collection called "movies" and another collection called "reviews" which holds the reviews for the movies in the collection "movies"(both are under sandbox application) and I am retying to connect them together and not sure how to do it! I read and tried every example in the documentation here with no luck yet!

Can someone please explain to me how can I connect two entities on BaaS? The goal is to retrieve the review of the movie if the user included "reviews=true" in the request!

Thank you

Comment
Add comment Show 2
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image brandon@apigee.com ♦ · Apr 23, 2016 at 02:08 PM 0
Link

Hey Hani, can you show the steps you've taken to connect the entities? One thing you should also know - there isn't a way to retrieve both the entity and the connection at the same time; you'll need to retrieve them separately via {URL}/collection/entity/relationship.

avatar image Hani Alghamdi · Apr 23, 2016 at 11:25 PM 0
Link

Hi Brandon and thanks for your reply! here are the steps:

1- I created "movie" collection and I posted 10 movies manually to it and got 10 UUIDs

2- I created another collection named "reviews" with the entity "name" corresponding to the entity "name" in "movies", then I created couple dummy reviews for each movie, so I still have only 10 entities under "reviews" with the movies names but some movies has more than more review. (a review contain a name, comment, and a rating number out of 5)

3- From the documentation here I tried this via cURL:

curl -X POST https://api.usergrid.com/ /sandbox/movies/username/review/reviews

And I switched between movies and reviews because I wasn't sure what is "connecting entity" and "connected entity" in the example in the docs!

- is it right that I added the reviews manually or should I do the connectoin between the movies and

its reviews somehow else?

Thanks!

Close

2 Answers

  • Sort: 
avatar image
3
Best Answer

Answer by williamssean · Apr 25, 2016 at 02:58 AM

Hello @Hani Alghamdi

The way you should connect two entities is by UUID or entity name. I pasted how to connect two entities by UUID below. If you want the movies collection to connect to the reviews collection, then you have to create a relationship with the following request. In this instance, I used rated as the relationship name, but you could replace that with whatever you want.

curl -X POST https://api.usergrid.com/<org>/sandbox/movies/<movieUUID>/rated/<reviewUUID>

Here is my request and response. You can see my movie entity is now connected to the rating that I created.

curl -XPOST https://api.usergrid.com/myorg/sandbox/movies/96a0409a-0a8d-11e6-a3f0-6b5db3f771f8/rated/accea87a-0a8d-11e6-87b9-3b0939e74c09 

In the response you can see that the two entities are now connected.

{  
"action":"post",
"application":"31943980-e80e-832e",
"params":{  
"access_token":[ ""]
},
"path":"/movies/96a0409a-0a8d-11e6-a3f0-6b5db3f771f8/rated",
"uri":"https://api.usergrid.com/swilliams/sandbox/movies/96a0409a-0a8d-11e6-a3f0-6b5db3f771f8/rated",
"entities":[  
{  
"uuid":"accea87a-0a8d-11e6-87b9-3b0939e74c09",
"type":"review",
"name":"review1",
"created":1461551428727,
"modified":1461551428727,
"metadata":{  
"path":"/movies/96a0409a-0a8d-11e6-a3f0-6b5db3f771f8/rated/accea87a-0a8d-11e6-87b9-3b0939e74c09"
},
"rating":"great"
}
],
"timestamp":1461552246234,
"duration":64,
"organization":"myorg",
"applicationName":"sandbox"
}

Now I can access the rating with the following request. If you have multiple ratings attached to this movie, then all of them would be returned by this request.

curl -X GET https://api.usergrid.com/myorg/sandbox/movies/96a0409a-0a8d-11e6-a3f0-6b5db3f771f8/rated

Response:

{

"action" : "get",

"application" : "319439b536a789da",

"params" : {

"access_token" : [ "" ]

},

"path" : "/movies/96a0409a-0a8d-11e6-a3f0-6b5db3f771f8/rated",

"uri" : "https://api.usergrid.com/myorg/sandbox/movies/96a0409a-0a8d-11e6-a3f0-6b5db3f771f8/rated",

"entities" : [ {

"uuid" : "accea87a-0a8d-11e6-87b9-3b0939e74c09",

"type" : "review",

"name" : "review1",

"created" : 1461551428727,

"modified" : 1461551428727,

"metadata" : {

"connecting" : {

"rated" : "/movies/96a0409a-0a8d-11e6-a3f0-6b5db3f771f8/rated/accea87a-0a8d-11e6-87b9-3b0939e74c09/connecting/rated"

},

"path" : "/movies/96a0409a-0a8d-11e6-a3f0-6b5db3f771f8/rated/accea87a-0a8d-11e6-87b9-3b0939e74c09"

},

"rating" : "great"

} ],

"timestamp" : 1461552816852,

"duration" : 28,

"organization" : "myorg",

"applicationName" : "sandbox"

}

Comment
Add comment · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Kurt Googler Kanaskie · Jan 24, 2017 at 11:38 PM

@Hani Alghamdi, @seanwilliams

If you wanted to have the relationship be intrinsic, that is, you want the collections to be related as you would expect in a traditional collections and resources API design, this works.

First create the review and then make the connection:

  • POST /reviews { review details } - create a new review.
  • POST /movies/{movieId}/reviews/{reviewId} { no-content } - connect it to the movie

Then you can:

  • GET /movies/{movieId}/reviews - to see all the reviews for that movie

If you want to delete a review, first remove the relationship and then delete the entity:

  • DELETE /movies/{movieId}/reviews/{reviewId} - deletes just the relationship
  • DELETE reviews/{reviewId} - delete the entity
Comment
Add comment · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

45 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Usergrid data encryption at rest 3 Answers

How to move baas collections from one org-app to another? 2 Answers

Multiple collections or single one containing everything 1 Answer

How to retrieve all entities in one collection using android sdk 0 Answers

Sorting using Order By 0 Answers

  • Products
    • Edge - APIs
    • Insights - Big Data
    • Plans
  • Developers
    • Overview
    • Documentation
  • Resources
    • Overview
    • Blog
    • Apigee Institute
    • Academy
    • Documentation
  • Company
    • Overview
    • Press
    • Customers
    • Partners
    • Team
    • Events
    • Careers
    • Contact Us
  • Support
    • Support Overview
    • Documentation
    • Status
    • Edge Support Portal
    • Privacy Policy
    • Terms & Conditions
© 2021 Apigee Corp. All rights reserved. - Apigee Community Terms of Use - Powered by AnswerHub
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Post an idea
  • Spaces
  • Product Announcements
  • General
  • Edge/API Management
  • Developer Portal (Drupal-based)
  • Developer Portal (Integrated)
  • API Design
  • APIM on Istio
  • Extensions
  • Business of APIs
  • Academy/Certification
  • Adapter for Envoy
  • Analytics
  • Events
  • Hybrid
  • Integration (AWS, PCF, Etc.)
  • Microgateway
  • Monetization
  • Private Cloud Deployment
  • 日本語コミュニティ
  • Insights
  • IoT Apigee Link
  • BaaS/Usergrid
  • BaaS Transition/Migration
  • Apigee-127
  • New Customers
  • Explore
  • Topics
  • Questions
  • Articles
  • Ideas
  • Badges