Recently a colleague from a previous employer of mine pinged me about connecting to Skype for Business using the Unified Communications Web API (UCWA). UCWA is the REST API that comes with Skype for Business 2015 and exposes Instant Messaging and Presence capabilities. Initially UCWA was only for the OnPremise release of S4B, but this has recently been extended to Skype for Business Online.

The detail on leveraging the UCWA is all here however when it comes to actually doing it, it gets a little daunting. This blog by Matthew Proctor gives more hope and a few more threads to pull on to get something working. After jumping through a few hoops and also being pointed in the right direction from this post from Adam I got the sequence sorted to authenticate, access the API using PowerShell and then actually doing something with it. I thought I’d write it up so I can save someone else the pain (and myself if I need it in the future).

Getting Started

As per the title I’m going to show you connecting to and consuming information from Skype for Business Online using PowerShell. Naturally you’re going to need to have an Office365 Tenant with S4B and all the pre-requisites associated with that configured (such as your CNAME and SRV S4B DNS settings etc).

This post covers using PowerShell to:

  • Authenticate to the UCWA API
  • Get your S4B account details
  • Change your status between Busy, Away and Available, Do not disturb
  • Get your Contacts
  • Get your Contacts status

That should give you enough to also get started and munge it for whatever you need.


The following script gets you authenticated to S4B Online via the API. Change the script for your S4BO account and associated password. Also update for your S4BO tenant Autodiscover URL.

Create the UCWA Application

The following script will create an application on the UCWA endpoint. The Endpoint ID you can make up yourself. Same for the Application name.


Change your Presence, Get your Contacts &  their Status

Now you can do what you want or need to with the API. Here are a few examples of changing your status, getting your contacts, getting the status of your contacts.

Contacts Statuses

Contacts List

Follow Darren on Twitter @darrenjrobinson

Communication and Collaboration, Lync, PowerShell, Skype For Business

Join the conversation! 14 Comments

  1. […] Querying Skype for Business Online using UCWA and PowerShell […]

  2. […] Querying Skype for Business Online using UCWA and PowerShell […]

  3. $rootappurl is not defined. What’s that supposed to be?

  4. Thanks, that works now.

    Now trying pull out the conferenceID for the current user (e.g. from the Dial-in Conferencing page). I have the onlineMeeting ID so can construct the MeetingURL but the conference ID eludes me.

    I got the onlineMeetingID (the last part of the current user’s default MeetingURL like this:
    $data = Invoke-WebRequest -Uri (“$rootappurl/$appid/onlineMeetings/myOnlineMeetings”) -Method Get -Headers @{“Authorisation”=”Bearer $authcwt”} -ContentType “application/json” -UseBasicParsing

    $onlineMeetingID = ($data.content | ConvertFrom-Json)._embedded.myAssignedOnlineMeeting.onlineMeetingID

    Any idea where the ConferenceID can be found?

  5. I was reading that doc but I never would have thought of that. Works like a charm. You’re a legend. Thanks.

  6. Have this pretty solid now. Thanks for your help. Started down another rabbit hole which is conversation history.

    If I look under here:

    I see conversations, startMessaging, startOnlineMeeting and joinOnlineMeeting

    Seems like i should have a few more:

    But the one I think I really need is conversationLogs. Any idea why it’s missing or how to get at it?


    • Hey Tony, yes I’m seeing the same as you. It appears to be because of the scope of the application. Looks like to access CommunicationLogs we need to specify a different scope. I’ll have a mess around and see if I can work it out.

  7. Hello,

    Thanks for the great script but i have an issue on office 365, i receive the following error when it gets the oauth token :


    Does it mean we can’t make it work with a full O365 s4b infra ?


  8. Hello Darren,

    I desperately tried to use your code to access to Skype for Business Online, and I’m stuck at the Oauth request.
    So do we have to register a specific UCWA apps prior to run the scripts ?
    If yes, what is the process ?


    • I’m guessing you are getting an error from the webrequest response on line 20? Something like
      Invoke-WebRequest :
      500 – Internal server error.
      Server Error

      500 – Internal server error.
      There is a problem with the resource you are looking for, and it cannot be displayed.

      This is usually the case if the account you are using has the password to not-expire. Change the password for the account and you should be all good.

      Alternatively you may have S4B configured in a different method. If you are on Domain joined machine, try using the Integrated Windows Authentication Grant Type as detailed here urn:microsoft.rtc:windows


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: