sdk-php-shop icon indicating copy to clipboard operation
sdk-php-shop copied to clipboard

UploadOrdersDocument 400 bad request

Open Ggwppino opened this issue 10 months ago • 1 comments

Hi, I initially tried to implement the OR74 UploadOrderDocument API via guzzle without success, then I tried via this SDK, but still I can't attach the invoices to the order, returning a 400 bad request.

This is the code


$api = new ShopApiClient($this->env . '/api', $this->auth());
$docs = new DocumentCollection();
foreach ($order['invoices'] as $invoice) {
    $filename = explode('/', $invoice['filename'])[2];
    $file = fopen(sys_get_temp_dir() . '/' . $filename, 'wb');
    fwrite($file, base64_decode($invoice['file']));
    fclose($file);
    $file = new SplFileObject(sys_get_temp_dir() . '/' . $filename);
    $docs->add(new Document($file, str_replace('_', '-', $filename), 'CUSTOMER_INVOICE'));
}
$request = new UploadOrdersDocumentsRequest($docs, $order['order_id']);
$result = $api->uploadOrderDocuments($request); //GuzzleHttp\Exception\ClientException  Client error: `POST https://adeo-marketplace.mirakl.net/api/orders/XXX-XXXXXXXXX-X/documents` resulted in a `400 Bad Request` response.

Can anyone who has solved it give me a tip? Ty

Ggwppino avatar Apr 18 '24 12:04 Ggwppino