mirakl / sdk-php-shop

Mirakl PHP SDK for sellers
30 stars 16 forks source link

UploadOrdersDocument 400 bad request #66

Closed Ggwppino closed 2 days ago

Ggwppino commented 7 months ago

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

amarie75 commented 6 months ago

Hello,

I've run your code and there don't seem to be any errors. Have you checked that the file generated in the temporary directory (sys_get_temp_dir() . '/' . $filename) is correct and can be opened?

Best regards, Alexandre