[#1232] Getting error during booking api

Migrated from Redmine #1232 | Author: eatsham salim
Status: New | Priority: High, I’m very impatient | Created: 2024-05-15


Hi sir,
I have an issue while making a booking request, here is my code
async function testMethod(req,res) {
try {
const apiUrl = “https://user-api.simplybook.me/admin/”;
const eventId = 36;
const unitId = 2;
const date = ‘2024-05-16’;
const time = ‘10:00:00’;
const clientData = {
‘name’: ‘sham ch’,
‘email’: ‘shamich625@gmail.com’,
‘phone’: ‘+13152108338’
};
const token = await simplybookService.getToken();
const headers = {
‘Content-Type’: ‘application/json’,
‘X-Company-Login’: companyLogin,
‘X-User-Token’: token
};

    const requestBody = {
        jsonrpc: '2.0',
        method: 'book',
        params: {
            eventId: eventId,
            unitId: unitId,
            date: date,
            time: time,
            clientData: clientData
        },
        id: '12'
    };


    const response = await axios.post(apiUrl, requestBody, { headers });

    // const bookingResult = await bookingApiResponse.json();
    const bookingResult = response.data;
    if(bookingResult.error){
        res.json({success:false,error:bookingResult.error})

    }else{
        res.json({success:true,data:bookingResult.data})

    }
} catch (error) {
    res.json({message:error})
}

}
response of this request is here:
{
“success”: false,
“error”: {
“code”: -32053,
“message”: “Selected date start is not available”,
“data”:
}
}
I checked available time on simplybook but everything is fine

Dmytro Bondarev wrote:

Hi,
please use unnamed parameters:

params: [eventId, unitId, date, time, clientData],

Please double check that date and time is available for selected service/provider.

Dmytro Bondarev wrote:

PLease have a look API documentation | SimplyBook.me Online Scheduling
And as far as i see you are using admin API and function book has different signature:

book ($eventId, $unitId, $clientId, $startDate, $startTime, $endDate, $endTime, $clientTimeOffset, $additional, $count, $batchId, $recurringData)

eatsham salim wrote:

Dmytro Bondarev wrote:

Hi,
please use unnamed parameters:

[…]

Please double check that date and time is available for selected service/provider.

Dmytro Bondarev wrote:

Hi,
please use unnamed parameters:

[…]

Please double check that date and time is available for selected service/provider.

Dmytro Bondarev wrote:

PLease have a look API documentation | SimplyBook.me Online Scheduling
And as far as i see you are using admin API and function book has different signature:

API documentation | SimplyBook.me Online Scheduling

book ($eventId, $unitId, $clientId, $startDate, $startTime, $endDate, $endTime, $clientTimeOffset, $additional, $count, $batchId, $recurringData)

I checked date and time for service/provider. its available,
when I wasn’t using admin API it was giving me access denied so that’s why I choose this, using your suggested method which parameters are required because I don’t have batchId and recurringData

eatsham salim wrote:

I checked date and time for service/provider. its available,
when I wasn’t using admin API it was giving me access denied so that’s why I choose this, using your suggested method which parameters are required because I don’t have batchId and recurringData

Dmytro Bondarev wrote:

If you are using admin API you have to pass parameters for admin API. Otherwise it will not work.
batchId and recurringData are not obliogatory fields.

eatsham salim wrote:

Last Question for clarification
which API is best for booking admin API or the other one?
i tried this one also: API documentation | SimplyBook.me Online Scheduling
got 400 response code

Dmytro Bondarev wrote:

It depends on your requirements.
Admin API (and REST API) is the same as you book from admin side (it has less limits).
Public API is the same as you book from public site.

eatsham salim wrote:

i pass the parameter like this book ($eventId, $unitId, $clientId, $startDate, $startTime, $endDate, $endTime, $clientTimeOffset, $additional, $count, $batchId, $recurringData)

i got error: Gender - ‘’ was not found in the haystack,Value is required and can’t be empty

Dmytro Bondarev wrote:

You have intake forms Gender, that is required, you have to pass it in $additional

eatsham salim wrote:

additional:{Gender:“male”}
still same error

Dmytro Bondarev wrote:

Please have a look example above and read documentation.
You should get list of intake forms, and pass it in format {fieldHash: fieldValue}

eatsham salim wrote:

this is my intake form:
{
“id”: 4,
“name”: “623ab80dded6c4ee4f79a9a9636e2097”,
“field_name”: “Gender”,
“field_type”: “select”,
“field_options”: [
“Male”,
“Female”,
“Prefer not to say”
],
“default_value”: “”,
“optional”: false,
“is_visible”: true,
“show_for_all_services”: false
}
can you please tell me how can I pass it in an additional object

Dmytro Bondarev wrote:

Hi, please use

{
"623ab80dded6c4ee4f79a9a9636e2097": "make"
}

eatsham salim wrote:

i already tried it but didnot work:
params: {
eventId: eventId,
unitId: unitId,
clientId:clientId,
startDate: startDate,
startTime: startTime,
endDate: endDate,
endTime: endTime,
additional: {
“623ab80dded6c4ee4f79a9a9636e2097”: “male”
}
},

Dmytro Bondarev wrote:

As I said before you should not use named parameters.

eatsham salim wrote:

i removed the name but issue is name as before

Dmytro Bondarev wrote:

Please provide http request and response.

eatsham salim wrote:

https://user-api.simplybook.me/admin/
method :book
“error”: {
“code”: -32070,
“message”: “Gender - ‘’ was not found in the haystack,Value is required and can’t be empty”,
“data”:
}

Dmytro Bondarev wrote:

Please provide http request and response.