—Rate this article—
 

Posting activities

Posting a user activity

Use the  POST method to create an activity in the activities collection.

Request URI

POST /<org_id>/<app_id>/users/<uuid | username>/activities { request body }

Parameters

Parameter Description
arg uuid|string org_id Organization UUID or organization name
arg uuid|string app_id Application UUID or application name
request body

One or more sets of activity properties:

{
    "actor":{
        "displayName":"John Doe",
        "uuid":"1f3567aa-da83-11e1-afad-12313b01d5c1",
        "username":"john.doe",
        "image":{
            "duration":0,
            "height":80,
            "url":"http://www.gravatar.com/avatar/","width":80},
            "email":"john.doe@gmail.com"
        },
        "verb":"post",
        "content":"Hello World!"
    }
}

Example - Request

curl -X POST "https://api.usergrid.com/my-org/my-app/users/john.doe/activities" -d '{"actor":{"displayName":"John Doe","uuid":"1f3567aa-da83-11e1-afad-12313b01d5c1","username":"john.doe",
"image":{"duration":0,"height":80,"url":"http://www.gravatar.com/avatar/","width":80},
"email":"john.doe@gmail.com"},"verb":"post","content":"Hello World!"}'

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

var options = {
    method:'POST',
    endpoint:'users/john.doe/activities',
    body: {
        "actor": {
            "displayName":"John Doe",
            "uuid":"1f3567aa-da83-11e1-afad-12313b01d5c1",
            "username":"john.doe",
            "image": {
                "duration":0,
                "height":80,
                "url":"http://www.gravatar.com/avatar/",
                "width":80},
                "email":"john.doe@gmail.com"
            },
            "verb":"post",
            "content":"Hello World!"
        }
    };
