Это фрагмент кода, который я использую для публикации данных через «API»
<?php
curl_setopt_array($curl, array(
CURLOPT_URL => "api.ewmjobsystem.com/third-party/add_job",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "license_key=***&customer_id=74&full_name=SystemTest&address=SystemTestAddress&site_address=SystemSiteAddress&short_description=SystemShortDescription&item_id=&item_name=SystemItemName&price=4.99&completion_date=25\04\2019",
CURLOPT_HTTPHEADER => array(
"content-type: application/x-www-form-urlencoded",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
?>
<?php
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
Теперь я могу делать все, что захочу с этим кодом, но есть одна часть документации API, котораяя не понимаю.Я могу успешно все добавить до "продуктов работы".Может ли кто-нибудь указать мне или хорошо (завиток для чайников) или, может быть, показать мне, как я должен публиковать данные правильно.Я понятия не имел, как задать вопрос, поэтому приветствуются все необходимые изменения.
Пример сообщения выглядит так
{
"license_key":"123456",
"customer_id":"74",
"full_name":"Jack",
"email_address":"test@test.com",
"telephone":"002125254",
"mobile":"00787787",
"address":"126 Unit ",
"city":"Liverpool",
"county":"MERSEYSIDE",
"postcode":"CH41 1EP",
"site_company_name":"Eworks",
"site_full_name":"K V P",
"site_telephone":"012121",
"site_mobile":"0787878",
"site_email_address":"site@test.com",
"site_address":"127",
"site_city":"Liverpool",
"site_county":"MERSEYSIDE",
"site_postcode":"CH41 1EP",
"site_notes":"this is a site notes",
"customer_ref":"12",
"wo_ref":"34",
"po_ref":"56",
"completion_date":"25\/04\/2017",
"short_description":"this is short desc",
"description":"long desc",
"customer_notes":"customer notes",
"job_products":[
{
"item_id":"221",
"item_name":"TEST:SMOKE OR PRESSURE TEST",
"item_code":"039018",
"item_description":"Test:Carry out smoke or pressure test.",
"cost_price":"21.09",
"price":"32.44"
},
{
"item_id":"255",
"item_name":"WALL:DEMOLISH EXTERNAL WALL",
"item_code":"101101",
"item_description":"Wall:Take down external half brick wall and remove spoil.",
"cost_price":"12.58",
"price":"19.35"
}
]
}
Итак, я наконец-то получил от них несколько примеров файлов (когда мне сказали, что яотменим £ 150 в месяц, я им платил), и они прислали мне это как пример, но все еще не работает Server Error: 500 (Internal Server Error)
example1.php
error_reporting(E_ALL);
include_once('includes.php');
$licence_key = '***'; //Your Licence Key here
//getting the customers
//$response = postRequest($licence_key, 'get_customers');
//print_r($response);
//Add Job
$job_products = [
[
"item_id" => "",
"item_name" => "Product A",
"item_code" => "039018",
"item_description" => "Test:Carry out smoke or pressure test.",
"cost_price" => "21.09",
"price" => "32.44"
],
[
"item_id" => "",
"item_name" => "Product B",
"item_code" => "039018",
"item_description" => "Test:Carry out smoke or pressure test.",
"cost_price" => "10",
"price" => "50"
]
];
$data = [
'completion_date' => '31/03/2019',
'customer_id' => 1,
'full_name' => 'Full Name',
'email_address' => 'email@email.com',
'telephone' => '012122212',
'mobile' => '0787878',
'address' => 'Line 1 address'.chr(10).'Line 2 address',
'city' => 'City',
'county' => 'County',
'postcode' => 'Postcode',
'site_company_name' => 'Site Company Name',
'site_full_name' => 'Site Contact Name',
'site_telephone' => '012121212',
'site_mobile' => '07878787',
'site_fax' => 'Depreciated, not in use',
'site_email_address' => 'email@email.com',
'site_address' => 'Site Line 1 address'.chr(10).'Line 2 address',
'site_city' => 'Site City',
'site_county' => 'Site County',
'site_postcode' => 'Site Postcode',
'site_notes' => 'Site Notes',
'customer_ref' => 'Customer Ref',
'wo_ref' => 'Customer Job Ref',
'po_ref' => 'PO Ref',
'short_description' => 'short description of job',
'description' => 'long description of job',
'customer_notes' => 'Customer notes',
'job_products' => json_encode($job_products)
];
$response = postRequest($licence_key, 'add_job', $data);
print_r($response);
и включает в себя .php
function postRequest($license_key, $method, $data = []){
$url = 'http://api.ewmjobsystem.com/third-party/';
$post_string = '';
$data['license_key'] = $license_key;
$ch = curl_init();
if(is_array($data) && count($data) > 0){
$post_string = http_build_query($data);
curl_setopt($ch, CURLOPT_POST, count($data));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
}
curl_setopt($ch, CURLOPT_URL, $url.$method);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_USERAGENT, "Eworks Manager Client API");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // this line makes it work under https
$response = curl_exec($ch);
curl_close($ch);
return $response;
}