I have an order that has multiple line items (in particular 15) and I am trying to loop through id's with params What am I missing here?:
foreach($line_ids as $key => $id ) {
$params = [
"order_lines" => [
"accepted" => true,
"id" => $id
]
];
$data = json_encode($params);
echo '<pre>';
print_r($data);
echo '</pre>';
}
the out put looks like this:
{
"order_lines":{
"accepted":true,
"id":"75167652-1"
}
}
but it needs to be like this for each line item:
{
"order_lines": [
{
"accepted": true,
"id": "75261431-1"
}
]
}
here is the CURL for a single id:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $baseUrl . $order_id . '/accept',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS =>'{
"order_lines": [
{
"accepted": true,
"id": "75261431-1"
}
]
}
',
CURLOPT_HTTPHEADER => array(
'Authorization: xxxxxx-xxxxx-xxxxx-xxxxx',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
here is the CURL i've tried for multiples id's with the foreach above.:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $baseUrl . $order_id . '/accept',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS => http_build_query($data),
CURLOPT_HTTPHEADER => array(
'Authorization: xxxxxx-xxxxx-xxxxx-xxxxx',
'Content-Type: application/json'
),
));
$accept_orders = curl_exec($curl);
curl_close($curl);
echo $accept_orders . '<br>';
but this is the output I get for each line item:
{ "message" : "Body is required", "status" : 400 }