PHP cURL通过API在投递中抛出500错误

时间:2018-09-14 14:03:29

标签: php curl post

我正在使用POST请求将数据从wordpress通过API发送到vreasy。但这给了我下面的错误。

{"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代码。

$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 '</pre>';

我已经搜索了该主题,并且大多数情况下都显示了发送POST请求的相同方法。 这是文档URL,以供参考https://api.vreasy.com/docs/public-api/#operation/post_reservation

0 个答案:

没有答案