mirakl / sdk-php-shop

Mirakl PHP SDK for sellers
29 stars 16 forks source link

M12 thread reply with multiple attachments #40

Closed alokinac closed 1 year ago

alokinac commented 1 year ago

Hello,

When adding multiple attachments to a thread reply, only one attachment is actually sent.

eg.

$file = new FileWrapper(new \SplFileObject('test1.txt'));
$file->setFileName('test1.txt'); // Optional, only needed if file name different than 'foobar.txt'
$request->addFile($file);
$file2 = new FileWrapper(new \SplFileObject('test2.txt'));
$file2->setFileName('test2.txt'); // Optional, only needed if file name different than 'foobar.txt'
$request->addFile($file2);

$result = $api->replyToThread($request);

The test2.txt seems to just overwrite the test1.txt instead of being added to a list of attachments.

Is this actually the expected behavior ?

Thanks

jreinke commented 1 year ago

Hello,

I am not able to reproduce the error you are talking about.

Here is the code I have tried successfully for 2 files uploaded on an existing thread:

$client = new ShopApiClient($url, $apiKeyShop);

$request = new ThreadReplyRequest('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', [
    'body' => 'Lorem ipsum dolor sit amet',
    'to'   => [
        ['type' => 'OPERATOR'],
    ],
]);

$file1 = new FileWrapper(new \SplFileObject(__DIR__ . '/test1.txt'));
$file1->setFileName('test1.txt');
$request->addFile($file1);

$file2 = new FileWrapper(new \SplFileObject(__DIR__ . '/test2.txt'));
$file2->setFileName('test2.txt');
$request->addFile($file2);

$result = $client->replyToThread($request);

Can you verify please?

Thank you.

alokinac commented 1 year ago

Hello @jreinke thanks for the feedback. Indeed it looks like this issue was caused by a PHP proxy that was routing CLI requests to Mirakl, and not to the client itself. The problem was caused by the fact that several files that are forming the multipart request all need to have the same name ("files") and the proxy was overwriting that.

We did get it to work, thanks for your quick answer !