ionafan2 / selling-partner-api-php-sandbox

Working PHP implementation of SP API. Just fill out .env file!
MIT License
11 stars 1 forks source link

Signature Incorrect #6

Open igormatkovic opened 3 years ago

igormatkovic commented 3 years ago

I'm trying to create a report but when ever i try to do a POST request i get a invalid singing request:

$response = $this->send(
                'POST',
                '/reports/2020-09-04/reports',
                null,
                [
                    "x-amz-access-token" => $this->accessToken
                ],
                null,
                '1.1',
                [
                    'form_params' => [
                        'marketplaceIds' => implode(',', $marketplaceIds),
                        'reportType'     => $reportType,
                    ],
                ]
            );

And here is the response I get:

{
    "errors": [
    {
        "message": "The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

        The Canonical String for this request should have been
        'POST
        /reports/2020-09-04/reports

        host:sellingpartnerapi-na.amazon.com
        x-amz-access-token:Atza|jf3fj3f3xxxxxxxxxxxxxxxxxxxxxxxxxxxx
        x-amz-date:20210126T071236Z
        x-amz-security-token:FwoGZxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

        host;x-amz-access-token;x-amz-date;x-amz-security-token
        a294dbxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

        The String-to-Sign should have been
        'AWS4-HMAC-SHA256
        20210126T071236Z
        20210126/us-east-1/execute-api/aws4_request
        402acxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
        ",
        "code": "InvalidSignature"
    }
]
}

I looked at the core of the library and compared the results, the structure I'm sending matches perfectly with the response I'm receiving from Amazon. But for some reason, the signature ends up different.

Any ideas?

kingsun-he commented 3 years ago

I met the same problem. I use the sandbox environment.

Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error:POST https://sandbox.sellingpartnerapi-eu.amazon.com/reports/2020-09-04/reports/resulted in a403 Forbiddenresponse: { "errors": [ { "message": "The request signature we calculated does not match the signature you provided. C (truncated...)

Here is my code:

` public function createReport(array $options): ?array{ $response = $this->send( 'POST', '/reports/2020-09-04/reports/', null, ["x-amz-access-token" => $this->accessToken], null, '1.1', [ 'form_params' => [ 'reportType' => 'GET_FLAT_FILE_OPEN_LISTINGS_DATA', 'marketplaceIds' => ['A1F83G8C2ARO7P'], 'dataStartTime' => '2021-01-24T16:00:00Z', ], ] );

    if (0 === count((array)$response['payload'])) {
        return null;
    }

    return $response['payload'];
}

`

Any idea? @ionafan2

ionafan2 commented 3 years ago

I don’t really know why it’s happening. I tried myself and got the same error. Then I tried in Postman - same issue. At this point I guess something with the endpoint might be wrong. I'll keep you updated.

ionafan2 commented 3 years ago

More about issue here ->: Troubleshooting canonicalization errors

mandykaurdev commented 3 years ago

Is anyone find the solutions for the same ? :|