RESTful API using CURL does not work as expected

Good M@rning!

I have a scenario where I have setup a basic Wowza server instance on my PC (localhost). Now, I would like to use restful API with Wowza using curl. I got some basic direction here: https://www.wowza.com/docs/how-to-use-curl-to-query-wowza-rest-api, but, with whatever queries I tried (either GET or POST method), I always get the same error: “The request requires user authentication”.

For example, I tried different combinations:

curl -X GET --header 'Accept:application/json; charset=utf-8' http://taha:a1@localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications
curl -X GET --header 'Accept:application/json' http://taha:a1@localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications
curl -X GET --header 'Accept:application/json; charset=utf-8' http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications
curl -X POST  -H "Accept:application/json; charset=utf-8" -H "Content-type:application/json; charset=utf-8" http://taha:a1@localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive -d '{"restURI":"http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive","name":"testlive","appType":"Live","clientStreamReadAccess":"*","clientStreamWriteAccess":"*","description":"Testing our Rest Service","streamConfig":{"restURI":"http://taha:a1@localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive/streamconfiguration","streamType":"live"}}'
curl -X GET --header 'Accept:application/json; charset=utf-8' http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive/streamfiles

All return the same error:

C:\Users\Admin>curl -X GET --header 'Accept:application/json; charset=utf-8' http://taha:a1@localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications
curl: (6) Couldn't resolve host 'charset=utf-8''
<?xml version="1.0" encoding="UTF-8" standalone="no"?><error><wowzaServer>4.2.0</wowzaServer><code>401</code><message>The request requires user authentication</message></error>
C:\Users\Admin>

I noticed this error message is not documented in the page referenced, what am I missing?

Note: taha is username, and a1 is password. I tried different combinations, with and without the username/password string so it may not display the same error over and over.

Wowza server version is 4.2.0.

Thanks…

Hello,

Can you try using this instead:

curl -X GET --header 'Accept:application/json; charset=utf-8' -u taha:a1 http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications

Zoran

Hi,

I noticed that you are runnign CURL on a Windows box.

Can you try using this command instead?

curl -X GET --header "Accept:application/json; charset=utf-8" -u taha:a1 http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications

Also, please check your [wowza-install-dir]/conf/Server.xml file, if you have the /Root/Server/RESTInterface/AuthenticationMethod/ parameter set to “basic”.

If you make any changes to the Server.xml file, please make sure to restart your Wowza Streaming Engine service so that the new changes can take effect.

Just to make sure, please check if the taha username and a1 password is set in your [wowza-install-dir]/conf/admin.password file.

Zoran

Hello tahaOS

I think there is a url issue and some quoting issues at play here. Try the following (note the use of single quote and the removal of the user/pass from the second restURI entry):

curl -X POST  -H "Accept:application/json; charset=utf-8" -H "Content-type:application/json; charset=utf-8" -u "taha:a1" http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive -d '{"restURI":"http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive3","name":"testlive","appType":"Live","clientStreamReadAccess":"*","clientStreamWriteAccess":"*","description":"Testing our Rest Service","streamConfig":{"restURI":"http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive/streamconfiguration","streamType":"live"}}'

Thanks for your prompt reply; its still the same error:

C:\Users\Admin>curl -X GET --header 'Accept:application/json; charset=utf-8' -u taha:a1 http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications
curl: (6) Couldn't resolve host 'charset=utf-8''
<?xml version="1.0" encoding="UTF-8" standalone="no"?><error><wowzaServer>4.2.0</wowzaServer><code>401</code><message>The request requires user authentication</message></error>
C:\Users\Admin>

Hi,

I noticed that you are runnign CURL on a Windows box.

Can you try using this command instead?

curl -X GET --header "Accept:application/json; charset=utf-8" -u taha:a1 http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications

Also, please check your [wowza-install-dir]/conf/Server.xml file, if you have the /Root/Server/RESTInterface/AuthenticationMethod/ parameter set to “basic”.

If you make any changes to the Server.xml file, please make sure to restart your Wowza Streaming Engine service so that the new changes can take effect.

Just to make sure, please check if the taha username and a1 password is set in your [wowza-install-dir]/conf/admin.password file.

Zoran

