{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","settings":"","results":{"codes":[]},"params":[]},"next":{"description":"","pages":[]},"title":"Code Samples","type":"basic","slug":"code-samples","excerpt":"","body":"Get started with using the Data Export API. Explore our samples and discover the things you can build. This Sample Code is provided for the purpose of illustration only and is not intended to be used as-is in a production environment.\n\n**Using the Yammer API to Set-up Recurring Exports**\nOn first run, the script will export all network data up from the beginning of the network up until present. From then on, it will automatically check for previous exports, and perform an export from the date of the previous export. This script can be used with common schedulers (Cron, etc) to easily set up recurring exports.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"#!/bin/sh\\n \\nif [! $1 -o ! $2 ]; then\\n  echo \\\"Usage: export.sh <OAuth Access Token> <Directory>\\\"\\n  exit 1\\nfi\\n \\n \\n# Your Yammer OAuth 2 Access Token. This must be a token for a verified admin account.\\nAT=$1\\n \\n# Download location for the export files\\nDIR=$2\\ncd $DIR\\n \\n# Find the last export if there is one. The start date and time of the previous export\\n# is encoded in the filename in UNIX time (http://en.wikipedia.org/wiki/unix_time)\\nLAST_EXPORT=`ls export-*.zip | sed -e 's/export-\\\\(.*\\\\)\\\\.zip/\\\\1/g' | sort -n | tail -l`\\n\\n# Check to see if a previous export was done\\nif [ ! $LAST_EXPORT ]; then\\n  # No previous export was done. Start at the beginning of time (or 1970, which is close enough given Yammer's age).\\n  LAST_EXPORT=0\\nfi\\n \\n# Convert UNIX time to ISO-8601 time, which the API endpoint accepts.\\nDATE=`date -j -r  $LAST_EXPORT \\\"+%Y-%m-%dT%H:%M:%S%z\\\"`\\n \\n# Calculate the current date in UNIX time for the filename of the export.\\nNEXT_EXPORT=`date \\\"+%s\\\"`\\n \\n# Perform the next export. Send the OAuth2 access token and store the UNIX time of this export in the filename.\\ncurl -v --output export-$NEXT_EXPORT.zip \\\\\\n  --header \\\"Authorization: Bearer $AT\\\" \\\\\\n  --get --data-urlencode since=$DATE \\\\\\n  \\\"https://export.yammer.com/api/v1/export\\\"\\n \\n# Verify the download completed\\nif [ $? != 0]; then\\n  echo \\\"Download failed...cleaning up.\\\"\\n  rm export-$NEXT_EXPORT.zip\\n  exit 1\\nfi\\n \\n# Verify the contents of the zip file.\\nunzip -t export-$NEXT_EXPORT.zip >/dev/null 2>&1\\nif [$? != 0 ]; then\\n  echo \\\"Invalid up file detected, export failed....removing downloaded ZIP\\\"\\n  rm export-$NEXT_EXPORT.zip\\n  exit 1\\nfi\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n**Sample Data Export Script for Windows**\nOn the first run, the script will export all network data up from the beginning of the network up until the present. From then on, it will automatically check for previous exports, and perform an export from the date of the previous export. This script can be used with Windows schedulers to create automatic, recurring exports.\n\nYou may need to install wget for Windows if you do not already have it installed. Here is a link to the latest version:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"http://sourceforge.net/projects/gnuwin32/files/wget/1.11.4-1/\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nMake sure to update your PATH environment variable to include the GNU bin path (e.g., C:Program Files (x86)GnuWin32bin).\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \":::at:::ECHO OFF\\n\\nIF [%1]==[ ] (\\n\\tIF [%2]==[ ](\\n\\t\\tECHO \\\"Usage: export.cdm <OAuth Access Token> <Directory>\\\"\\n\\t\\tEXIT /B\\n\\t)\\n)\\n\\n:: Your Yammer Oauth 2 Access Token. This must be a token for a verified admin account. \\nSET AT=%1\\n\\n:: Download location for the export files.\\nSET DIR=%2\\ncd %DIR%\\n\\n:: Find the last export of there is one. The start date and time of the previous export is encoced in the filename \\nSET LAST_EXPORT=0\\nIF EXIST export-*.zip (\\n\\tFOR /f \\\"delims=\\\" %%a in ('dir /B /D export-*.zip') do(\\n\\t\\t:: Use the timestamp from the most recent file\\n\\t\\tSET LAST_EXPORT=%%a\\n  )\\n)\\n\\n:: Remove the relevant parts of the filename so the timestamp can be stored \\nSET LAST_EXPORT=%LAST_EXPORT:export-=%\\nSET LAST_EXPORT=%LAST_EXPORT:.zip=%\\n:: Don't foget the replace the underscore with the colons to ensure correct ISO-8601 formatting\\nSET LAST_EXPORT=%LAST_EXPORT:_=:%\\n\\n:: Calculate the current date in UNIX time for the filename of the export.\\nSET TIME_STAMP=%time:~0,2%:%time:~3,2%:%time:~6,2%z\\nSET NEXT_EXPORT=%date:~10,4%-%date:~4,2%-%date:~7,2%T%TIME_STAMP%\\n:: Make sure to replace \\\":\\\" with \\\"_\\\" so that Windows will save the file\\nSET NEXT_EXPORT=%NEXT_EXPORT::=_%\\n:: Make sure to replace any spaces with 0's. DOS doesn't always provide leading 0's when a time fragment is less than 10\\nSET NEXT_EXPORT=%NEXT_EXPORT: =0%\\n\\n::Preform the next export. Send the OAuth 2 access token and store the time of this export in the filename.\\nSET FILE_NAME=export-%NEXT_EXPORT%.zip\\nSET AUTH_HEADER=Authorization: Bearer %AT%\\nSET API_URL=https://export.yammer.com/api/v1/export\\nIF NOT EXIST cacert.pem ( wget http://curl.haxx.se/ca/cacert.pem )\\n\\nECHO %LAST_EXPORT%\\nwget -o %FILE_NAME% -t 1 --header \\\"%AUTH_HEADER%\\\" -ca-certificate cacert.pem\\n%API_URL%?since=%LAST_EXPORT%\",\n      \"language\": \"powershell\"\n    }\n  ]\n}\n[/block]\nData Export API Sample Code\nCopyright (c) Microsoft Corporation\nAll rights reserved.\nMIT License\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"\"Software\"\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\nTHE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.","updates":[],"order":2,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"605d6c322f1aef0054d29875","createdAt":"2021-03-26T05:08:02.906Z","user":"5cd352a0d05b5a000f225f36","category":{"sync":{"isSync":false,"url":""},"pages":["547391bf007eb108007e042c"],"title":"Data Export","slug":"data-export-api","order":5,"from_sync":false,"reference":false,"_id":"546ced235884600e007a92f6","__v":1,"project":"545137a814af501a00b50cf9","createdAt":"2014-11-19T19:18:59.863Z","version":"545137a814af501a00b50cfc"},"version":{"version":"1.0","version_clean":"1.0.0","codename":"","is_stable":true,"is_beta":true,"is_hidden":false,"is_deprecated":false,"categories":["545137a814af501a00b50cfd","545138eaa66f020800dbab4a","546b9072b47b5d1400109edf","546b9082b47b5d1400109ee0","546b9088b47b5d1400109ee1","546b909462515a14007ebc43","546b90a0b47b5d1400109ee2","546ced235884600e007a92f6","5481008eea7fd40b00cd7c2b","573b9d83ee2b3b220042291f","57be1efa15efc70e006a5f99","5ee004f52c97b4004c7a5876"],"_id":"545137a814af501a00b50cfc","project":"545137a814af501a00b50cf9","__v":12,"createdAt":"2014-10-29T18:53:28.525Z","releaseDate":"2014-10-29T18:53:28.525Z"},"project":"545137a814af501a00b50cf9","__v":0,"parentDoc":null}
Get started with using the Data Export API. Explore our samples and discover the things you can build. This Sample Code is provided for the purpose of illustration only and is not intended to be used as-is in a production environment. **Using the Yammer API to Set-up Recurring Exports** On first run, the script will export all network data up from the beginning of the network up until present. From then on, it will automatically check for previous exports, and perform an export from the date of the previous export. This script can be used with common schedulers (Cron, etc) to easily set up recurring exports. [block:code] { "codes": [ { "code": "#!/bin/sh\n \nif [! $1 -o ! $2 ]; then\n echo \"Usage: export.sh <OAuth Access Token> <Directory>\"\n exit 1\nfi\n \n \n# Your Yammer OAuth 2 Access Token. This must be a token for a verified admin account.\nAT=$1\n \n# Download location for the export files\nDIR=$2\ncd $DIR\n \n# Find the last export if there is one. The start date and time of the previous export\n# is encoded in the filename in UNIX time (http://en.wikipedia.org/wiki/unix_time)\nLAST_EXPORT=`ls export-*.zip | sed -e 's/export-\\(.*\\)\\.zip/\\1/g' | sort -n | tail -l`\n\n# Check to see if a previous export was done\nif [ ! $LAST_EXPORT ]; then\n # No previous export was done. Start at the beginning of time (or 1970, which is close enough given Yammer's age).\n LAST_EXPORT=0\nfi\n \n# Convert UNIX time to ISO-8601 time, which the API endpoint accepts.\nDATE=`date -j -r $LAST_EXPORT \"+%Y-%m-%dT%H:%M:%S%z\"`\n \n# Calculate the current date in UNIX time for the filename of the export.\nNEXT_EXPORT=`date \"+%s\"`\n \n# Perform the next export. Send the OAuth2 access token and store the UNIX time of this export in the filename.\ncurl -v --output export-$NEXT_EXPORT.zip \\\n --header \"Authorization: Bearer $AT\" \\\n --get --data-urlencode since=$DATE \\\n \"https://export.yammer.com/api/v1/export\"\n \n# Verify the download completed\nif [ $? != 0]; then\n echo \"Download failed...cleaning up.\"\n rm export-$NEXT_EXPORT.zip\n exit 1\nfi\n \n# Verify the contents of the zip file.\nunzip -t export-$NEXT_EXPORT.zip >/dev/null 2>&1\nif [$? != 0 ]; then\n echo \"Invalid up file detected, export failed....removing downloaded ZIP\"\n rm export-$NEXT_EXPORT.zip\n exit 1\nfi", "language": "shell" } ] } [/block] **Sample Data Export Script for Windows** On the first run, the script will export all network data up from the beginning of the network up until the present. From then on, it will automatically check for previous exports, and perform an export from the date of the previous export. This script can be used with Windows schedulers to create automatic, recurring exports. You may need to install wget for Windows if you do not already have it installed. Here is a link to the latest version: [block:code] { "codes": [ { "code": "http://sourceforge.net/projects/gnuwin32/files/wget/1.11.4-1/", "language": "text" } ] } [/block] Make sure to update your PATH environment variable to include the GNU bin path (e.g., C:Program Files (x86)GnuWin32bin). [block:code] { "codes": [ { "code": "@ECHO OFF\n\nIF [%1]==[ ] (\n\tIF [%2]==[ ](\n\t\tECHO \"Usage: export.cdm <OAuth Access Token> <Directory>\"\n\t\tEXIT /B\n\t)\n)\n\n:: Your Yammer Oauth 2 Access Token. This must be a token for a verified admin account. \nSET AT=%1\n\n:: Download location for the export files.\nSET DIR=%2\ncd %DIR%\n\n:: Find the last export of there is one. The start date and time of the previous export is encoced in the filename \nSET LAST_EXPORT=0\nIF EXIST export-*.zip (\n\tFOR /f \"delims=\" %%a in ('dir /B /D export-*.zip') do(\n\t\t:: Use the timestamp from the most recent file\n\t\tSET LAST_EXPORT=%%a\n )\n)\n\n:: Remove the relevant parts of the filename so the timestamp can be stored \nSET LAST_EXPORT=%LAST_EXPORT:export-=%\nSET LAST_EXPORT=%LAST_EXPORT:.zip=%\n:: Don't foget the replace the underscore with the colons to ensure correct ISO-8601 formatting\nSET LAST_EXPORT=%LAST_EXPORT:_=:%\n\n:: Calculate the current date in UNIX time for the filename of the export.\nSET TIME_STAMP=%time:~0,2%:%time:~3,2%:%time:~6,2%z\nSET NEXT_EXPORT=%date:~10,4%-%date:~4,2%-%date:~7,2%T%TIME_STAMP%\n:: Make sure to replace \":\" with \"_\" so that Windows will save the file\nSET NEXT_EXPORT=%NEXT_EXPORT::=_%\n:: Make sure to replace any spaces with 0's. DOS doesn't always provide leading 0's when a time fragment is less than 10\nSET NEXT_EXPORT=%NEXT_EXPORT: =0%\n\n::Preform the next export. Send the OAuth 2 access token and store the time of this export in the filename.\nSET FILE_NAME=export-%NEXT_EXPORT%.zip\nSET AUTH_HEADER=Authorization: Bearer %AT%\nSET API_URL=https://export.yammer.com/api/v1/export\nIF NOT EXIST cacert.pem ( wget http://curl.haxx.se/ca/cacert.pem )\n\nECHO %LAST_EXPORT%\nwget -o %FILE_NAME% -t 1 --header \"%AUTH_HEADER%\" -ca-certificate cacert.pem\n%API_URL%?since=%LAST_EXPORT%", "language": "powershell" } ] } [/block] Data Export API Sample Code Copyright (c) Microsoft Corporation All rights reserved. MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.