jlevers / selling-partner-api

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

Type Error when calling validateContentDocumentAsinRelations() #781

Closed TonyMarston closed 2 months ago

TonyMarston commented 2 months ago

Problem description:

Error:

Fatal Error: Uncaught exception from TypeError, message = SellingPartnerApi\Seller\APlusContentV20201101\Api::validateContentDocumentAsinRelations(): Argument #1 ($postContentDocumentRequest) must be of type SellingPartnerApi\Seller\APlusContentV20201101\Dto\PostContentDocumentRequest, string given

How do I turn the JSON string into an object of the required type?

Code


$connector = SellingPartnerApi::seller(
            clientId: $client_id,
            clientSecret: $client_secret,
            refreshToken: $refresh_token,
            endpoint: Endpoint::{$endpoint}
);

        $api = $connector->aPlusContentV20201101();

        try {
            $result = $api->validateContentDocumentAsinRelations(
                postContentDocumentRequest: $json_string,
                marketplaceId: $marketplace_id);
        } catch (Exception $e) {
            echo 'Exception when calling aPlusContentV20201101->validateContentDocumentAsinRelations: ',
                $e->getMessage(),
                PHP_EOL;
        };
TonyMarston commented 2 months ago

After trawling through the source code and trying various combinations I found that the method call needed to be changed to the following:

$result = $api->validateContentDocumentAsinRelations(
        marketplaceId: $marketplace_id,
        postContentDocumentRequest: new Dto\PostContentDocumentRequest(new Dto\ContentDocument($name,
                                                                                               $contentType,
                                                                                               $locale,
                                                                                               $contentModuleList,
                                                                                               $contentSubType)));

If this had been properly documented I would not have had to waste so much time.