jlevers / selling-partner-api

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

403 Forbidden - SignatureDoesNotMatch #486

Closed nikgilbe closed 1 year ago

nikgilbe commented 1 year ago

Problem description:

Since last night, around 7:40GMT, with no code or config updates, we have started receiving a 403 error when trying to upload any feeds (inventory, shipping updates). This has been working fine for many months, and other APIs are still working fine (e.g. getOrders, getMyFeesEstimates) so I don't believe but could easily be wrong) it to be a problem with access keys, secrets etc. We have refreshed them just in case, but no change. The error happens at $docToUpload->upload($feedContents). I have raised a case with Seller Central, but am hoping someone here may have a suggestion as I have had to turn off our "shop" till we can resolve it.

Error:

SignatureDoesNotMatchThe request signature does not match the signature you provided (truncated...) ## Code $lwaClientId = $sp_conn['client_id']; $lwaClientSecret = $sp_conn['secret']; $lwaRefreshToken = $sp_conn['refresh_token']; $awsAccessKeyId = $sp_conn['aws_access_key']; $awsSecretAccessKey = $sp_conn['aws_secret']; $config = new SellingPartnerApi\Configuration([ 'lwaClientId' => $lwaClientId, 'lwaClientSecret' => $lwaClientSecret, 'lwaRefreshToken' => $lwaRefreshToken, 'awsAccessKeyId' => $awsAccessKeyId, 'awsSecretAccessKey' => $awsSecretAccessKey, "endpoint" => SellingPartnerApi\Endpoint::EU ]); $feedsApi = new SellingPartnerApi\Api\FeedsV20210630Api($config) $fullFeedName = "/home/feeds/inv_feed.txt"; $feedType = FeedType::POST_FLAT_FILE_INVLOADER_DATA; $marketplace_ids = array('A1F83G8C2ARO7P'); $createFeedDocSpec = new SellingPartnerApi\Model\FeedsV20210630\CreateFeedDocumentSpecification(['content_type' => $feedType['contentType']]); try { $feedDocumentInfo = $feedsApi->createFeedDocument($createFeedDocSpec); } catch (Exception $e) { echo 'Exception when calling FeedsApi->getFeedDocument: ', $e->getMessage(), PHP_EOL; return $e->getMessage(); } $feedDocumentId = $feedDocumentInfo->getFeedDocumentId(); $feedContents = file_get_contents($fullFeedName); $docToUpload = new SellingPartnerApi\Document($feedDocumentInfo, $feedType); try { **$docToUpload->upload($feedContents);** } catch (Exception $e) { echo 'Exception when calling FeedsApi->upload: ', $e->getMessage(), PHP_EOL; return $e->getMessage(); } ``` ## Seller Central SP API config page screenshot ![SP-API](https://user-images.githubusercontent.com/25084818/220321958-028f5dbb-4958-4625-b2de-59cac8c3bdfc.png)
iamvishaldubeyy commented 1 year ago

I am getting the same error when calling the upload() method

