Azure Media Service is a great turn-key solution for your video-on-demand and live streaming needs. It’s has been well documented in the
Azure official site, however, it’s still not much information talking about AMS Node.js SDK and the AMS REST API. So, I’m going to talk a little bit about it in this blog.
1.There’s no offical Node.js SDK yet
Michelle’s Node project covers many of the functions, but it’s still missing some functions of Live Streaming. So if you need to use some live streaming functions, you can definitely leverage this.
2. How to make a successful call to AMS REST API using Node
There are many ways that you can test the API first, one of these is using
POSTMAN. Note that you have to have an Azure subscription to do this.
You can follow this information to get your token back:
URL: https://wamsprodglobal001acs.accesscontrol.windows.net/v2/OAuth2-13
Method: POST
Headers:
Content-Type: application/x-www-form-urlencoded
Host: wamsprodglobal001acs.accesscontrol.windows.net
Content-Length: 120
Expect: 100-continue
Connection: Keep-Alive
Accept: application/json
Body: (choose x-www-form-urlencoded, which means it will encode your parameters automatically)
grant_type: client_credentials
client_id: [YOUR_AMS_CLIENTID]
client_secret: [YOUR_AMS_CLIENTSECRETE]
scope: urn:WindowsAzureMediaServices
if you’ve done it successfully, you will get the response like below:
and then you can use this access_token to operate
AMS REST API.
if you want to implement it in Node.js, here are some tips that will save you some time.
a. if you follow the guide above and provide your header and body accordingly you might still encounter this error
{“error”:”invalid_client”,”error_description”:”ACS50012: Authentication failed.rnTrace ID: 621b507f-d2f5-4fc6-b208-9bafc83aba68rnCorrelation ID: 67435ae3-3f3f-485a-b58d-85f28eabf2c9rnTimestamp: 2016-01-06 08:32:42Z”}
so what to do then?
please modify the headers and body as below, then you should be able to get your token back.

Header:
‘accept’: ‘application/json;odata=verbose’,
‘Content-Type’: ‘application/json;odata=verbose’,
DataServiceVersion: ‘3.0’,
MaxDataServiceVersion: ‘3.0’,
‘x-ms-version’: ‘2.5’
Body:
scope: ‘urn:WindowsAzureMediaServices’,
grant_type: ‘client_credentials’,
client_id: ‘[YOUR_CLIENT_ID’,
client_secret: ‘[YOUR_CLIENT_SECRETE]’
3.APIs regarding live streaming
Please refer
this document to operation Channels, and Programs…etc
I’ll find time to blog about this API.