How To Programmatically Upload Large Files to Yammer Using Rest API and AAD Token – Part 1 - Netwoven
Blog

How To Programmatically Upload Large Files to Yammer Using Rest API and AAD Token – Part 1

By Subhankar Roy  |  Published on March 2, 2021

How To Programmatically Upload Large Files to Yammer Using Rest API and AAD Token – Part 1

Introduction:

If your organization uses Yammer as its internal socializing platform, you may be tempted to share files here to reach out to the set of audience specified by the Yammer group, instead of the conventional email method, which not only makes adding recipients seem cumbersome, but also formal.

Not only text messages, but using Yammer documented File Upload API files can also be uploaded programmatically to Yammer groups; however this method limits the maximum file size to only 4MB, which is very small.

This may not be a widely known limitation until someone tries to programmatically upload a large file to Yammer.

An alternative Yammer APIs which does not have any limitation on maximum file size is discussed in this article, though these set of APIs are not yet officially documented by Microsoft / Yammer team yet.

In this two-parts article we are going to create an AAD app (Part 1) and a C# console application (Part 2) to fetch AAD token by user login prompt and use the generated token to upload large files using unofficial Yammer API.

Pre-requisites

  • Any version of Visual Studio (tested well with Visual Studio 2019)
  • An active user account in Azure Active Directory having access to Yammer as well
  • Azure Active Directory (AAD) app for authentication and generating the delegated token

Azure AD App

Register a new app in Azure Active Directory

Follow the below steps supported by the following screenshot:

  1. Sign into the Azure portal from https://portal.azure.com.
  2. If your account gives you access to more than one tenant, select your account in the top right corner, and set your portal session to the Azure AD tenant that you want.
  3. In the left-hand navigation pane, select the Azure Active Directory service, and then select App registrations > New registration.
  4. When the Register an application page appears, enter your application’s registration information:
  5. Name: Enter a meaningful application name that will be displayed to users of the app. (E.g. YammerADApp)
  6. Supported account types: Accounts in this organizational directory only.
  7. Redirect URI: Type as Public client/native (mobile & desktop) and URI to https://login.microsoftonline.com/common/oauth2/nativeclient
  8. When finished, select Register.
How To Programmatically Upload Large Files to Yammer Using Rest API and AAD Token – Part 1

Grant permissions to Azure AD App

Open the newly created Azure AD App and perform the following steps:

  • Click on API permission from left navigation.
  • Click on Add a permission.
  • From the Request API permissions screen Click on “Yammer”.
How To Programmatically Upload Large Files to Yammer Using Rest API and AAD Token – Part 1
  • Click on Delegated permissions.
  • Select “user_impersonation” and click on Add Permission button.
How To Programmatically Upload Large Files to Yammer Using Rest API and AAD Token – Part 1
  • App would already have “Microsoft Graph” > “User.Read” permission; if not, add this permission as well following the steps above.

Enabling OAuth 2 Token generation for Azure AD App

Open the newly created Azure AD App and perform the following steps:

  1. Click on “Manifest” from left navigation.
  2. From right hand pane change the following JSON keys to true.
    • “oauth2AllowIdTokenImplicitFlow”: true,
    • “oauth2AllowImplicitFlow”: true
  3. Click on Save to save the changes
How To Programmatically Upload Large Files to Yammer Using Rest API and AAD Token – Part 1

Capture Azure AD Application Identifier

Open the newly created Azure AD App and perform the following steps:

  1. Click on “Overview” from left navigation.
  2. From right hand pane copy the Application ID and Directory ID and save for future uses.
How To Programmatically Upload Large Files to Yammer Using Rest API and AAD Token – Part 1

Summary

Once all the above steps are completed, we are ready to use the above Azure AD app for token generation and we are going to use the same in our C# application.

Do not miss the next part of this article where we create a C# console application that can be used to upload large files to Yammer using the AAD token.

Read Next Part :

How To Programmatically Upload Large Files to Yammer Using Rest API and AAD Token – Part 2

Leave a comment

Your email address will not be published. Required fields are marked *

Unravel The Complex
Stay Connected

Subscribe and receive the latest insights

Netwoven Inc. - Microsoft Solutions Partner

Get involved by tagging Netwoven experiences using our official hashtag #UnravelTheComplex