selling-partner-api icon indicating copy to clipboard operation
selling-partner-api copied to clipboard

GET_BRAND_ANALYTICS_SEARCH_QUERY_PERFORMANCE_REPORT: A client error occurred

Open Braindea7 opened this issue 6 months ago • 0 comments

Problem description:

I am currently trying to generate the report ‘GET_BRAND_ANALYTICS_SEARCH_QUERY_PERFORMANCE_REPORT’, but unfortunately I cannot understand why I keep getting the error message from the ‘FATAL’ report. All data looks exactly as required by the Amazon schema. Have you had a similar experience?

Error:

{"errorDetails":"A client error occurred. Please double check that your parameters are valid and fulfill the requirements of the report type."}

Code

//POST Request
{
    "reportType": "GET_BRAND_ANALYTICS_SEARCH_QUERY_PERFORMANCE_REPORT",
    "dataStartTime": "2025-08-01",
    "dataEndTime": "2025-08-31",
    "reportOptions":{
        "asin": "B0CXWFX51W",
        "reportPeriod": "MONTH"
    }
}

//$container get filled from post request
$container = new ReportContainer(
                $request->header('spapi-seller'),
                $insertDB->id, 
                ['input' => $request->all(), 'header' => getHeaders($request)],
                'reports',
                $request->input('reportType'),
                $request->input('dataStartTime',null),
                $request->input('dataEndTime',null),
                $request->input('reportOptions',null),
 );

//Init Normalizer
        $normalizer = new FBAReportsNormalizer();
//Do something with $container
        $response = $normalizer->createReport($container->__get('reportType'), $container->__get('dataStartTime'), $container->__get('dataEndTime'), $container->__get('reportOptions'), $container->__get('requestdata'));

//Creates a report.
    //POST /reports/2021-06-30/reports
    public function createReport(string $reportType, string|null $dataStartTime = null, string|null $dataEndTime = null, array|null $reportOptions = null, array $request){
        //VALIDATE REQUEST
        if(isset($reportType) && $reportType !== ""){
          if(!$this->validateReportType($reportType)){
            return ['success' => false, 'status' => 400, 'message' => 'Invalid reportType: '.$reportType];
          }  
        }else{
            return ['success' => false, 'status' => 400, 'message' => 'Missing reportType: '.$reportType];
        }
        if($this->validateDateTime($dataStartTime) === false){
            return ['success' => false, 'status' => 400, 'message' => 'Invalid dataStartTime Format: '.$dataStartTime];
        }

        if($this->validateDateTime($dataEndTime) === false){
            return ['success' => false, 'status' => 400, 'message' => 'Invalid dataEndTime Format: '.$dataEndTime];
        }

        $seller = $this->createConnection($request);
        $apiConnection = $seller->reportsV20210630();

        //TYPECAST
        $reportSpecification = $this->buildReportSpecification($reportType, $dataStartTime, $dataEndTime, $reportOptions);

        try{
            $response = $apiConnection->createReport($reportSpecification); //SellingPartnerApi\Seller\ReportsV20210630\Responses\CreateReportResponse | SellingPartnerApi\Seller\ReportsV20210630\Responses\ErrorList
        }catch(ClientException $e){
            return ['success' => false, 'status' => $e->getStatus(), 'message' => $e->getMessage()];
        }
        $response_json = $response->json();

        if($response->status() === 202){
            return ['success' => true, 'status' => $response->status(), 'reportID' => $response_json["reportId"]];        
        }else{
            return ['success' => false, 'status' => $response->status(), 'message' => $response_json];
        }
    }

//Create CreateReportSpecification Object
protected function buildReportSpecification(string $reportType, string|null $dataStartTime = null, string|null $dataEndTime = null, array|null $reportOptions = null){
        $dataStartTimeFormat = ($dataStartTime ? new \DateTime($dataStartTime) : null);
        $dataEndTimeFormat = ($dataEndTime ? new \DateTime($dataEndTime) : null);
        //$reportOptionsArray = ($reportOptions !== null ? json_decode(json_encode($reportOptions),true) : null);
        $reportOptionsArray = $reportOptions;

        return new CreateReportSpecification($reportType, [config("spapi.marketplaceids.germany")], $reportOptionsArray, $dataStartTimeFormat, $dataEndTimeFormat);
    }

Braindea7 avatar Sep 02 '25 13:09 Braindea7