Many thanks for your prompt reply; all of your suggestions helped in one way or the other.

First, I noticed /Root/Server/RESTInterface/AuthenticationMethod/ parameter was set to ‘digest’, so I changed to ‘basic’ and restarted service.

After restart, when I applied curl string as:

curl -X GET --header "Accept:application/json; charset=utf-8" -u taha:a1 [url]http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications[/url]

(as you suggested), I got response in JSON (as needed):

{"restURI":"http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications","applications":[{"id":"IP Cam","href":"http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/IP Cam","appType":"Live","dvrEnabled":false,"drmEnabled":false,"transcoderEnabled":false,"streamTargetsEnabled":false},{"id":"live","href":"http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/live","appType":"Live","dvrEnabled":false,"drmEnabled":false,"transcoderEnabled":false,"streamTargetsEnabled":false},{"id":"vod","href":"http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/vod","appType":"VOD","dvrEnabled":false,"drmEnabled":false,"transcoderEnabled":false,"streamTargetsEnabled":false}]}

And like you mentioned, if I changed it to:

curl -X GET --header 'Accept:application/json; charset=utf-8' -u taha:a1 http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications

(single quotes), I got response in XML format:

  <Application id="IP Cam" href="http://localhost:8087/v2/servers/_defaultServer
_/vhosts/_defaultVHost_/applications/IP Cam">
    <AppType>Live</AppType>
    <DVREnabled>false</DVREnabled>
    <DRMEnabled>false</DRMEnabled>
    <TranscoderEnabled>false</TranscoderEnabled>
    <StreamTargetsEnabled>false</StreamTargetsEnabled>
  </Application>
  <Application id="live" href="http://localhost:8087/v2/servers/_defaultServer_/
vhosts/_defaultVHost_/applications/live">
    <AppType>Live</AppType>
    <DVREnabled>false</DVREnabled>
    <DRMEnabled>false</DRMEnabled>
    <TranscoderEnabled>false</TranscoderEnabled>
    <StreamTargetsEnabled>false</StreamTargetsEnabled>
  </Application>
  <Application id="vod" href="http://localhost:8087/v2/servers/_defaultServer_/v
hosts/_defaultVHost_/applications/vod">
    <AppType>VOD</AppType>
    <DVREnabled>false</DVREnabled>
    <DRMEnabled>false</DRMEnabled>
    <TranscoderEnabled>false</TranscoderEnabled>
    <StreamTargetsEnabled>false</StreamTargetsEnabled>
  </Application>
</Applications>

so your latest string does the trick.

Just to make sure, please check if the taha username and a1 password is set in your [wowza-install-dir]/conf/admin.password file.

Yes, this part was set correctly.

Thanks for all the help in right direction!

After last done steps, I tried to create an application using REST interface, as follows:

curl -X POST  -H "Accept:application/json; charset=utf-8" -H "Content-type:application/json; charset=utf-8" -u taha:a1 http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive -d "{"restURI":"http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive","name":"testlive","appType":"Live","clientStreamReadAccess":"*","clientStreamWriteAccess":"*","description":"Testing our Rest Service","streamConfig":{"restURI":"http://taha:a1@localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/testlive/streamconfiguration","streamType":"live"}}"

Which returned some error:

<?xml version="1.0" encoding="UTF-8" standalone="no"?><error><wowzaServer>4.2.0</wowzaServer><code>400</code><message>com.fasterxml.jackson.core.JsonParseException: Unexpected character ('r' (code 114)): was expecting double-quote to start field name at [Source: java.io.ByteArrayInputStream@1390c955; line: 1, column: 3]</message></error><html><head><META HTTP-EQUIV="refresh" CONTENT="0;URL=/cgi-sys/defaultwebpage.cgi"></head><body></body></html>
<html><head><META HTTP-EQUIV="refresh" CONTENT="0;URL=/cgi-sys/defaultwebpage.cgi"></head><body></body></html>
curl: (3) [globbing] unmatched close brace/bracket at pos 168

After this, now if I try to open enginemanager using: http://localhost:8088/enginemanager/login.htm

after login attempt, it gives me a new error:

Internal Server Error (500) - Internal Server Error 

This is something really new - tried stopping/starting wowza services multiple times, but no benefit.

Any clues…?