[#1051] /admin/clients throwing 400 error when its been working for months

Migrated from Redmine #1051 | Author: Stu Dio
Status: Rejected | Priority: Immediate, there is BUG! | Created: 2023-04-28


My end point https://user-api-v2.simplybook.me/admin/clients has just started throwing a 400 error when its been working for months.

I am passing the following:


axios.post('https://user-api-v2.simplybook.me/admin/clients', '{"name":"Emily Vinsen","email":"emily@flocc.co","phone":"+447807491565"}', {
    headers: {
      'X-Company-Login': SIMPLYBOOK_COMPANY,
      'X-Token': SIMPLYBOOK_TOKEN,
      'Content-Type': 'application/json',
    },
})

And then I am getting:


{"message":"Request failed with status code 400","name":"Error","stack":"Error: Request failed with status code 400"}

Any ideas why this would have stopped working?

I came across this issue when I was asked to look into a different issue where the api returned unauthorised when creating a booking, again when there was a valid token etc. But I can’t get to that step to replicate because I can’t get past setting up my client.

We haven’t touched anything to do with this booking process for months, and there have been many successful bookings since then, so I’m inclined to think that its something your end? But any help would be greatly appreciated as the booking system for our client is currently down!

Dmytro Bondarev wrote:

Hi,
This is not our error, please provide RAW HTTP request and response.

Stu Dio wrote:

Dmytro Bondarev wrote:

Hi,
This is not our error, please provide RAW HTTP request and response.

Hey, I think ‘request failed with status code 400’ comes from axios, but thats all it returns to me?

This is my http request:


POST /admin/clients HTTP/1.1
Host: user-api-v2.simplybook.me
Content-Type: application/json
X-Company-Login: admin
X-Token: XXX
Content-Length: 89

{
  "name": "Emily Test",
  "email": "emily.test@gmail.com",
  "phone": "+123456789987"
}

I have just done this in postman as its easier, and the auth endpoint worked perfectly for me to get my token, but then create client one took 2m and returned ‘502 Bad Gateway’. The response I get from axios is as follows:


{"message":"Request failed with status code 400","name":"Error","stack":"Error: Request failed with status code 400
at createError (/var/task/node_modules/axios/lib/core/createError.js:16:15)
at settle (/var/task/node_modules/axios/lib/core/settle.js:17:12)
at IncomingMessage.handleStreamEnd (/var/task/node_modules/axios/lib/adapters/http.js:322:11)
at IncomingMessage.emit (node:events:525:35)
at endReadableNT (node:internal/streams/readable:1358:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)",
"config":{"transitional":{"silentJSONParsing":true,"forcedJSONParsing":true,"clarifyTimeoutError":false},"transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1,"maxBodyLength":-1,"headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json","X-Company-Login":"universityarms","X-Token":"XXX","User-Agent":"axios/0.26.1","Content-Length":80},"method":"post","url":"https://user-api-v2.simplybook.me/admin/clients","data":"{\"name\":\"Emily\",\"email\":\"email@test.com\",\"phone\":\"+4471234567890\"}"},"status":400}

I’m not sure what else you need?

Redmine Admin wrote:

this is not error from our API

Stu Dio wrote:

Oh apologies, I have just realised I was missing a header on postman - this is the error I am receiving:

{"code":400,"message":"","data":{"name":["Invalid type given, value should be float, string, or integer"],"email":["Invalid type given, value should be float, string, or integer"],"phone":["Invalid type given, value should be float, string, or integer"]},"message_data":[]}

I have copied the example request body from API documentation | SimplyBook.me Online Scheduling and still getting this 400 error?

Redmine Admin wrote:

please provide raw http request to our API, we are not sure which data you are passing there

Stu Dio wrote:

Redmine Admin wrote:

please provide raw http request to our API, we are not sure which data you are passing there

Request:

POST /admin/clients HTTP/1.1
Host: user-api-v2.simplybook.me
Content-Type: application/json
X-Company-Login: universityarms
X-Token: XXX
Content-Length: 82

{
  "name": "Mike",
  "email": "mikeemail@gmail.com",
  "phone": "+123456789987"
}

Response:

{"code":400,"message":"","data":{"name":["Invalid type given, value should be float, string, or integer"],"email":["Invalid type given, value should be float, string, or integer"],"phone":["Invalid type given, value should be float, string, or integer"]},"message_data":[]}

Dmytro Bondarev wrote:

I made a test requests on your company:

Request:

POST /admin/clients
Content-Type: application/json
X-Company-Login: universityarms
X-Token: ***
Content-Type: application/json; charset=UTF-8
Host: user-api-v2.simplybook.me

{
  "name": "Mike",
  "email": "mikeemail@gmail.com",
  "phone": "+123456789987"
}

Response:

HTTP/1.1 200 OK
Server : nginx
Date : Fri, 28 Apr 2023 15:49:47 GMT
Content-Type : application/json; charset=UTF-8
Content-Length : 185
Keep-Alive : timeout=20
Access-Control-Allow-Origin : *
Access-Control-Allow-Methods : POST, PUT, DELETE, GET, OPTIONS
Access-Control-Allow-Headers : content-type, x-company-login, x-token, x-requested-with
X-XSS-Protection : 1; mode=block
X-IPLB-Request-ID : 68EEB58A:CA76_8E2C8CB0:01BB_644BEB1B_10D222E2:E8C9
Strict-Transport-Security : max-age=15768000
X-IPLB-Instance : 45487

{
  "id": 399,
  "name": "Mike",
  "email": "mikeemail@gmail.com",
  "phone": "+123456789987",
  "address1": null,
  "address2": null,
  "city": null,
  "zip": null,
  "country_id": null,
  "state_id": null,
  "full_address": ""
}

And for your initial data i received:

HTTP/1.1 400 Bad Request
Server: nginx
Date: Fri, 28 Apr 2023 16:00:17 GMT
Content-Type: application/json; charset=UTF-8
Content-Length: 77
Keep-Alive: timeout=20
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, PUT, DELETE, GET, OPTIONS
Access-Control-Allow-Headers: content-type, x-company-login, x-token, x-requested-with
X-IPLB-Request-ID: 3EE455A2:E11E_8E2C8CB0:01BB_644BED91_10D3640D:E8C9
Strict-Transport-Security: max-age=15768000
X-IPLB-Instance: 45487

{"code":400,"message":"","data":{"email":["Email exists"]},"message_data":[]}

Which is also correct answer from server.
And your response above definitely for some other request.
Please check your code. Make sure you send correct data to correct URL. with required headers.

Stu Dio wrote:

Dmytro Bondarev wrote:

I made a test requests on your company:

Request:

[…]

Response:

[…]

And for your initial data i received:

[…]

Which is also correct answer from server.
And your response above definitely for some other request.
Please check your code. Make sure you send correct data to correct URL. with required headers.

I do not see any different between my http request and yours? Stating that mine is ‘definitely for some other request’ is just ridiculous, I have provided you my code as I am sending it in postman. I feel like you are being deliberately unhelpful and I do not appreciate your curtness. I am a paying customer and I expect better support than this. My clients booking on our website is currently down because of this issue, so I expect you to take this much more seriously.

I have just tried again and request:


POST /admin/clients
Host: user-api-v2.simplybook.me
Content-Type: application/json; charset=UTF-8
X-Company-Login: universityarms
X-Token: ***

{
  "name": "Catherine",
  "email": "catherine@gmail.com",
  "phone": "+123456789987"
}

Response:

{
    "code": 400,
    "message": "",
    "data": {
        "name": [
            "Invalid type given, value should be float, string, or integer"
        ],
        "email": [
            "Invalid type given, value should be float, string, or integer"
        ],
        "phone": [
            "Invalid type given, value should be float, string, or integer"
        ]
    },
    "message_data": []
}

So this is still not working for me.

For my initial data, the response you got was an error that the email already exists. Can you not create a client if they already have an account? In that case, how do I find that user based on their email address to get their client id? Do you have a search for client by field endpoint? And why has this only just become an issue?

Stu Dio wrote:

Stu Dio wrote:

Dmytro Bondarev wrote:

I made a test requests on your company:

Request:

[…]

Response:

[…]

And for your initial data i received:

[…]

Which is also correct answer from server.
And your response above definitely for some other request.
Please check your code. Make sure you send correct data to correct URL. with required headers.

I do not see any different between my http request and yours? Stating that mine is ‘definitely for some other request’ is just ridiculous, I have provided you my code as I am sending it in postman. I feel like you are being deliberately unhelpful and I do not appreciate your curtness. I am a paying customer and I expect better support than this. My clients booking on our website is currently down because of this issue, so I expect you to take this much more seriously.

I have just tried again and request:

[…]

Response:

[…]

So this is still not working for me.

For my initial data, the response you got was an error that the email already exists. Can you not create a client if they already have an account? In that case, how do I find that user based on their email address to get their client id? Do you have a search for client by field endpoint? And why has this only just become an issue?

Ah don’t worry, I have worked out how to search the endpoint. It seems that this was my issue, that I was trying to create an existing user