{"_id":"546b9234b47b5d1400109efc","project":"545137a814af501a00b50cf9","user":"5433099f9a2b451a00ad4531","__v":7,"category":{"_id":"545137a814af501a00b50cfd","project":"545137a814af501a00b50cf9","version":"545137a814af501a00b50cfc","pages":["545137a814af501a00b50cff","5451389e14af501a00b50d11","5451384514af501a00b50d04","546b8edb62515a14007ebc39","546b9214b47b5d1400109efa","546b922862515a14007ebc4f","546b9234b47b5d1400109efc","546b924762515a14007ebc51","546b925662515a14007ebc53","546fdac1691dc8080089521d","547374bd007eb108007e0380"],"__v":11,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-10-29T18:53:28.598Z","from_sync":false,"order":0,"slug":"documentation","title":"Documentation"},"version":{"_id":"545137a814af501a00b50cfc","project":"545137a814af501a00b50cf9","__v":11,"createdAt":"2014-10-29T18:53:28.525Z","releaseDate":"2014-10-29T18:53:28.525Z","categories":["545137a814af501a00b50cfd","545138eaa66f020800dbab4a","546b9072b47b5d1400109edf","546b9082b47b5d1400109ee0","546b9088b47b5d1400109ee1","546b909462515a14007ebc43","546b90a0b47b5d1400109ee2","546ced235884600e007a92f6","5481008eea7fd40b00cd7c2b","573b9d83ee2b3b220042291f","57be1efa15efc70e006a5f99"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2014-11-18T18:38:44.442Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"settings":"","try":true,"basic_auth":false,"results":{"codes":[]},"auth":"never","params":[],"url":""},"isReference":false,"order":3,"body":"**Write Data Into Yammer Using Open Graph**\n\nOnce your app has been successfully authenticated, it can write data into Yammer or read data from Yammer. Most commonly, your app will post users' activity to Yammer as Open Graph objects. For example, let’s say a sales rep updated the price of a sales deal.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/DPkzMcqxT3qgqtQO2UdG_7-activity-stream-.png\",\n        \"7-activity-stream-.png\",\n        \"1005\",\n        \"692\",\n        \"\",\n        \"\"\n      ],\n      \"caption\": \"User activity displayed in Yammer’s Activity Stream\"\n    }\n  ]\n}\n[/block]\n##Here is a step-by-step tutorial of how to write a business activity to Yammer:\n\n**A. Define The Activity**\n\nStructure your business activity in the following format:\n\n<Actor> <Action> <Object> on <App Name>: <Message> For example, “Sidd Singh created ‘Lunch Meeting’ on Sched.do: ‘Hey, let’s get sushi!’”\n\n<Actor> is the Yammer user who created the activity. The actor is linked to the user’s Yammer profile when the activity is displayed in Yammer.\n\n<Action> is a verb that describes the activity. We currently support: Create, Update, Delete, Follow, and Like by default. Additionally you can create custom verbs.\n\n<Object> is the Open Graph (OG) object on which the action was taken. An OG object represents an entity instance in your application, for example, an event (e.g. lunch meeting) in Sched.do. OG objects are uniquely identified with their URL. Their title is displayed in Yammer as a link to the URL. We recommend sending Yammer as many properties for your OG objects as you can for appropriate display.\n\n<App Name> is the name of your app (specified when registering your app).\n\n<Message> is a free text field to provide context to the activity.\n\n<Users> is an optional field, which allows you to specify recipients of the activity. By default the actor and their followers on Yammer receive the activity. See more details at http://developer.yammer.com/v1.0/docs/open-graph, “Delivering to Users”.\n\n**B. Write The Activity**\n\nOnce you have defined what your activity should look like, the next step is to POST this activity into Yammer’s activity stream. This is done by defining the appropriate JSON payload and posting it to the API endpoint (below) using the Oauth access token you obtained earlier.\n\nPOST to: \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"https://www.yammer.com/api/v1/activity.json\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nMake sure to set the Content-type of the request body to “application/json”.\n\n*Oauth access token sent as a “Bearer” token in the “Authorization” request header:* \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"GET /api/v1/messages/following.json HTTP/1.1 \\nHost: www.yammer.com \\nAuthorization: Bearer abcDefGhi\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nFor more details on the “Bearer” token refer to http://tools.ietf.org/html/draft-ietf-oauth-v2-bearer-23\n\n*JSON Payload for the activity:* \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n\\\"activity\\\":{\\n\\\"actor\\\":{\\\"name\\\":\\\"Sidd Singh\\\",\\n\\\"email\\\":\\\"sidd:::at:::xyz.com\\\"},\\n\\\"action\\\":\\\"create\\\",\\n\\\"object\\\": {\\n\\\"url\\\":\\\"https://www.sched.do\\\",\\n\\\"title\\\":\\\"Lunch Meeting\\\"\\n},\\n\\\"message\\\":\\\"Hey, let’s get sushi!\\\",\\n\\\"users\\\":[\\n{\\\"name\\\":\\\"Adarsh Pandit\\\",\\n\\\"email\\\":\\\"adarsh@xyz.com\\\"}\\n]\\n}\\n}\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"def post_yammer_activity\\nuser.yammer_client.post('/activity', json_payload)\\nend\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"def json_payload\\n{\\nactivity: {\\nactor: {\\nname: user.name,\\nemail: user.email\\n},\\naction: action,\\nobject: {\\nurl: event_url(event),\\ntitle: event.name,\\nimage: 'http://' + ENV['HOSTNAME'] + '/logo.png'\\n}\\n},\\nmessage: '',\\nusers: invitees_for_json\\n}\\nend\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"def event\\n@event ||= Event.find(event_id)\\nend\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"def invitees_for_json\\nevent.invitees.map { |i| { name: i.name, email: i.email } }\\nend\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"writing-activity","type":"basic","title":"Step 3: Writing Activity"}

Step 3: Writing Activity


**Write Data Into Yammer Using Open Graph** Once your app has been successfully authenticated, it can write data into Yammer or read data from Yammer. Most commonly, your app will post users' activity to Yammer as Open Graph objects. For example, let’s say a sales rep updated the price of a sales deal. [block:image] { "images": [ { "image": [ "https://files.readme.io/DPkzMcqxT3qgqtQO2UdG_7-activity-stream-.png", "7-activity-stream-.png", "1005", "692", "", "" ], "caption": "User activity displayed in Yammer’s Activity Stream" } ] } [/block] ##Here is a step-by-step tutorial of how to write a business activity to Yammer: **A. Define The Activity** Structure your business activity in the following format: <Actor> <Action> <Object> on <App Name>: <Message> For example, “Sidd Singh created ‘Lunch Meeting’ on Sched.do: ‘Hey, let’s get sushi!’” <Actor> is the Yammer user who created the activity. The actor is linked to the user’s Yammer profile when the activity is displayed in Yammer. <Action> is a verb that describes the activity. We currently support: Create, Update, Delete, Follow, and Like by default. Additionally you can create custom verbs. <Object> is the Open Graph (OG) object on which the action was taken. An OG object represents an entity instance in your application, for example, an event (e.g. lunch meeting) in Sched.do. OG objects are uniquely identified with their URL. Their title is displayed in Yammer as a link to the URL. We recommend sending Yammer as many properties for your OG objects as you can for appropriate display. <App Name> is the name of your app (specified when registering your app). <Message> is a free text field to provide context to the activity. <Users> is an optional field, which allows you to specify recipients of the activity. By default the actor and their followers on Yammer receive the activity. See more details at http://developer.yammer.com/v1.0/docs/open-graph, “Delivering to Users”. **B. Write The Activity** Once you have defined what your activity should look like, the next step is to POST this activity into Yammer’s activity stream. This is done by defining the appropriate JSON payload and posting it to the API endpoint (below) using the Oauth access token you obtained earlier. POST to: [block:code] { "codes": [ { "code": "https://www.yammer.com/api/v1/activity.json", "language": "text" } ] } [/block] Make sure to set the Content-type of the request body to “application/json”. *Oauth access token sent as a “Bearer” token in the “Authorization” request header:* [block:code] { "codes": [ { "code": "GET /api/v1/messages/following.json HTTP/1.1 \nHost: www.yammer.com \nAuthorization: Bearer abcDefGhi", "language": "text" } ] } [/block] For more details on the “Bearer” token refer to http://tools.ietf.org/html/draft-ietf-oauth-v2-bearer-23 *JSON Payload for the activity:* [block:code] { "codes": [ { "code": "{\n\"activity\":{\n\"actor\":{\"name\":\"Sidd Singh\",\n\"email\":\"sidd@xyz.com\"},\n\"action\":\"create\",\n\"object\": {\n\"url\":\"https://www.sched.do\",\n\"title\":\"Lunch Meeting\"\n},\n\"message\":\"Hey, let’s get sushi!\",\n\"users\":[\n{\"name\":\"Adarsh Pandit\",\n\"email\":\"adarsh@xyz.com\"}\n]\n}\n}", "language": "text" } ] } [/block] [block:code] { "codes": [ { "code": "def post_yammer_activity\nuser.yammer_client.post('/activity', json_payload)\nend", "language": "text" } ] } [/block] [block:code] { "codes": [ { "code": "def json_payload\n{\nactivity: {\nactor: {\nname: user.name,\nemail: user.email\n},\naction: action,\nobject: {\nurl: event_url(event),\ntitle: event.name,\nimage: 'http://' + ENV['HOSTNAME'] + '/logo.png'\n}\n},\nmessage: '',\nusers: invitees_for_json\n}\nend", "language": "text" } ] } [/block] [block:code] { "codes": [ { "code": "def event\n@event ||= Event.find(event_id)\nend", "language": "text" } ] } [/block] [block:code] { "codes": [ { "code": "def invitees_for_json\nevent.invitees.map { |i| { name: i.name, email: i.email } }\nend", "language": "text" } ] } [/block]