404 error trying to authenticate with API OAuth

Hi!

I was following the tutorial here: http://xibo.org.uk/2014/02/19/scripting-xibo-content-management-a-brief-tour-of-the-api/

Itā€™s throwing an exception when I try to generate the Access Token: ā€œException: Invalid response 404ā€

I have configured the defaults.cfg file and have tried a number of different values for the ā€˜urlā€™:
http://my.server.com
http://my.server.com/
http://my.server.com/api
http://my.server.com/api/
http://my.server.com/api/authorize
http://my.server.com/api/authorize/

If I use a web browser to open http://my.server.com/api/authorize, I do get a response from the API so I know itā€™s thereā€¦ but none of the above works. Any thoughts?

Cheers!

Iā€™m not familiar with 1.7 api, but the url in defaults.cfg should be just a full path to your Xibo installation.
If you have that and the consumer key and secret from Applications page in defaults.cfg and run the script it should generate correct link to authorise the API.

Unless itā€™s something urgent that you need from 1.7 api, Iā€™d wait for 1.8 release (or try 1.8rc1) that has a lot better, more compete, documented and tested API.

Thanks Peter! I think you might be on to something ā€“ Iā€™m using 1.8rc1.

I read the documentation - services.php does not seem to exist (I get a 404 trying to access it from the web browser; I havenā€™t yet figured out how to view the web serverā€™s file system using Docker.)

Is there some other 1.8rc1 documentation I should be looking at?

Cheers!

ahh well that makes sense then :smiley:

1.8 api is documented here - http://xibo.org.uk/manual-tempel/en/api.html
and the 1.8 calls are documented here - http://xibo.org.uk/manual-tempel/api/

I think Iā€™ll create some guide about API access and some example calls using Postman (which Iā€™d recommend itā€™s quite great) later today - could be useful for community.

Edit - 1.8 API Introduction

Peter - many thanks. I used your new tutorial and things are working well!!

Cool, Iā€™m glad it was useful to you :slight_smile:

Hello, guys!

Iā€™m getting the same error when trying to access through python. The whole situation looks the same. Iā€™m able to connect to CMS through Postman. I canā€™t find in documentation something regarding to services.php. Can you give me more details on that?

Many thanks!

The guide referenced at the beginning relates to the old 1.7 API.

The API for 1.8 is different and the two are not compatible.

Alex, thanks for reply!

Now itā€™s clear.
Is there any python example on authorization part? Or i can write it using oauth2 and requests libraries?(if you know them)

Thanks!

Weā€™ve not published an example no. Iā€™m sure there are libraries for Python and OAUTH.

We do publish some wrappers for PHP which might be a better option for you.

Thanks a lot, Alex!

If i succeed in that, will post here.

Regards

UPDATE:

import base64
import requests

url = 'http://127.0.0.1/xibo/web/api/authorize/access_token'
layoutsurl = 'http://127.0.0.1/xibo/web/api/layout?layout=&embed=regions,playlists'
consumer_key = 'Msn1AEVOmqeuQqCEhDr6lR94zGge7JHFYEzKkht3'
consumer_secret = 'p2WsPcDMbSRi5gIyhSOm6nxRf5iJZ87JEZSeQj2oTnVQoH4wF8ogPLrtwZxdsklAnmhfs3whq99nxI1lfQXN8R4CJYYjTr2RmYd72KKG4oDtwAEvyy6czwAChSrnfbaNSyifu27Mu5ZVAa87cveDR7ql5LHhEEohNpO6yycogCNPJRHYP5YDJykMF49HWFa346esBQbu9zVnzkSsdlYvlbzlx4WZWniOblnEDo5x7t2hv7f6fUsrqVvgz5c9rW'
token = ''

bearer_token_credentials = base64.urlsafe_b64encode(
    '{}:{}'.format(consumer_key, consumer_secret).encode('ascii')).decode('ascii')
headers = {
    'Authorization': 'Basic {}'.format(bearer_token_credentials),
    'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
}
data = 'grant_type=client_credentials'
response = requests.post(url, headers=headers, data=data)
response_data = response.json()
if response_data['token_type'] == 'Bearer':
    bearer_token = response_data['access_token']
    headers = {
        'Authorization': 'Bearer {}'.format(bearer_token),
        'Accept-Encoding': 'gzip',
    }
    response = requests.get(layoutsurl, headers=headers)
    response_data = response.json()
    print(response_data)
else:
    raise RuntimeError('unexpected token type: {}'.format(response_data['token_type']))