try {
            $feedType = FeedType::POST_FBA_INBOUND_CARTON_CONTENTS;
            $feedsApi = new FeedsApi($config);

            // Create feed document
            $createFeedDocSpec = new Feeds\CreateFeedDocumentSpecification(['content_type' => $feedType['contentType']]);
            $feedDocumentInfo = $feedsApi->createFeedDocument($createFeedDocSpec);
            $feedDocumentId = $feedDocumentInfo->getFeedDocumentId();
            // Upload feed contents to document
            $feedContents = file_get_contents(FCPATH.'../inventoryFeed.xml');

            $docToUpload = new SellingPartnerApi\Document($feedDocumentInfo, $feedType);

            $docToUpload->upload($feedContents);

            $createFeedSpec = new Feeds\CreateFeedSpecification();
            $createFeedSpec->setMarketplaceIds([$marketplace_id]);
            $createFeedSpec->setInputFeedDocumentId($feedDocumentId);
            $createFeedSpec->setFeedType($feedType['name']);

            $createFeedResult = $feedsApi->createFeed($createFeedSpec);
            $feedId = $createFeedResult->getFeedId();
            if ($feedId) {
                $this->db->where('id',$fba_shipment['id'])->update('fba_shipment',array('feed_on'=>date('Y-m-d H:i:s'),'feed_submission_id'=>$feedId,'feed_status'=>'submitted','modified_on'=>date('Y-m-d H:i:s'),'modified_by'=>$user));
            }
            $this->logs->log('log_mws',array('id'=>$result['headers']['x-amzn-RequestId'][0],'fba_id'=>str_replace('F','',$fba['id']),'fba_shipment_id'=>$fba_shipment['id'],'result'=>'successful','type'=>'carton_feed_submission','request'=>'','response'=>'','created_on'=>date('Y-m-d H:i:s'),'created_by'=>$user));
        } catch (Exception $e) {
            $response = $e->getMessage();
            print_r($response);exit;
            $this->logs->log('log_mws',array('fba_id'=>str_replace('F','',$fba['id']),'fba_shipment_id'=>$fba_shipment['id'],'result'=>'failed','type'=>'carton_feed_submission','failed_message'=>$response,'request'=>'','response'=>'','created_on'=>date('Y-m-d H:i:s'),'created_by'=>$user));
            $this->error = $response;
            exit;
        }
    The error I am getting is

    `PUT https://tortuga-prod-na.s3-external-1.amazonaws.com/%2FNinetyDays/amzn1.tortuga.4.na.cfafa93f-b187-4365-9c48-1fae6675ca50.TGMA2AEAQRBZP?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20230221T080021Z&X-Amz-SignedHeaders=content-type%3Bhost&X-Amz-Expires=300&X-Amz-Credential=AKIA5U6MO6RABV4GCCBL%2F20230221%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=5f573727d59beb1f8ba715fe1e071ed060623ea816052d6ea2d2c92f1a2588a4` resulted in a `403 Forbidden` response: SignatureDoesNotMatchThe request signature we calcul (truncated...)`
RoanOak127 commented 1 year ago

Do you know if the Amazon Seller you're connecting to changed their LWA tokens? https://developer-docs.amazon.com/sp-api/changelog/important-you-must-rotate-your-login-with-amazon-lwa-credentials-client-secrets-for-all-applications-every-180-days I've had this happen with one of my clients already who changed it without letting me know.

nikgilbe commented 1 year ago

Do you know if the Amazon Seller you're connecting to changed their LWA tokens? https://developer-docs.amazon.com/sp-api/changelog/important-you-must-rotate-your-login-with-amazon-lwa-credentials-client-secrets-for-all-applications-every-180-days I've had this happen with one of my clients already who changed it without letting me know.

Hi - the sellers are actually me and a colleague, so this shouldn't be the case. The fact other APIs are working is what is confusing me, it's just the upload that fails, whatever the type of feed.

Julian3004 commented 1 year ago

I have the same problem. I tried to change the refreshtoken but it doesn't work. Maybe Amazon have actually problems.

nikgilbe commented 1 year ago

Interesting, thanks. I've not had any response yet from Amazon on the case raised, will update if it gets resolved there

jlevers commented 1 year ago

The signed URL used by the upload method is also actually generated by Amazon themselves...the library doesn't calculate that signature. But just to make sure this isn't related to a library change – did any of you update the library version right before this error started? There was a minor change to the upload method in the latest release (v5.6.0) which I released 4 days ago.

nikgilbe commented 1 year ago

I did update, on the 17th itself I believe so I didn't think to check that as the issue didn't start until last night. But I have just done a downgrade to 5.5.4, and it's working.......

nikgilbe commented 1 year ago

2 inventory feeds in quick succession just being loaded by Amazon - thank you - it didn't occur to me to try downgrading for some reason.

Julian3004 commented 1 year ago

Yeah same here.I'm in the process of implementing the SP-API and therefore have the newest version since yesterday. Thank u!

nikgilbe commented 1 year ago

And processing reports received successfully, so all back to normal my side.

Thanks again - for your next trick, can you fix an issue I'm having with o365 emails / oauth /authentication ? :-)

jlevers commented 1 year ago

I'm going to leave this open, because clearly there's some bug with the latest version. Are you guys working with reports that you expect to be using a charset other than utf-8? Japanese reports and some EU reports fall into this category

nikgilbe commented 1 year ago

OK, no problem. Should be UTF-8 only for me (UK only)

iamvishaldubeyy commented 1 year ago

Downgrading to 5.5.4 helped. Thanks!

M-Mommsen commented 1 year ago

Me too, after an upgrade this morning! Downgrade to 5.5.4 helped.

I did not have the time to test exactly what functions worked and what not, but I remember invoice upload and fba inbound failed. Both use uploads at some point.

AlexeyKosov commented 1 year ago

I had to downgrade it as well :(

KhorneHoly commented 1 year ago

Same issue here. Upgraded to 5.6 today and we could not upload any feeds. Feeds are ISO-8856-15 encoded.

plegenza commented 1 year ago

Same issue for EU. Downgrading to 5.5.4 resolved problem.

meertensm commented 1 year ago

Also EU and downgraded solved it

M-Mommsen commented 1 year ago

I just noticed, I get the same error if I try to pass the charset, like with the new "withContentType" function.

$createFeedDocSpec = new Feeds\CreateFeedDocumentSpecification(['content_type' => $feedType['contentType'].'; charset='.$charset]);

Could it be there is some sort of conversion happening AFTER the signature calculation is done ? Or maybe the header is changed after signature calculation.

jlevers commented 1 year ago

Thanks for your patience everyone – this should be fixed in v5.7.0.

M-Mommsen commented 1 year ago

It's been a few month since I last updated (or rather downgraded to 5.5.4) the library. Since I ran into a codepage issue, I tried the recent 5.10.2 and use utf-8 (EU marketplace, so default seems to be cp1252). But when I add a charset to the upload function, I still get a wrong signature error. Could it really be this issue is only partially resolved ?

$docToUpload = new SellingPartnerApi\Document($feedDocumentInfo, $feedType);
$docToUpload->upload($feedContents,'utf-8');

I have to remove the 2nd parameter or else I get a signature error.

jlevers commented 1 year ago

What happens if you pass cp1252 as the encoding parameter?

And @nikgilbe, sorry to drag you back into this...are you on the latest version of the library? And are you running into these errors?

M-Mommsen commented 1 year ago

$docToUpload->upload($feedContents,'cp1252');

Also results in SignatureDoesNotMatch.

nikgilbe commented 1 year ago

Sorry, I'm still on an old version. I need to update a number of libraries, but need to find the right time to do it. Will update when I do if things working as expected or not.