jlevers / selling-partner-api

A PHP client library for Amazon's Selling Partner API
BSD 3-Clause "New" or "Revised" License
398 stars 188 forks source link

Invoice Upload: NotImplemented #685

Closed tvu002 closed 4 months ago

tvu002 commented 5 months ago

Problem description:

Error:

Current I try to upload my invoice for the UPLOAD_VAT_INVOICE feed. But after the createFeedDocument call I can't upload the file into to the provided place. I get this response:

<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>NotImplemented</Code>
<Message>A header you provided implies functionality that is not implemented</Message>
<Header>Transfer-Encoding</Header><RequestId>xxxx</RequestId><HostId>xxxx
=</HostId></Error>

Code


        $feedType = FeedType::UPLOAD_VAT_INVOICE;

        $createFeedDocumentSpec = new CreateFeedDocumentSpecification(['content_type' => $feedType['contentType']]);
        $feedDocumentInfo = $this->feedsApi->createFeedDocument($createFeedDocumentSpec);

        $invoiceResource = \GuzzleHttp\Psr7\Utils::tryFopen($fileUrl, 'r');
        $invoiceContent = \GuzzleHttp\Psr7\Utils::tryGetContents($invoiceResource);

        $stack = new HandlerStack();
        $stack->setHandler(new CurlHandler());
        $stack->push(new GuzzleLogMiddleware(AmazonApiLogger::getInstance()));
        $client = new Client(['handler' => $stack]);
        try {
            $document = new Document($feedDocumentInfo, $feedType, $client);
            $document->upload(base64_encode($invoiceContent));
        } catch (\Exception $exception) {
        }

Does someone knows the issue? I am still using v5.

misterakko commented 5 months ago

Why do you call directly Guzzle? After $feedDocumentInfo = createFeedDocument I do something like this instead:


        $feedDocumentId = $feedDocumentInfo->getFeedDocumentId();
        // Upload feed contents to document
        $docToUpload = new SellingPartnerApi\Document($feedDocumentInfo, $feedType);
        $docToUpload->upload($xml);
        // Ask Amazon to queue the feed
      $createFeedSpecification = new SellingPartnerApi\Model\FeedsV20210630\CreateFeedSpecification (array ('feed_type'=>$feedType['name'], 'marketplace_ids'=>array($a->prefs['amazon-MARKETPLACE_ID']), 'input_feed_document_id'=>$feedDocumentId));
        $sent = $feedsApi->createFeed($createFeedSpecification);
        return $sent;
tvu002 commented 5 months ago

In order to to log the trace. We are using a different logging logic in our project. With that I was able to narrow down the issue with the upload to <Code>NotImplemented</Code>

tvu002 commented 5 months ago

Additional information since I saw you code: The upload works for all Feed types which requires a xml file. Currently only the pdf files are not working.

Patricia92 commented 4 months ago

I work in the same company as @tvu002, we could fix the issue, there were three problems:

  1. We could not use Guzzle in the upload, probably because of this issue
  2. We had to add the metadata: prefix to the feed specifications
  3. We had to change the content type to application/json even though we upload a PDF

So this issue can be closed.

jlevers commented 4 months ago

@tvu002, are you the same person who emailed me about this issue? Just want to confirm that you're all set, if that's in fact the case.