client.request(options, function (err, data) {
    if (err) {
        //error — POST failed
    } else {
        // success — POST worked. 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.create_activity { actor: { displayName: 'John Doe', uuid: '1f3567aa-da83-11e1-afad-12313b01d5c1', username: 'john.doe', image: { duration: 0, height: 80, url: 'http://www.gravatar.com/avatar/', width: 80 }, email: 'john.doe@gmail.com' }, verb: 'post', content: 'Hello World!' }

The example assumes use of the Node.js module.

var options = {
    method:'POST',
    endpoint:'users/john.doe/activities',
    body:{
        "actor":
           {
               "displayName":"John Doe",
               "uuid":"1f3567aa-da83-11e1-afad-12313b01d5c1",
               "username":"john.doe",
               "image":{
                   "duration":0,
                   "height":80,
                   "url":"http://www.gravatar.com/avatar/",
                   "width":80
               },
               "email":"john.doe@gmail.com"
           },
           "verb":"post",
           "content":"Hello World!"
        }
    };
client.request(options, function (err, data) {
    if (err) {
        //error — POST failed
    } else {
        // success — POST worked. Data will contain raw results from API call        
    }
});

Example - Response

{
    "action" : "post",
    "application" : "5111c463-6a42-11e1-b6dd-1231380a0284",
     "params" : {
    },
    "path" : "/users/1f3567aa-da83-11e1-afad-12313b01d5c1/activities",
    "uri" : "https://api.usergrid.com/5111c463-6a42-11e1-b6dd-1231380a0284/users/1f3567aa-da83-11e1-afad-12313b01d5c1/activities",
    "entities" : [ {
        "uuid" : "da448955-f3aa-11e1-8042-12313d331ae8",
        "type" : "activity",
        "created" : 1346445092974,
        "modified" : 1346445092974,
        "actor" : {
            "displayName" : "John Doe",
            "uuid" : "1f3567aa-da83-11e1-afad-12313b01d5c1",
            "username" : "john.doe",
            "image" : {
                "duration" : 0,
                "height" : 80,
                "url" : "http://www.gravatar.com/avatar/",
                "width" : 80
            },
            "email" : "john.doe@gmail.com"
        },
        "content" : "Hello World!",
        "metadata" : {
            "path" : "/users/1f3567aa-da83-11e1-afad-12313b01d5c1/activities/da448955-f3aa-11e1-8042-12313d331ae8"
        },
        "published" : 1346445092974,
        "verb" : "post"
    } ],
    "timestamp" : 1346445092827,
    "duration" : 1406,
    "organization": "my-org",
    "applicationName": "my-app"
}

Note: Anytime a logged-in user makes a request, you can substitute "me" for the uuid or username. So the format of a request to create an activity for the currently logged-in user would look like this:

POST /<org_id>/<app_id>/users/me/activities { request body }

The users/me endpoint is accessible only if you provide an access token with the request. If you don't provide an access token with the request, that is, you make an anonymous (or "guest") call, the system will not be able to determine which user to return as /users/me.

When you create an activity it creates a relationship between the activity and the user who created it. In other words, the newly created activity above belongs to john.doe. Another way of saying this is the user "owns" the activity. And because this relationship exists, the activity will appear in the feed of any of the user’s followers (in this example, anyone who is following john.doe). However, it will not appear in the feed of people the user follows. The activity is accessible at the /activities endpoint to users who have the permission to read that endpoint.

Notice the properties specified in the request body in the previous example are actor, verb, and content. The actor, verb, and content properties are built into the Activity entity (see Default Data Entity Types). The actor property specifies properties of the entity that performs the action (here, user john.doe). The gravatar URL is used to create an icon for the activity. And because an Activity is simply an API Services data entity, you can also create custom properties.

The verb parameter is descriptive. You can use it to indicate what type of activity is posted, for example, an image versus text. The value post is defined in the JSON Activity Streams specification as “the act of authoring an object and then publishing it online.“

Posting an activity to a group

Use the POST method to post an activity to a specific group. In this case the activity is created in the activities collection and is accessible at the /activities endpoint to users who have the permission to read that endpoint. In addition, a relationship is established between the activity and the group, and because of that, the activity will appear in the group’s feed. The group "owns" the activity. Also, the activity will be published in the feed of all users that are members of the group.

Request URI

POST /{org_id}/{app_id}/groups/{uuid|groupname}/activities {request body}

Parameters

Parameter Description
arg uuid|string org_id Organization UUID or organization name
arg uuid|string app_id Application UUID or application name
arg uuid|string groupname UUID or name of the group
request body

One or more sets of activity properties:

{
  "actor":
    {
    "displayName":"John Doe",
    "uuid":"1f3567aa-da83-11e1-afad-12313b01d5c1",
    "username":"john.doe",
    "image":{
      "duration":0,
      "height":80,
      "url":"http://www.gravatar.com/avatar/","width":80},
  "email":"john.doe@gmail.com"},
  "verb":"post",
  "content":"Hello World!"    
}

Example - Request

curl -X POST "https://api.usergrid.com/my-org/my-app/groups/mygroup/activities" -d '{"actor":{"displayName":"John Doe","uuid":"1f3567aa-da83-11e1-afad-12313b01d5c1","username":"john.doe",
"image":{"duration":0,"height":80,"url":"http://www.gravatar.com/avatar/","width":80},
"email":"john.doe@gmail.com"},"verb":"post","content":"Hello World!"}'

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

var options = {
    method:'POST',
    endpoint:'groups/mygroup/activities',
    body:{"actor":
           {"displayName":"John Doe",
            "uuid":"1f3567aa-da83-11e1-afad-12313b01d5c1",
            "username":"john.doe",
            "image":
             {"duration":0,
              "height":80,
              "url":"http://www.gravatar.com/avatar/",
              "width":80},
              "email":"john.doe@gmail.com"},
             "verb":"post",
             "content":"Hello World!"}
};
client.request(options, function (err, data) {
    if (err) {
        //error — POST failed
    } else {
        //success — POST worked. 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['groups/mygroup/activities'].post { actor:{ displayName: 'John Doe', uuid : '1f3567aa-da83-11e1-afad-12313b01d5c1', username: 'john.doe', image: { duration: 0, height: 80, url: 'http://www.gravatar.com/avatar/', width: 80 }, email: 'john.doe@gmail.com' }, verb: 'post', content: 'Hello World!' }

The example assumes use of the Node.js module.

var options = {
    method:'POST',
    endpoint:'groups/mygroup/activities',
    body:{"actor":
           {"displayName":"John Doe",
            "uuid":"1f3567aa-da83-11e1-afad-12313b01d5c1",
            "username":"john.doe",
            "image":
             {"duration":0,
              "height":80,
              "url":"http://www.gravatar.com/avatar/",
              "width":80},
              "email":"john.doe@gmail.com"},
             "verb":"post",
             "content":"Hello World!"}
};
client.request(options, function (err, data) {
    if (err) {
        //error — POST failed
    } else {
        //success — POST worked. Data will contain raw results from API call.        
    }
});

Because this relationship exists, this activity will appear in the feed of all users who are members of mygroup. It won't appear in the feeds of the group members’ followers or in feeds of users they follow.

Example - Response

{
  "action": "post",
  "application": "3400ba10-cd0c-11e1-bcf7-12313d1c4491",
  "params":  {},
  "path": "/groups/d87edec7-fc4d-11e1-9917-12313d1520f1/activities",
  "uri": "https://api.usergrid.com/my-org/my-app/groups/d87edec7-fc4d-11e1-9917-12313d1520f1/activities",
  "entities":  [
     {
      "uuid": "563f5d96-37f3-11e2-a0f7-02e81ae640dc",
      "type": "activity",
      "created": 1353952903811,
      "modified": 1353952903811,
      "actor":  {
        "displayName": "John Doe",
        "uuid": "1f3567aa-da83-11e1-afad-12313b01d5c1",
        "username": "john.doe",
        "image":  {
          "duration": 0,
          "height": 80,
          "url": "http://www.gravatar.com/avatar/",
          "width": 80
        },
        "email": "john.doe@gmail.com"
      },
      "content": "Hello World!",
      "metadata":  {
        "path": "/groups/d87edec7-fc4d-11e1-9917-12313d1520f1/activities/563f5d96-37f3-11e2-a0f7-02e81ae640dc"
      },
      "published": 1353952903811,
      "verb": "post"
    }
  ],
  "timestamp": 1353952903800,
  "duration": 81,
  "organization": "my-org",
  "applicationName": "my-app"

Creating an activity for a user's followers in a group

Use the POST method to create an activity that will be published only in the feeds of users who (1) follow you, and (2) are in the same group to which you posted the activity. This is useful if you want to create specific groups of friends (for example, acquaintances or colleagues) and publish content to them with more precise privacy settings. This allows you to re-create a privacy model similar to Google+’s Circles or Facebook current privacy system.

When you create an activity for a user’s followers in a group:

  • The activity is accessible at the /activities endpoint to users who have the permission to read that endpoint. The activity will not be cross-posted to the group’s activity endpoint (/groups/{uuid|groupname}/activities)
  • A relationship is automatically created between the activity entity that was just created and the user within that group (/groups/{uuid|groupname}/users/{uuid|username})
  • The user within the group (/groups/{uuid|groupname}/users/{uuid|username}) becomes the owner of the activity (through the owner property in the activity).

Request URI

POST /{org_id}/{app_id}/groups/{uuid|groupname}/users/{uuid|username}/activities {request body}

Parameters

Parameter Description
arg uuid|string org_id Organization UUID or organization name
arg uuid|string app_id Application UUID or application name
arg uuid|string groupname UUID or name of the group
arg uuid|string username UUID or name of the user
request body

One or more sets of activity properties:

{
  "actor":
    {
    "displayName":"John Doe",
    "uuid":"1f3567aa-da83-11e1-afad-12313b01d5c1",
    "username":"john.doe",
    "image":{
      "duration":0,
      "height":80,
      "url":"http://www.gravatar.com/avatar/","width":80},
  "email":"john.doe@gmail.com"},
  "verb":"post",
  "content":"Hello World!"    
}

Example - Request

curl -X POST "https://api.usergrid.com/my-org/my-app/groups/mygroup/users/john.doe/activities" -d '{"actor":{"displayName":"John Doe","uuid":"1f3567aa-da83-11e1-afad-12313b01d5c1","username":"john.doe",
"image":{"duration":0,"height":80,"url":"http://www.gravatar.com/avatar/","width":80},
"email":"john.doe@gmail.com"},"verb":"post","content":"Hello World!"}'

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

var options = {
    method:'POST',
    endpoint:'groups/mygroup/users/john.doe/activities',
    body:{"actor":
           {"displayName":"John Doe",
            "uuid":"1f3567aa-da83-11e1-afad-12313b01d5c1",
            "username":"john.doe",
            "image":
             {"duration":0,
              "height":80,
              "url":"http://www.gravatar.com/avatar/",
              "width":80},
              "email":"john.doe@gmail.com"},
             "verb":"post",
             "content":"Hello World!"}
};
client.request(options, function (err, data) {
    if (err) {
        //error — POST failed
    } else {
        //success — POST worked. 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['groups/mygroup/users/john.doe/activities'].post { actor:{ displayName: 'John Doe', uuid : '1f3567aa-da83-11e1-afad-12313b01d5c1', username: 'john.doe', image: { duration: 0, height: 80, url: 'http://www.gravatar.com/avatar/', width: 80 }, email: 'john.doe@gmail.com' }, verb: 'post', content: 'Hello World!' }

The example assumes use of the Node.js module.

var options = {
    method:'POST',
    endpoint:'groups/mygroup/users/john.doe/activities',
    body:{"actor":
           {"displayName":"John Doe",
            "uuid":"1f3567aa-da83-11e1-afad-12313b01d5c1",
            "username":"john.doe",
            "image":
             {"duration":0,
              "height":80,
              "url":"http://www.gravatar.com/avatar/",
              "width":80},
              "email":"john.doe@gmail.com"},
             "verb":"post",
             "content":"Hello World!"}
};
client.request(options, function (err, data) {
    if (err) {
        //error — POST failed
    } else {
        //success — POST worked. Data will contain raw results from API call.        
    }
});

Because this relationship exists, this activity will appear in the feed of all users who are members of mygroup. It won't appear in the feeds of the group members’ followers or in feeds of users they follow.

Example - Response

{
  "action" : "post",
  "application" : "3400ba10-cd0c-11e1-bcf7-12313d1c4491",
  "params" : { },
  "path" : "/groups/d87edec7-fc4d-11e1-9917-12313d1520f1/users/34e26bc9-2d00-11e2-a065-02e81ae640dc/activities",
  "uri" : "https://api.usergrid.com/my-org/my-app/
/groups/d87edec7-fc4d-11e1-9917-12313d1520f1/users/34e26bc9-2d00-11e2-a065-02e81ae640dc/activities",
  "entities" : [ {
    "uuid" : "2440ca58-49ff-11e2-84c0-02e81adcf3d0",
    "type" : "activity",
    "created" : 1355937094825,
    "modified" : 1355937094825,
    "actor" : {
      "displayName" : "John Doe",
      "uuid" : "1f3567aa-da83-11e1-afad-12313b01d5c1",
      "username" : "john.doe",
      "image" : {
        "duration" : 0,
        "height" : 80,
        "url" : "http://www.gravatar.com/avatar/",
        "width" : 80
      },
      "email" : "john.doe@gmail.com"
    },
    "content" : "Happy New Year!",
    "metadata" : {
      "path" : "/groups/d87edec7-fc4d-11e1-9917-12313d1520f1/users/34e26bc9-2d00-11e2-a065-02e81ae640dc/activities/2440ca58-49ff-11e2-84c0-02e81adcf3d0"
    },
    "published" : 1355937094825,
    "verb" : "post"
  } ],
  "timestamp" : 1355937094789,
  "duration" : 95,
  "organization" : "my-org",
  "applicationName" : "my-app"

Help or comments?

  • Something's not working: See Apigee Support
  • Something's wrong with the docs: Click Send Feedback in the lower right.
    (Incorrect? Unclear? Broken link? Typo?)