我正在尝试使用curl以json格式发布表单以启动27以创建预订。我的json数据是:
{"booking":{
"id":55,
"user_id":5,
"service_date":"2015-08-15T13:00",
"services":[{
"id":1,
"extras":[{
"extra_id":1,
"quantity":1
}],
"pricing_parameters":[{
"pricing_parameter_id":1,
"quantity":1
}],
"service_maids":1,
"service_hours":1
},{
"id":2,
"extras":[],
"pricing_parameters":[],
"service_maids":1,
"service_hours":2
}],
"frequency_id":1,
"address":"595 Market St",
"city":"San Francisco",
"state":"CA",
"zip":"94105",
"phone":"462-485-0790",
"price":"202.0",
"final_price":"202.0",
"completed":false,
"payment_method":"stripe",
"active":true,
"discount_code":null,
"customer_comments":null,
"sms_notifications":false,
"flexibility":0,
"custom_fields":{
"custom_text":"text",
"custom_dropdown":{"values":"1"},
"custom_radio":{"values":"2"}
}
}}
和curl函数是:
function curl_post($url,$postData){
$postData = json_encode($postData);
if(!isset($timeout))
$timeout=30;
$curl = curl_init();
if(isset($referer)){
curl_setopt ($curl, CURLOPT_REFERER, $referer);
}
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt ($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt ($curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322)');
curl_setopt ($curl, CURLOPT_HEADER, false);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt ($curl, CURLOPT_POST, true);
curl_setopt ($curl, CURLOPT_POSTFIELDS, $postData);
curl_setopt ($curl, CURLOPT_HTTPHEADER,
array('X-API-Key: my_test_api_key',
"Content-Type: application/json",
"Accept: application/launch27.v2"));
$html = curl_exec ($curl);
curl_close ($curl);
return $html;
}
此处将给定的json发送到$postData
和$url=https://acme-sandbox.l27.co/api/bookings
它返回我的资源ID#4 ...我对发生的事情感到很困惑。我正在关注Launch 27的文档https://bitbucket.org/awoo23/api-2.0/wiki/Create_booking。
我搜索过它但找不到足够的标准来解决这个问题。你能帮我吗?