Was this helpful?

See all application entities.

You can connect users with other entities by using cURL or one of the SDKs. Connecting entities is how, for example, you create relationships between entities. This is how one user "follows" another, or "likes" a particular item from your foods collection.

If the relationship is a collection (such as a users collection for the group employees), this request adds the second entity to the first entity’s collection of the specified name. (Note that employees is an entity name within the groups collection.) In the case of a group, this is how you add users as group members.

When creating a connection, if you specify the entity type for the second entity, then you can create the connection using the entity’s name rather than its UUID.

Disconnecting users from entity data

To disconnect a user from other data, perform a delete operation against the same endpoint at which you posted to create the connection.

Request URIs

POST /<org_id>/<app_id>/<collection>/<first_entity_id>/<relationship>/<second_entity_uuid>

POST /<org_id>/<app_id>/<collection>/<first_entity_id>/<relationship>/<second_entity_type>/<second_entity_id>

Parameters

Parameter Description
app_id | uuid Application UUID or application name
collection Collection name
first_entity_id | uuid First entity UUID or entity name
org_id | uuid Organization UUID or organization name
relationship Collection name or connection type (e.g., likes)
second_entity_type Second entity type
second_entity_uuid | uuid Second entity UUID or entity name

Example: Connecting to an Entity UUID

Request

curl POST http://api.usergrid.com/my-org/my-app/users/vincent/likes/6c56ffda-9e75-11e3-99fd-8dd1801e534c

Response

{
    "action" : "post",
    "application" : "db1e60a0-417f-11e3-9586-0f1ff3650d20",
    "params" : { },
    "path" : "/users/174785aa-8ea8-11e3-ae1f-eb20e5bce407/likes",
    "uri" : "https://api.usergrid.com/my-org/my-app/users/174785aa-8ea8-11e3-ae1f-eb20e5bce407/likes",
    "entities" : [ {
        "uuid" : "6c56ffda-9e75-11e3-99fd-8dd1801e534c",
        "type" : "food",
        "name" : "pizza",
        "created" : 1393371291725,
        "modified" : 1393371291725,
        "metadata" : {
            "path" : "/users/174785aa-8ea8-11e3-ae1f-eb20e5bce407/likes/6c56ffda-9e75-11e3-99fd-8dd1801e534c"
        }
    } ],
    "timestamp" : 1393371455487,
    "duration" : 77,
    "organization" : "my-org",
    "applicationName" : "my-app"
}

Example: Connecting to a Collection/Entity

Request

curl -X POST http://api.usergrid.com/my-org/my-app/users/betty/likes/food/pizza

Response

{
    "action" : "post",
    "application" : "db1e60a0-417f-11e3-9586-0f1ff3650d20",
    "params" : { },
    "path" : "/users/2857ca5a-8230-11e3-a8b1-3705e3ad0cc6/likes",
    "uri" : "https://api.usergrid.com/my-org/my-app/users/2857ca5a-8230-11e3-a8b1-3705e3ad0cc6/likes",
    "entities" : [ {
        "uuid" : "6c56ffda-9e75-11e3-99fd-8dd1801e534c",
        "type" : "food",
        "name" : "pizza",
        "created" : 1393371291725,
        "modified" : 1393371291725,
        "metadata" : {
            "connecting" : {
                "likes" : "/users/2857ca5a-8230-11e3-a8b1-3705e3ad0cc6/likes/6c56ffda-9e75-11e3-99fd-8dd1801e534c/connecting/likes"
            },
            "path" : "/users/2857ca5a-8230-11e3-a8b1-3705e3ad0cc6/likes/6c56ffda-9e75-11e3-99fd-8dd1801e534c"
        }
    } ],
    "timestamp" : 1393371810679,
    "duration" : 57,
    "organization" : "my-org",
    "applicationName" : "my-app"
}

The example assumes use of the JavaScript (HTML5) SDK.

var options = {
    method:'POST',
    endpoint:'users/jane.doe/likes/d9693ec3-61c9-11e2-9ffc-02e81adcf3d0'    
};
client.request(options, function (err, data) {
    if (err) {
        //error — POST failed
    } else {
        //success — data will contain raw results from API call        
    }
});

The example assumes use of the Ruby SDK.

app = Usergrid::Application.new 'https://api.usergrid.com/my-org/my-app/'
app['users/jane.doe/likes/d9693ec3-61c9-11e2-9ffc-02e81adcf3d0'].post nil

The example assumes use of the Node.js module.

var options = {
    method:'POST',
    endpoint:'users/jane.doe/likes/d9693ec3-61c9-11e2-9ffc-02e81adcf3d0'    
};
client.request(options, function (err, data) {
    if (err) {
        //error — POST failed
    } else {
        //success — data will contain raw results from API call        
    }
});

Comments

When a user is connected with entity data, is there a way to specify that that data can only be acted on by that specific user? I understand it can be limited by the API, but is it possible to fully prevent users from accessing entity data connected to other users? Even if someone hacks the URL of the API?

Add new comment

Provide your email address if you wish to be contacted offline about your comment.
We will not display your email address as part of your comment.

We'd love your feedback and perspective! Please be as specific as possible.
Type the characters you see in this picture. (verify using audio)

Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.