[#214] how to use editBook?

Migrated from Redmine #214 | Author: Ben Esparza
Status: Resolved | Priority: Normal | Created: 2018-08-07


Hello.

What we’d like to do is save the original provider of a new booking so that when it gets reassigned to other
providers we still have the information about who it was assigned to originally.

We have added a hidden input field called “original provider” that we set as empty and we’d like to use the
API to read the provider of a new booking and copy the provider to the “original provider” hidden field.

So far we are able to do:

  1. run ‘getBookings’ to get a list of booking IDs
  2. compare the current booking IDs to what we had last time
  3. for each new booking {
    run ‘getBookingDetails’ and obtain the service provider
    }

Now we’d like to be able to use ‘editBooking’ to set the “original provider” field but we are not sure how
to use editBooking. The API gives us the usage but we’d like to see a little more information, perhaps an
example, of how to use ‘editBooking’. Or if there is a better way to do this then please let us know.

Thank you
Ben Esparza

Ben Esparza wrote:

Here is what we did so far:

  1. We get the token.

  2. Then we run getBookings to get something like this:

{“id”:“71”,“record_date”:“2018-07-31 20:05:24”,“start_date”:“2018-08-02 01:00:00”,“end_date”:“2018-08-02 05:00:00”,“unit_id”:“4”,“text”:“Hugo Boss”,“client”:“Hugo Boss”,“unit”:“Jed Dyreng",“unit_email”:"dyreng@us.ibm.com”,“event”:“DS8K Flexible-Customer Standard Code Load Activation",“event_id”:“16”,“is_confirm”:“1”,“client_id”:“3”,“client_phone”:“15203313226”,“client_email”:"ameinel@us.ibm.com”,“offset”:“-420”,“comment”:“Chuck’s cell number is (531) 205-3326”,“code”:“5a61y84k”,“approve_status”:“approved”,“status”:“7”,“location”:“1”},

  1. Then we try the editBook (using some of the fields from the getBookings), but it doesn’t work:

curl -XPOST -H ‘x-company-login: ibmrcl’ -H ‘x-user-token: 23b12f0ee294e5f2d57ec6c11f71b0799cdd49a9c09e1ef737373e2f897824ed’ -H “Content-type: application/json” -d ‘{“jsonrpc”:“2.0”,“id”:71,“method”:“editBook”,“params”:{“schedulerId”:71,“eventId”:16,“unitId”:4,“clientId”:3,“startDate”:“2018-08-02”,“startTime”:“02:00:00”,“endDate”:“2018-08-02”,“endTime”:“06:00:00”,“19”:“test”}}’ ‘https://user-api.simplybook.me/admin

{“error”:{“code”:-32070,“message”:“Customer Company Name - Value is required and can’t be empty”,“data”:},“id”:“71”,“jsonrpc”:“2.0”}

Ben Esparza wrote:

  1. We get the token.

  2. Then we run getBookings to get something like this:

{“id”:“71”,“record_date”:“2018-07-31 20:05:24”,“start_date”:“2018-08-02 01:00:00”,“end_date”:“2018-08-02 05:00:00”,“unit_id”:“4”,“text”:“Hugo Boss”,“client”:“Hugo Boss”,“unit”:“Jed Dyreng",“unit_email”:"dyreng@us.ibm.com”,“event”:“DS8K Flexible-Customer Standard Code Load Activation",“event_id”:“16”,“is_confirm”:“1”,“client_id”:“3”,“client_phone”:“15203313226”,“client_email”:"ameinel@us.ibm.com”,“offset”:“-420”,“comment”:“Chuck’s cell number is (531) 205-3326”,“code”:“5a61y84k”,“approve_status”:“approved”,“status”:“7”,“location”:“1”},

  1. Then we try the editBook (using some of the fields from the getBookings), but it doesn’t work:

curl -XPOST -H ‘x-company-login: ibmrcl’ -H ‘x-user-token: ’ -H “Content-type: application/json” -d ‘{“jsonrpc”:“2.0”,“id”:71,“method”:“editBook”,“params”:{“schedulerId”:71,“eventId”:16,“unitId”:4,“clientId”:3,“startDate”:“2018-08-02”,“startTime”:“02:00:00”,“endDate”:“2018-08-02”,“endTime”:“06:00:00”,“19”:“test”}}’ ‘https://user-api.simplybook.me/admin

{“error”:{“code”:-32070,“message”:“Customer Company Name - Value is required and can’t be empty”,“data”:},“id”:“71”,“jsonrpc”:“2.0”}

Vitaliy Kordiak wrote:

Hi,
please pass the parameters as an array (no parameter name). In our API, the parameters are identified by the position.
For example:
…,“params”:[71, 16,4,3,“2018-08-02”,“02:00:00”,…], …

Ben Esparza wrote:

I tried your suggestion, but still not working for me:

curl -XPOST -H ‘x-company-login: ibmrcl’ -H ‘x-user-token: ’ -H “Content-type: application/json” -d ‘{“jsonrpc”:“2.0”,“id”:71,“method”:“editBook”,“params”:[71,16,4,3,“2018-08-02”,“01:00:00”,“2018-08-02”,“06:00:00”,“-420”,{“1”:“test”}]’ ‘https://user-api.simplybook.me/admin

I’m trying to change one of the intake forms.

Ben Esparza wrote:

After some help from the simplybook slack channel…finally got this working. For others who would like to use editBook in the future here is what worked, of course you’d need to put this all on one line but I separated it for easier reading and understanding.

Each “new value” line is a required additional field. We have 13 required fields right now in our application.

==============================================================================================================================

curl -XPOST -H ‘x-company-login: ’ -H ‘x-user-token: ’ -H “Content-type: application/json” -d ‘{“jsonrpc”:“2.0”,“id”:71,“method”:“editBook”,“params”:
[71,16,4,3,“2018-08-02”,“01:00:00”,“2018-08-02”,“06:00:00”,“-420”,
{“9756754584dcf520f48a5b96d0acea4e”:“new value 1”,
“c37af62bc693a67e5228b1af2d839b88”:“new value 2”,
“de4d8ee29195f069a46de1a5f552897f”:“new value 3”,
“ec6c3c3f0686959a537621ba7d62721b”:“new value 4”,
“e51e66d4272f19e13862d620d7aa6a4c”:“new value 5”,
“dbae5bcc570ddb84cca1381242c684fc”:“new value 6”,
“43ab99ed3da3d9632d26bcaa83752f81”:“new value example”,
“b4910147f88223e85dcca2ab1043efa3”:“new value 8”,
“242f64e91b4798f26cba235b40e6a87c”:“new value 9”,
“b1afb4b225ca83428320b052df15df29”:“new value 10”,
“13b4b4391c74a1aab33d59381aeeac4c”:“new value 11”,
“cce6d5b99e56010396fc329f3b7783a8”:“new value 12”,
“5c17fd514cd33582e3dd58cfa0f74361”:“new value 13”}]}’ ‘https://user-api.simplybook.me/admin

==============================================================================================================================

Here is the resulting output when we run the command above:

{“result”:{“require_confirm”:false,“bookings”:[{“id”:“71”,“event_id”:16,“unit_id”:4,“client_id”:3,“client_hash”:“23faa038dde92e3204f8ba114de918d5”,“start_date_time”:“2018-08-02 01:00:00”,“end_date_time”:“2018-08-02 06:00:00”,“time_offset”:“-420”,“is_confirmed”:“1”,“require_payment”:false,“code”:“5a61y84k”,“hash”:“b42e4b44fdda0dc791a59000c6766258”}]},“id”:“71”,“jsonrpc”:“2.0”}

Dmytro Bondarev wrote:

Thank you, Ben for explanation!