Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issues since 5 may on amazon JP with feeds #717

Closed
emelaz opened this issue May 31, 2024 · 2 comments
Closed

issues since 5 may on amazon JP with feeds #717

emelaz opened this issue May 31, 2024 · 2 comments

Comments

@emelaz
Copy link

emelaz commented May 31, 2024

Problem description:

code worked perfectly for years and since 2024-05-05 it says InvalidInput ?
same code works in US CA MX FR IT ...
only in JP does not work.
I cannot upload files (POST_FLAT_FILE_INVLOADER_DATA)
I refreshed the api credit in case but no

Error:

array (12) [
    'errors' => array (1) [
        0 => array (3) [
            'code' => string (12) "InvalidInput"
            'message' => string (26) "Invalid request parameters"
            'details' => string (0) ""
        ]
    ]
    'feed_type' => string (29) "POST_FLAT_FILE_INVLOADER_DATA"
    'marketplace_ids' => array (1) [
        0 => string (14) "A1VC38T7YXB528"
    ]
    'input_feed_document_id' => string (70) "amzn1.tortuga.4.fe.51fd48e0-5e7b-4033-912f-7949917e35db.T1WAT7B53NRPBO"
    'feedDocumentInfo' => SellingPartnerApi\Model\FeedsV20210630\CreateFeedDocumentResponse (1) (
        protected 'container' -> array (3) [
            'feed_document_id' => string (70) "XXX"
            'url' => string (402) "XXX"
            'headers' => array (12) [
                'Server' => array (1) [
                    0 => string (6) "Server"
                ]
                'Date' => array (1) [
                    0 => string (29) "Fri, 31 May 2024 12:38:07 GMT"
                ]
                'Content-Type' => array (1) [
                    0 => string (16) "application/json"
                ]
                'Content-Length' => array (1) [
                    0 => string (3) "502"
                ]
                'Connection' => array (1) [
                    0 => string (10) "keep-alive"
                ]
                'x-amz-rid' => array (1) [
                    0 => string (20) "XXX"
                ]
                'x-amzn-RateLimit-Limit' => array (1) [
                    0 => string (3) "0.5"
                ]
                'x-amzn-RequestId' => array (1) [
                    0 => string (36) "XXX"
                ]
                'x-amz-apigw-id' => array (1) [
                    0 => string (15) "XXX"
                ]
                'X-Amzn-Trace-Id' => array (1) [
                    0 => string (32) "XXX"
                ]
                'Vary' => array (1) [
                    0 => string (39) "Content-Type,Accept-Encoding,User-Agent"
                ]
                'Strict-Transport-Security' => array (1) [
                    0 => string (44) "max-age=47474747; includeSubDomains; preload"
                ]
            ]
        ]
    )
    'feedType' => array (2) [
        'contentType' => string (25) "text/tab-separated-values"
        'name' => string (29) "POST_FLAT_FILE_INVLOADER_DATA"
    ]
    'feedTypeName' => string (29) "POST_FLAT_FILE_INVLOADER_DATA"
    'marketplace_id' => string (14) "A1VC38T7YXB528"
    'file' => string (58) "...QoRKsegbz5asin.amazonJP.csv"
    'err' => array (0) []
    'headers' => null
    'payload' => null
]

Code

