Voici l’ensemble du code :
$tab_prod1 = [
‘name’ => ‘Produit 11’,
“tax” => “20”,
“total_price_gross” => “82.50”,
“quantity” => “1”
];
$tab_prod2 = [
‘name’ => ‘Produit 22’,
“tax” => “20”,
“total_price_gross” => “12.50”,
“quantity” => “3”
];
$tab_contenu=array($tab_prod1, $tab_prod2);
$headers = [
‘Accept: application/json’,
‘Content-Type: application/json’,
];
$data_api = [
‘api_token’ => $api_token,
‘invoice’ => [
“kind” => “vat”,
“number” => “null”,
“sell_date” => “2023-10-12”,
“issue_date” => “2023-10-12”,
“payment_to” => “2023-10-19”,
“department_id” => “XXXX”,
“client_id” => “XXXX”,
“test” => “true”,
“positions” => [
$tab_contenu
]
]
];
var_dump($data_api);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data_api));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url_api);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$retour_api = curl_exec($ch);
curl_close ($ch);
A noter que si dans position je remplace $tab_contenu par : [“name” => “Produit 11”, “tax” => “20”, “total_price_gross” => “82.50”, “quantity” => “1”], [“name” => “Produit 22”, “tax” => “20”, “total_price_gross” => “12.50”, “quantity” => “3”] tout fonctionne bien.