[#1001] Can't access API endpoint for bookings using company login

Migrated from Redmine #1001 | Author: Mitun Talapatra
Status: Rejected | Priority: High, I’m very impatient | Created: 2023-01-20


Hi Team,

I am trying to access bookings using followings:

headers = {‘X-Company-Login’: ‘holmesplacedeutschland’,
‘X-Token’: ‘f2ceaa865575241eebf5fd3bdd0c63e9bb25554c107d5246c748cd6ca38e9fdb’,
‘Content-Type’: ‘application/json’,
}
JSONRpcClient = requests.get(‘https://user-api-v2.simplybook.me/admin/bookings?status=confirmed’, headers= headers)

Which is throwing an error of 401, meaning unauthorized access.

Could you please suggest me necessary steps to follow ASAP?

Redmine Admin wrote:

please check here, you need to pass the following

 $client = new JsonRpcClient('https://user-api.simplybook.me' . '/admin/', array(
        'headers' => array(
            'X-Company-Login: ' . YOUR_COMPANY_LOGIN,
            'X-User-Token: ' . $token
        )
    ));

X-User-Token not X-Token

Mitun Talapatra wrote:

Thanks, I have tried following code and was able to get token and refresh token both:

url = “https://user-api-v2.simplybook.me/admin/auth
headers = {‘Content-Type’: ‘application/json’}
data = {
“company”: “holmesplacedeutschland”,
“login”: “Mitun.Talapatra@holmesplace.de”,
“password”: “XXXXXX”
}

response = requests.post(url, headers=headers, data=json.dumps(data))

response.json()

Result:
{‘token’: ‘XXX’,
‘company’: ‘holmesplacedeutschland’,
‘login’: ‘Mitun.Talapatra@holmesplace.de’,
‘refresh_token’: ‘XXXX’,
‘domain’: ‘simplybook.me’,
‘require2fa’: False,
‘allowed2fa_providers’: ,
‘auth_session_id’: ‘’,
‘id’: None}

then, I have tried to get booking list by following:

headers_booking = {
‘Content-Type’: ‘application/json’,
‘X-Company-Login’: ‘holmesplacedeutschland’,
‘X-User-Token’: response.json()[‘token’] ,
}

booking_list = requests.get(‘https://user-api-v2.simplybook.me/admin/bookings’, headers=headers_booking)

booking_list.json()

And the error is:
{‘code’: 401, ‘message’: ‘Unauthorized’, ‘data’: , ‘message_data’: }

I have used both token and refresh token to get booking list and had same error. It would be great if you please help me out here.