function submitFeed($file,$feedTypeName,$marketplace_ids=null)
        {

            if (!file_exists($file)||!is_file($file)||!is_readable($file)||filesize($file)==0) {
                $report = ['feedTypeName'=>$feedTypeName??null,
                           'marketplace_id'=>$marketplace_id??null,
                           'file'=>$file??null,
                           'exists'=>file_exists($file),
                           'is_file'=>is_file($file),
                            'is_readable'=>is_readable($file)??null,
                            'filesize'=>filesize($file) ?? null];


                err('erreur file', $report);
                exit;
            }

            $feedTypeName = trim($feedTypeName, '_');

            $feedTypeClass = new ReflectionClass(FeedType::class);
            if ($feedTypeClass->hasConstant($feedTypeName)) {
                $feedType = $feedTypeClass->getConstant($feedTypeName);
            } else {
                // Gérer l'erreur si la constante n'existe pas.
                err("Invalid feed type: $feedTypeName");
                return false;
            }

            if (empty($marketplace_ids)) $marketplace_ids = $this->marketplace_id;
            $marketplace_id=$this->marketplaceIdsFormat($marketplace_ids, false)[0];

            $apiInstance = new FeedsApi($this->config);

            $createFeedDocSpec = new CreateFeedDocumentSpecification(['content_type' => $feedType['contentType']]);
            $feedDocumentInfo = $this->callApi($apiInstance,'createFeedDocument',$createFeedDocSpec);

            $feedDocumentId = $feedDocumentInfo['feedDocumentId']??null;

            if (empty($feedDocumentId)) {
                $report = ['feedDocumentInfo'=>$feedDocumentInfo??null,
                           'feedType'=>$feedType??null,
                           'feedTypeName'=>$feedTypeName??null,
                           'marketplace_id'=>$marketplace_id??null,
                           'file'=>$file??null,
                           'err'=>$this->error??$this->errors??null,
                           'headers'=>$this->headers??null,
                           'payload'=>$this->payload??null];

                //gestion des erreurs
                $error = $feedDocumentInfo['errors'][0]??null;
                $handle_error= amazon_errors::handle($this->cfg_id,$error,$report);
                if (!$handle_error) {
                    err('erreur feedDocumentId', $report);
                    exit;
                }
            }

            $url = $feedDocumentInfo['url']??null;



            $feedDocumentInfo = $this->apiReturn;

            if (!is_object($feedDocumentInfo)) {
                $report = ['feedDocumentInfo'=>$feedDocumentInfo??null,
                           'feedType'=>$feedType??null,
                           'feedTypeName'=>$feedTypeName??null,
                           'marketplace_id'=>$marketplace_id??null,
                           'file'=>$file??null,
                           'err'=>$this->error??$this->errors??null,
                           'headers'=>$this->headers??null,
                           'payload'=>$this->payload??null,
                            ];
                err('erreur feedDocumentInfo', $report);
                exit;
            }



            $feedContents = file_get_contents($file);

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


            $body = new CreateFeedSpecification([
                'feed_type' => $feedTypeName,
                "marketplace_ids" => [$marketplace_id],
                "input_feed_document_id" => $feedDocumentId,
            ]);

            $apiInstance = new FeedsApi($this->config);
            $result = $this->callApi($apiInstance,'createFeed',$body);

            $errors = $result['errors']??null;
            $feedId =  $result['feedId']??null;
            if ($errors||empty($feedId) ) {
                $report = ['errors'=>$errors??$result,
                        'feed_type' => $feedTypeName,
                        "marketplace_ids" => [$marketplace_id],
                        "input_feed_document_id" => $feedDocumentId,
                           'feedDocumentInfo'=>$feedDocumentInfo??null,
                           'feedType'=>$feedType??null,
                           'feedTypeName'=>$feedTypeName??null,
                           'marketplace_id'=>$marketplace_id??null,
                           'file'=>$file??null,
                           'err'=>$this->error??null,
                           'headers'=>$this->headers??null,
                           'payload'=>$this->payload??null];
                err('erreur createFeed: '.$errors[0]['message'], $report);
                exit;
            }
            return $feedId;

        }

Seller Central SP API config page screenshot

your screenshot here

@jlevers
Copy link
Owner

jlevers commented Jun 10, 2024

Which version of the library are you using?

@jlevers
Copy link
Owner

jlevers commented Jul 9, 2024

Since I haven't heard back from you on this, I'm going to close the issue. Feel free to reopen it if you still need help.

@jlevers jlevers closed this as completed Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants