Was this helpful?

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 /activites 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 Entities). 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.“

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.