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

Migrated from Redmine #1002 | Author: Mitun Talapatra
Status: Closed | Priority: High, I’m very impatient | Created: 2023-01-24


Hi There,

According to the REST API Documentation, I am trying to get all booking data. for authentification, I have tried following:

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

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

response.json()

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

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

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

booking_list.json()

Result:
{‘code’: 401, ‘message’: ‘Unauthorized’, ‘data’: , ‘message_data’: }

Dmytro Bondarev wrote:

Hi, please pass token instead of refresh_token.

'X-User-Token': response.json()['token'] ,

Mitun Talapatra wrote:

Dmytro Bondarev wrote:

Hi, please pass token instead of refresh_token.

[…]

Still same error:
{‘code’: 401, ‘message’: ‘Unauthorized’, ‘data’: , ‘message_data’: }

Dmytro Bondarev wrote:

Please provide full raw HTTP request, including headers.

Mitun Talapatra wrote:

Dmytro Bondarev wrote:

Please provide full raw HTTP request, including headers.

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()

Dmytro Bondarev wrote:

Sorry but we need full raw HTTP request.
You can have some mistakes in your code.

Mitun Talapatra wrote:

Please find it in attachment.

Thanks

Dmytro Bondarev wrote:

Can’t see it. Please just paste HTTP request here.

Mitun Talapatra wrote:

Dmytro Bondarev wrote:

Can’t see it. Please just paste HTTP request here.

Mitun Talapatra wrote:

Here is the full code:
import requests
import json

import warnings
warnings.filterwarnings(“ignore”, category=FutureWarning)

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

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

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()

Redmine Admin wrote:

unfortunately we are unable to check your code, please provide raw http request which were send to our server

Mitun Talapatra wrote:

Redmine Admin wrote:

unfortunately we are unable to check your code, please provide raw http request which were send to our server

That’s all written in my notebook.

Can we have a short call please?

Mitun Talapatra wrote:

Does it work for you?

1st request:
Method: POST
URL: https://user-api-v2.simplybook.me/admin/auth
Headers:
Content-Type: application/json
Body:
{
“company”: “xxxx”,
“login”: “xxxx”,
“password”: “xxxx*”
}

And the second request

Method: GET
URL: https://user-api-v2.simplybook.me/admin/bookings
Headers:
Content-Type: application/json
X-Company-Login: xxxxx
X-User-Token: response.json()[‘token’]

Note that the response.json()[‘token’] in headers will be replaced by actual token value when the request is made.

Redmine Admin wrote:

we need actual headers sent to our API server, there is no way to see what will be replaced and will it be or not, maybe problem is because it was not replaced

Mitun Talapatra wrote:

Redmine Admin wrote:

we need actual headers sent to our API server, there is no way to see what will be replaced and will it be or not, maybe problem is because it was not replaced

this is exactly what I have followed as the documentation. do you need login and token info?

Mitun Talapatra wrote:

second request

Method: GET
URL: https://user-api-v2.simplybook.me/admin/bookings
Headers:
Content-Type: application/json
X-Company-Login: holmesplacedeutschland
X-User-Token: ‘002e3d4433d6fc86206b8e7fb0b8da6b5907d2da56a64e29bee6fd4b82417c36’

Dmytro Bondarev wrote:

Please remove quotas from X-User-Token header.
It must be
X-User-Token: 002e3d4433d6fc86206b8e7fb0b8da6b5907d2da56a64e29bee6fd4b82417c36

Dmytro Bondarev wrote:

Also you should set X-Token instead of X-User-Token.

Mitun Talapatra wrote:

But you have suggested to use X-User-Token earlier?

Dmytro Bondarev wrote:

For REST API it must be X-Token, please check documentation.