Я отправляю данные, используя POST
запрос из wordpress в vreasy через API
. Но это дает мне ошибку ниже.
{"message":"SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`vreasy_prod_2`.`reservations`, CONSTRAINT `fk_reservations_listor` FOREIGN KEY (`listor_id`) REFERENCES `listors` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION), query was: INSERT INTO `reservations` (`id`, `adults`, `kids`, `additional_description`, `owner_additional_description`, `accommodation_cost`, `currency_id`, `listing_id`, `host_id`, `guest_id`, `status`, `checkin`, `checkout`, `created_at`, `listor_id`, `gateway_listor_id`, `portal_uid`, `subscription_id`, `user_id`, `language_id`, `updated_at`, `auto_email_enabled`, `auto_sms_enabled`, `auto_task_enabled`, `auto_email_run_at`, `auto_sms_run_at`, `auto_task_run_at`, `original_parent_id`, `checkin_gmt`, `checkout_gmt`, `custom_eta`, `custom_etd`, `net_amount_for_pm`, `portal_service_fee_for_pm`, `channel_service_fee`, `gross_amount_paid_by_guest`, `extra_data`, `payment_fee`, `booking_conditions`, `confirmed_at`, `custom_eta_method`, `custom_etd_method`, `is_payments_automatable`, `is_pending_statement`, `statement_id`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)","exception":{},"request_params":{"controller":"reservations","action":"post","module":"api","body":{"checkin":"2018-09-25 15:00:00","checkout":"2018-09-27 11:00:00","listor_id":0,"gateway_listor_id":0,"user_id":1,"adults":1,"status":"UNCONFIRMED","guest":{"fname":"Chirag","lname":"Modi","email":"cmodi@atlas.com","phone":"123456798"},"listing_id":177035},"request-id":"W5u82-wkexMY6IkfseMiXAAAAIY","user_id":1,"agent":"user"},"code":500}
и вот мой PHP-код, который я использую.
<code>$url = 'https://api.vreasy.com/reservations';
$api_key = "api-key";
$fields = array(
'checkin' => '2018-09-25 15:00:00',
'checkout' => '2018-09-27 11:00:00',
'listor_id' => 0,
'gateway_listor_id' => 0,
'user_id' => 1,
'adults' => 1,
'property_id' => 177035,
'status' => 'UNCONFIRMED',
'guest' => array(
'fname' => 'Chirag',
'lname' => 'Modi',
'email' => 'cmodi@atlas.com',
'phone' => '123456798'
)
);
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, $api_key . ":");
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($fields));
$info = curl_getinfo($ch);
$result = curl_exec($ch);
curl_close($ch);
echo '<pre>';
var_dump($result);
echo '
';
Я искал эту тему, и в основном показываю тот же метод для отправки POST
запроса.
вот URL документации для справки https://api.vreasy.com/docs/public-api/#operation/post_reservation