Available: | Activity Streams 5.0 and later. |
We've added a new feature to Activity Streams that allows anyone to add activities to an Atlassian application's feed via a simple REST api. Activities added via this api can be associated with projects, users, and other targets such as Jira issues, Confluence spaces, and Bamboo builds. For example, an activity associated with a Jira issue will appear in the Activity tab on the View Issue page.
We'll walk through the feature, starting with the simplest possible example.
Let's assume the application is running at localhost:3990/jira. To add an activity to the feed, POST a JSON document to localhost:3990/jira/rest/activities/1.0/. You need to authenticate (e.g. with basic auth), and the content-type header should be set to application/vnd.atl.streams.thirdparty+json
. The document must adhere to the activitystrea.ms JSON specification. There are two deviations from the specification:
Here's the simplest possible document that displays something interesting:
Minimal example
1 2{ "actor": { "id": "user" }, "generator" : { "id": "http://www.bitbucket.org", "displayName" : "Bitbucket" }, "id" : "http://bitbucket.org/jkodumal", "title" : "Merge commit '68041056c69461d93958197cdb401a9ba4e5a0a4' into HEAD", "content" : "<blockquote>Compile with '-unchecked -deprecation' and clean up what we found.</blockquote>" }
And here's how this is displayed in the stream:
Here's a brief explanation of the meaning of the fields in the document:
You can post this document with any http client. For simplicity, here's how you might do it using curl
, a widely available command line tool (assume that the above document was saved as "sample.json", and that admin / admin is a valid username / password):
1 2curl -u admin:admin --data-binary @sample.json -H "Content-Type:application/vnd.atl.streams.thirdparty+json" http://localhost:3990/jira/rest/activities/1.0/
RESTClient is another easy to use tool for testing out this feature.
When you successfully post an activity, you'll receive a 201 CREATED response, along with a copy of the document containing additional information. The new information includes a "links" map containing a URL with a "self" link. That's the URL of the activity you just posted. If you do a GET on that URL, you'll fetch a copy of that document. If you do a DELETE, you'll remove it from the system.
You probably only want to delete activities for testing purposes. On production instances, it's probably best to keep activities indefinitely.
Let's show a more complete version of the same activity to demonstrate some additional capabilities:
A complete example
1 2{ "published": "2011-02-10T15:04:55.000Z", "actor": { "id": "jko", "image": { "url": "http://www.gravatar.com/avatar/00a08e3ffde37612301a0d65824cb6cb?s=48", "width": 48, "height": 48 } }, "icon" : { "url": "https://bitbucket.org/favicon.ico", "width" : "16", "height" : "16" }, "object" : { "id": "csid19021043803344554", "objectType": "changeset", "url" : "https://bitbucket.org/scalatra/scalatra/commit/a74e68d7de52f98c1ea4f3c48fd5bbec70fa507c" }, "generator" : { "id": "http://www.bitbucket.org", "displayName" : "Bitbucket" }, "target": { "url": "ONE-1" }, "id" : "http://bitbucket.org/jko/", "title" : "Merge commit '68041056c69461d93958197cdb401a9ba4e5a0a4' into HEAD", "content" : "<blockquote>Compile with '-unchecked -deprecation' and clean up what we found.</blockquote>" }
We've used the same title and content, but we've added a few additional fields to the document. Let's walk through the changes.
We recommend adhering to the following guidelines in order to make your activity entry appear consistent with the "native" activity feed:
Rate this page: