# Using javascript fetch() fails to access Wowza REST API

**URL:** <https://community.wowza.com/t/using-javascript-fetch-fails-to-access-wowza-rest-api/93386>\
**Category:** Wowza Developer Dojo\
**Tags:** wowza-streaming-engine\
**Created:** [June 3, 2021, 6:22pm UTC](https://community.wowza.com/t/using-javascript-fetch-fails-to-access-wowza-rest-api/93386 "2021-06-03T18:22:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Kirkpatrick](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@Chris\_Kirkpatrick](https://community.wowza.com/u/Chris_Kirkpatrick)\
**Post date:** [June 3, 2021, 6:22pm UTC](https://community.wowza.com/t/using-javascript-fetch-fails-to-access-wowza-rest-api/93386/1 "2021-06-03T18:22:33Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![video\_streaming](https://avatars.discourse-cdn.com/v4/letter/v/22d042/32.png) [@video\_streaming](https://community.wowza.com/u/video_streaming)\
**Post date:** [June 3, 2021, 7:45pm UTC](https://community.wowza.com/t/using-javascript-fetch-fails-to-access-wowza-rest-api/93386/2 "2021-06-03T19:45:49Z")

</div>

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

There are some [third party examples](https://www.npmjs.com/package/wowza-js-api) 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.

---

<div class="post-metadata">

**Author:** ![Karel\_Boek](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/karel_boek/32/454_2.png) [@Karel\_Boek](https://community.wowza.com/u/Karel_Boek)\
**Post date:** [June 4, 2021, 8:19am UTC](https://community.wowza.com/t/using-javascript-fetch-fails-to-access-wowza-rest-api/93386/3 "2021-06-04T08:19:08Z")

</div>

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:

```auto
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);
```
