Wowza Community

Using javascript fetch() fails to access Wowza REST API

Hello,

I’m using Wowza Streaming Engine 4.8.5

I can successfully access the Wowza Streaming Engine API using the cURL commands such as the one below, but cannot get the equivalent to work in javascript using fetch(). Can anyone provide any guidance? I’m using Vanilla JS.

curl --digest -u "wowza:i-myAWSinstanceID" -X GET \
-H 'Accept:application/json; charset=utf-8' \
-H 'Content-Type:application/json; charset=utf-8' \
http://3.90.142.82:8087/v3/servers/_defaultServer_/publishers

However the equivalent javascript fetch() will fail:

fetch("http://3.90.142.82:8087/v3/servers/_defaultServer_/publishers", {
  headers: {
    Accept: "application/json; charset=utf-8",
    Authorization: "Basic d293emE6aS1teUFXU2luc3RhbmNlSUQ=",
    "Content-Type": "application/json; charset=utf-8"
  }
})

And I receive the following authentication errors:

1. body: (...)
2. bodyUsed: true
3. headers: Headers {}
4. ok: false
5. redirected: false
6. status: 401
7. statusText: "Unauthorized"
8. type: "cors"
9. url: "http://3.90.142.82:8087/v3/servers/_defaultServer_/publishers"

With the following JSON response:

1. code: "401"
2. message: "The request requires user authentication"
3. success: false
4. wowzaServer: "4.8.5"

Are there any javascript examples for accessing the Wowza Streaming Engine API?

Regarding a Javascript example, Wowza does not have this at this time.

There are some third party examples if you do a quick internet search, but these are not created, supported or maintained by wowza and we would not be able to assist with it in technical support.

There are also some non-Wowza examples on Stack Overflow if you search there. Other options include Hire a Consultant forum for custom code or Pro Services.

If your WSE is indeed setup to use Basic Auth for the REST API then you should authenticate with user:pass in the URL and not in the header.

Prior to 4.8.8.01 there was this problem that switching to Digest would cause the Engine Manager panel to fail because it was hard-coded to use Basic. Since 4.8.8.01 you can also choose to use Basic Auth and bcrypt.

For a Node.js project we use 3rd-party package ‘digest-fetch’, because there are calls to multiple services some of which use Digest and others use Basic Auth. For the calls to WSE REST API we use this:

const Digest = require('digest-fetch');
const client = new Digest("user", "pass", { basic: true });
const options = {
  method : 'PUT',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  }
};

var response = await client.fetch("http://wowza:8087/v3/servers...", options);
1 Like