Friday, May 20, 2016

UCWA 2.0 and Skype for Business online: Adding a contact

Authentication and Resources

While authentication using Azure AD and resources in UCWA 2.0 are not the topic of this post, they're necessary to get to the point of adding a contact to the Skype for Business contact list. I found this StackOverflow post very helpful, along with the Microsoft documentation. Also, understanding the nested formation of URL resources can be difficult, this Microsoft documentation is clarifying and can add some much needed visualization to the problem.

Adding a contact to the Skype for Business contact list

To add a new contact to the Skype for Business contact list with UCWA 2.0, a POST request will be made to the "people" resource myGroupMemberships. This path will look something like 
This path should be appended to the end of the UCWA application resource URL, such as:
The URI of the new contact will be passed as a parameter in this URL. So, if the contact's URI is, it will look something like:

There is an option to create the new contact in a specific group by including the ID of the group the contact should be added to. This demonstration doesn't include the group ID, so the contact is added to the default group. In the test cases, this was the group "Other Contacts".

All requests to UCWA resources require a bearer token to be present in the authentication header. Also, because the myGroupMemberships resource that's being accessed is in UCWA version 2.0, this version needs to be specified in the POST request with the "X-MS-RequiresMinResourceVersion" header, such as
float version = 2.0F;
client.DefaultRequestHeaders.Add("X-MS-RequiresMinResourceVersion", version.ToString());
If this POST request is made to the correct application URL with the bearer token, and version header, the new contact should appear in the authenticated user's Skype for Business client almost immediately. In rare cases, it might be necessary to log-out and then back in to see the changes.

This MSDN forum post was very helpful for this blog.