[ 'application/json', ], 'getFeed' => [ 'application/json', ], 'getItems' => [ 'application/json', ], 'getVariations' => [ 'application/json', ], 'listFeeds' => [ 'application/json', ], 'searchItems' => [ 'application/json', ], ]; /** * @param ClientInterface $client * @param Configuration $config * @param HeaderSelector $selector * @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec */ public function __construct( ?ClientInterface $client = null, ?Configuration $config = null, ?HeaderSelector $selector = null, int $hostIndex = 0 ) { $this->client = $client ?: new Client(); $this->config = $config ?: Configuration::getDefaultConfiguration(); $this->headerSelector = $selector ?: new HeaderSelector(); $this->hostIndex = $hostIndex; // Token manager created lazily on first API call } /** * Set the host index * * @param int $hostIndex Host index (required) */ public function setHostIndex($hostIndex): void { $this->hostIndex = $hostIndex; } /** * Get the host index * * @return int Host index */ public function getHostIndex() { return $this->hostIndex; } /** * @return Configuration */ public function getConfig() { return $this->config; } /** * Get or create OAuth2 token manager with lazy initialization and credential change detection * * @throws \InvalidArgumentException If OAuth2 configuration is missing * @return OAuth2TokenManager */ private function getOrCreateTokenManager(): OAuth2TokenManager { // Get current configuration values $currentCredentialId = $this->config->getCredentialId(); $currentCredentialSecret = $this->config->getCredentialSecret(); $currentVersion = $this->config->getVersion(); $currentAuthEndpoint = $this->config->getAuthEndpoint(); // Check if token manager needs to be created or recreated $needsRecreation = $this->tokenManager === null || $this->cachedCredentialId !== $currentCredentialId || $this->cachedCredentialSecret !== $currentCredentialSecret || $this->cachedVersion !== $currentVersion || $this->cachedAuthEndpoint !== $currentAuthEndpoint; if ($needsRecreation) { // Validate required OAuth2 configuration if (!$currentCredentialId || !$currentCredentialSecret || !$currentVersion) { throw new \InvalidArgumentException( "Missing OAuth2 configuration. Please specify credentialId, credentialSecret, and version." ); } // Create new token manager with current credentials $oauthConfig = new OAuth2Config( $currentCredentialId, $currentCredentialSecret, $currentVersion, $currentAuthEndpoint ); $this->tokenManager = new OAuth2TokenManager($oauthConfig); // Cache current configuration values $this->cachedCredentialId = $currentCredentialId; $this->cachedCredentialSecret = $currentCredentialSecret; $this->cachedVersion = $currentVersion; $this->cachedAuthEndpoint = $currentAuthEndpoint; } return $this->tokenManager; } /** * Build OAuth2 and custom headers for requests * * @param string $resourcePath The API resource path * @return array Array of headers */ private function buildAuthenticatedHeaders(string $resourcePath): array { // Get OAuth2 token (creates/recreates token manager if needed) $token = $this->getOrCreateTokenManager()->getToken(); // Build OAuth2 headers $oauthHeaders = [ 'Authorization' => "Bearer {$token}, Version {$this->config->getVersion()}" ]; return $oauthHeaders; } /** * Operation getBrowseNodes * * @param string $xMarketplace Target Amazon Locale. Type: String Default Value: None Example: 'www.amazon.com' (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetBrowseNodesRequestContent $getBrowseNodesRequestContent getBrowseNodesRequestContent (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getBrowseNodes'] to see the possible values for this operation * * @throws \Amazon\CreatorsAPI\v1\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetBrowseNodesResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ThrottleExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent */ public function getBrowseNodes($xMarketplace, $getBrowseNodesRequestContent, string $contentType = self::contentTypes['getBrowseNodes'][0]) { list($response) = $this->getBrowseNodesWithHttpInfo($xMarketplace, $getBrowseNodesRequestContent, $contentType); return $response; } /** * Operation getBrowseNodesWithHttpInfo * * @param string $xMarketplace Target Amazon Locale. Type: String Default Value: None Example: 'www.amazon.com' (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetBrowseNodesRequestContent $getBrowseNodesRequestContent (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getBrowseNodes'] to see the possible values for this operation * * @throws \Amazon\CreatorsAPI\v1\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return array of \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetBrowseNodesResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ThrottleExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent, HTTP status code, HTTP response headers (array of strings) */ public function getBrowseNodesWithHttpInfo($xMarketplace, $getBrowseNodesRequestContent, string $contentType = self::contentTypes['getBrowseNodes'][0]) { $request = $this->getBrowseNodesRequest($xMarketplace, $getBrowseNodesRequestContent, $contentType); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? (string) $e->getResponse()->getBody() : null ); } catch (ConnectException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), null, null ); } $statusCode = $response->getStatusCode(); switch($statusCode) { case 200: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetBrowseNodesResponseContent', $request, $response, ); case 400: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent', $request, $response, ); case 401: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent', $request, $response, ); case 403: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent', $request, $response, ); case 404: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent', $request, $response, ); case 429: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ThrottleExceptionResponseContent', $request, $response, ); case 500: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent', $request, $response, ); } if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, (string) $request->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetBrowseNodesResponseContent', $request, $response, ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetBrowseNodesResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 400: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 401: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 403: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 404: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 429: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ThrottleExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 500: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; } throw $e; } } /** * Operation getBrowseNodesAsync * * @param string $xMarketplace Target Amazon Locale. Type: String Default Value: None Example: 'www.amazon.com' (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetBrowseNodesRequestContent $getBrowseNodesRequestContent (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getBrowseNodes'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getBrowseNodesAsync($xMarketplace, $getBrowseNodesRequestContent, string $contentType = self::contentTypes['getBrowseNodes'][0]) { return $this->getBrowseNodesAsyncWithHttpInfo($xMarketplace, $getBrowseNodesRequestContent, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation getBrowseNodesAsyncWithHttpInfo * * @param string $xMarketplace Target Amazon Locale. Type: String Default Value: None Example: 'www.amazon.com' (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetBrowseNodesRequestContent $getBrowseNodesRequestContent (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getBrowseNodes'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getBrowseNodesAsyncWithHttpInfo($xMarketplace, $getBrowseNodesRequestContent, string $contentType = self::contentTypes['getBrowseNodes'][0]) { $returnType = '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetBrowseNodesResponseContent'; $request = $this->getBrowseNodesRequest($xMarketplace, $getBrowseNodesRequestContent, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } ); } /** * Create request for operation 'getBrowseNodes' * * @param string $xMarketplace Target Amazon Locale. Type: String Default Value: None Example: 'www.amazon.com' (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetBrowseNodesRequestContent $getBrowseNodesRequestContent (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getBrowseNodes'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function getBrowseNodesRequest($xMarketplace, $getBrowseNodesRequestContent, string $contentType = self::contentTypes['getBrowseNodes'][0]) { // verify the required parameter 'xMarketplace' is set if ($xMarketplace === null || (is_array($xMarketplace) && count($xMarketplace) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $xMarketplace when calling getBrowseNodes' ); } if (strlen($xMarketplace) > 1000) { throw new \InvalidArgumentException('invalid length for "$xMarketplace" when calling DefaultApi.getBrowseNodes, must be smaller than or equal to 1000.'); } if (!preg_match("/.*\\S.*/", $xMarketplace)) { throw new \InvalidArgumentException("invalid value for \"xMarketplace\" when calling DefaultApi.getBrowseNodes, must conform to the pattern /.*\\S.*/."); } // verify the required parameter 'getBrowseNodesRequestContent' is set if ($getBrowseNodesRequestContent === null || (is_array($getBrowseNodesRequestContent) && count($getBrowseNodesRequestContent) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $getBrowseNodesRequestContent when calling getBrowseNodes' ); } $resourcePath = '/catalog/v1/getBrowseNodes'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // header params if ($xMarketplace !== null) { $headerParams['x-marketplace'] = ObjectSerializer::toHeaderValue($xMarketplace); } $headers = $this->headerSelector->selectHeaders( ['application/json', ], $contentType, $multipart ); // Build OAuth2 and custom headers $authenticatedHeaders = $this->buildAuthenticatedHeaders($resourcePath); // for model (json/xml) if (isset($getBrowseNodesRequestContent)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($getBrowseNodesRequestContent)); } else { $httpBody = $getBrowseNodesRequestContent; } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; foreach ($formParamValueItems as $formParamValueItem) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValueItem ]; } } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters $httpBody = json_encode($formParams); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); } } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers, $authenticatedHeaders ); $operationHost = $this->config->getHost(); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'POST', $operationHost . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Operation getFeed * * @param string $xMarketplace Target Amazon Locale. (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetFeedRequestContent $getFeedRequestContent getFeedRequestContent (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getFeed'] to see the possible values for this operation * * @throws \Amazon\CreatorsAPI\v1\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetFeedResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent */ public function getFeed($xMarketplace, $getFeedRequestContent, string $contentType = self::contentTypes['getFeed'][0]) { list($response) = $this->getFeedWithHttpInfo($xMarketplace, $getFeedRequestContent, $contentType); return $response; } /** * Operation getFeedWithHttpInfo * * @param string $xMarketplace Target Amazon Locale. (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetFeedRequestContent $getFeedRequestContent (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getFeed'] to see the possible values for this operation * * @throws \Amazon\CreatorsAPI\v1\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return array of \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetFeedResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent, HTTP status code, HTTP response headers (array of strings) */ public function getFeedWithHttpInfo($xMarketplace, $getFeedRequestContent, string $contentType = self::contentTypes['getFeed'][0]) { $request = $this->getFeedRequest($xMarketplace, $getFeedRequestContent, $contentType); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? (string) $e->getResponse()->getBody() : null ); } catch (ConnectException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), null, null ); } $statusCode = $response->getStatusCode(); switch($statusCode) { case 200: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetFeedResponseContent', $request, $response, ); case 400: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent', $request, $response, ); case 401: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent', $request, $response, ); case 403: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent', $request, $response, ); case 404: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent', $request, $response, ); case 500: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent', $request, $response, ); } if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, (string) $request->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetFeedResponseContent', $request, $response, ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetFeedResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 400: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 401: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 403: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 404: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 500: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; } throw $e; } } /** * Operation getFeedAsync * * @param string $xMarketplace Target Amazon Locale. (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetFeedRequestContent $getFeedRequestContent (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getFeed'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getFeedAsync($xMarketplace, $getFeedRequestContent, string $contentType = self::contentTypes['getFeed'][0]) { return $this->getFeedAsyncWithHttpInfo($xMarketplace, $getFeedRequestContent, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation getFeedAsyncWithHttpInfo * * @param string $xMarketplace Target Amazon Locale. (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetFeedRequestContent $getFeedRequestContent (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getFeed'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getFeedAsyncWithHttpInfo($xMarketplace, $getFeedRequestContent, string $contentType = self::contentTypes['getFeed'][0]) { $returnType = '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetFeedResponseContent'; $request = $this->getFeedRequest($xMarketplace, $getFeedRequestContent, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } ); } /** * Create request for operation 'getFeed' * * @param string $xMarketplace Target Amazon Locale. (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetFeedRequestContent $getFeedRequestContent (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getFeed'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function getFeedRequest($xMarketplace, $getFeedRequestContent, string $contentType = self::contentTypes['getFeed'][0]) { // verify the required parameter 'xMarketplace' is set if ($xMarketplace === null || (is_array($xMarketplace) && count($xMarketplace) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $xMarketplace when calling getFeed' ); } if (strlen($xMarketplace) > 1000) { throw new \InvalidArgumentException('invalid length for "$xMarketplace" when calling DefaultApi.getFeed, must be smaller than or equal to 1000.'); } if (!preg_match("/.*\\S.*/", $xMarketplace)) { throw new \InvalidArgumentException("invalid value for \"xMarketplace\" when calling DefaultApi.getFeed, must conform to the pattern /.*\\S.*/."); } // verify the required parameter 'getFeedRequestContent' is set if ($getFeedRequestContent === null || (is_array($getFeedRequestContent) && count($getFeedRequestContent) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $getFeedRequestContent when calling getFeed' ); } $resourcePath = '/catalog/v1/getFeed'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // header params if ($xMarketplace !== null) { $headerParams['x-marketplace'] = ObjectSerializer::toHeaderValue($xMarketplace); } $headers = $this->headerSelector->selectHeaders( ['application/json', ], $contentType, $multipart ); // Build OAuth2 and custom headers $authenticatedHeaders = $this->buildAuthenticatedHeaders($resourcePath); // for model (json/xml) if (isset($getFeedRequestContent)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($getFeedRequestContent)); } else { $httpBody = $getFeedRequestContent; } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; foreach ($formParamValueItems as $formParamValueItem) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValueItem ]; } } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters $httpBody = json_encode($formParams); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); } } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers, $authenticatedHeaders ); $operationHost = $this->config->getHost(); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'POST', $operationHost . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Operation getItems * * @param string $xMarketplace Target Amazon Locale. (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetItemsRequestContent $getItemsRequestContent getItemsRequestContent (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getItems'] to see the possible values for this operation * * @throws \Amazon\CreatorsAPI\v1\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetItemsResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ThrottleExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent */ public function getItems($xMarketplace, $getItemsRequestContent, string $contentType = self::contentTypes['getItems'][0]) { list($response) = $this->getItemsWithHttpInfo($xMarketplace, $getItemsRequestContent, $contentType); return $response; } /** * Operation getItemsWithHttpInfo * * @param string $xMarketplace Target Amazon Locale. (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetItemsRequestContent $getItemsRequestContent (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getItems'] to see the possible values for this operation * * @throws \Amazon\CreatorsAPI\v1\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return array of \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetItemsResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ThrottleExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent, HTTP status code, HTTP response headers (array of strings) */ public function getItemsWithHttpInfo($xMarketplace, $getItemsRequestContent, string $contentType = self::contentTypes['getItems'][0]) { $request = $this->getItemsRequest($xMarketplace, $getItemsRequestContent, $contentType); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? (string) $e->getResponse()->getBody() : null ); } catch (ConnectException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), null, null ); } $statusCode = $response->getStatusCode(); switch($statusCode) { case 200: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetItemsResponseContent', $request, $response, ); case 400: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent', $request, $response, ); case 401: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent', $request, $response, ); case 403: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent', $request, $response, ); case 404: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent', $request, $response, ); case 429: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ThrottleExceptionResponseContent', $request, $response, ); case 500: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent', $request, $response, ); } if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, (string) $request->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetItemsResponseContent', $request, $response, ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetItemsResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 400: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 401: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 403: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 404: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 429: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ThrottleExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 500: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; } throw $e; } } /** * Operation getItemsAsync * * @param string $xMarketplace Target Amazon Locale. (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetItemsRequestContent $getItemsRequestContent (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getItems'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getItemsAsync($xMarketplace, $getItemsRequestContent, string $contentType = self::contentTypes['getItems'][0]) { return $this->getItemsAsyncWithHttpInfo($xMarketplace, $getItemsRequestContent, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation getItemsAsyncWithHttpInfo * * @param string $xMarketplace Target Amazon Locale. (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetItemsRequestContent $getItemsRequestContent (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getItems'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getItemsAsyncWithHttpInfo($xMarketplace, $getItemsRequestContent, string $contentType = self::contentTypes['getItems'][0]) { $returnType = '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetItemsResponseContent'; $request = $this->getItemsRequest($xMarketplace, $getItemsRequestContent, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } ); } /** * Create request for operation 'getItems' * * @param string $xMarketplace Target Amazon Locale. (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetItemsRequestContent $getItemsRequestContent (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getItems'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function getItemsRequest($xMarketplace, $getItemsRequestContent, string $contentType = self::contentTypes['getItems'][0]) { // verify the required parameter 'xMarketplace' is set if ($xMarketplace === null || (is_array($xMarketplace) && count($xMarketplace) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $xMarketplace when calling getItems' ); } if (strlen($xMarketplace) > 1000) { throw new \InvalidArgumentException('invalid length for "$xMarketplace" when calling DefaultApi.getItems, must be smaller than or equal to 1000.'); } if (!preg_match("/.*\\S.*/", $xMarketplace)) { throw new \InvalidArgumentException("invalid value for \"xMarketplace\" when calling DefaultApi.getItems, must conform to the pattern /.*\\S.*/."); } // verify the required parameter 'getItemsRequestContent' is set if ($getItemsRequestContent === null || (is_array($getItemsRequestContent) && count($getItemsRequestContent) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $getItemsRequestContent when calling getItems' ); } $resourcePath = '/catalog/v1/getItems'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // header params if ($xMarketplace !== null) { $headerParams['x-marketplace'] = ObjectSerializer::toHeaderValue($xMarketplace); } $headers = $this->headerSelector->selectHeaders( ['application/json', ], $contentType, $multipart ); // Build OAuth2 and custom headers $authenticatedHeaders = $this->buildAuthenticatedHeaders($resourcePath); // for model (json/xml) if (isset($getItemsRequestContent)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($getItemsRequestContent)); } else { $httpBody = $getItemsRequestContent; } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; foreach ($formParamValueItems as $formParamValueItem) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValueItem ]; } } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters $httpBody = json_encode($formParams); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); } } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers, $authenticatedHeaders ); $operationHost = $this->config->getHost(); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'POST', $operationHost . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Operation getVariations * * @param string $xMarketplace Target Amazon Locale. This specifies the marketplace where the items should be searched. Example: 'www.amazon.com' (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetVariationsRequestContent $getVariationsRequestContent getVariationsRequestContent (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getVariations'] to see the possible values for this operation * * @throws \Amazon\CreatorsAPI\v1\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetVariationsResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ThrottleExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent */ public function getVariations($xMarketplace, $getVariationsRequestContent, string $contentType = self::contentTypes['getVariations'][0]) { list($response) = $this->getVariationsWithHttpInfo($xMarketplace, $getVariationsRequestContent, $contentType); return $response; } /** * Operation getVariationsWithHttpInfo * * @param string $xMarketplace Target Amazon Locale. This specifies the marketplace where the items should be searched. Example: 'www.amazon.com' (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetVariationsRequestContent $getVariationsRequestContent (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getVariations'] to see the possible values for this operation * * @throws \Amazon\CreatorsAPI\v1\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return array of \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetVariationsResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ThrottleExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent, HTTP status code, HTTP response headers (array of strings) */ public function getVariationsWithHttpInfo($xMarketplace, $getVariationsRequestContent, string $contentType = self::contentTypes['getVariations'][0]) { $request = $this->getVariationsRequest($xMarketplace, $getVariationsRequestContent, $contentType); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? (string) $e->getResponse()->getBody() : null ); } catch (ConnectException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), null, null ); } $statusCode = $response->getStatusCode(); switch($statusCode) { case 200: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetVariationsResponseContent', $request, $response, ); case 400: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent', $request, $response, ); case 401: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent', $request, $response, ); case 403: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent', $request, $response, ); case 404: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent', $request, $response, ); case 429: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ThrottleExceptionResponseContent', $request, $response, ); case 500: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent', $request, $response, ); } if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, (string) $request->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetVariationsResponseContent', $request, $response, ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetVariationsResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 400: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 401: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 403: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 404: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 429: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ThrottleExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 500: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; } throw $e; } } /** * Operation getVariationsAsync * * @param string $xMarketplace Target Amazon Locale. This specifies the marketplace where the items should be searched. Example: 'www.amazon.com' (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetVariationsRequestContent $getVariationsRequestContent (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getVariations'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getVariationsAsync($xMarketplace, $getVariationsRequestContent, string $contentType = self::contentTypes['getVariations'][0]) { return $this->getVariationsAsyncWithHttpInfo($xMarketplace, $getVariationsRequestContent, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation getVariationsAsyncWithHttpInfo * * @param string $xMarketplace Target Amazon Locale. This specifies the marketplace where the items should be searched. Example: 'www.amazon.com' (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetVariationsRequestContent $getVariationsRequestContent (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getVariations'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getVariationsAsyncWithHttpInfo($xMarketplace, $getVariationsRequestContent, string $contentType = self::contentTypes['getVariations'][0]) { $returnType = '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetVariationsResponseContent'; $request = $this->getVariationsRequest($xMarketplace, $getVariationsRequestContent, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } ); } /** * Create request for operation 'getVariations' * * @param string $xMarketplace Target Amazon Locale. This specifies the marketplace where the items should be searched. Example: 'www.amazon.com' (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\GetVariationsRequestContent $getVariationsRequestContent (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['getVariations'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function getVariationsRequest($xMarketplace, $getVariationsRequestContent, string $contentType = self::contentTypes['getVariations'][0]) { // verify the required parameter 'xMarketplace' is set if ($xMarketplace === null || (is_array($xMarketplace) && count($xMarketplace) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $xMarketplace when calling getVariations' ); } if (strlen($xMarketplace) > 1000) { throw new \InvalidArgumentException('invalid length for "$xMarketplace" when calling DefaultApi.getVariations, must be smaller than or equal to 1000.'); } if (!preg_match("/.*\\S.*/", $xMarketplace)) { throw new \InvalidArgumentException("invalid value for \"xMarketplace\" when calling DefaultApi.getVariations, must conform to the pattern /.*\\S.*/."); } // verify the required parameter 'getVariationsRequestContent' is set if ($getVariationsRequestContent === null || (is_array($getVariationsRequestContent) && count($getVariationsRequestContent) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $getVariationsRequestContent when calling getVariations' ); } $resourcePath = '/catalog/v1/getVariations'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // header params if ($xMarketplace !== null) { $headerParams['x-marketplace'] = ObjectSerializer::toHeaderValue($xMarketplace); } $headers = $this->headerSelector->selectHeaders( ['application/json', ], $contentType, $multipart ); // Build OAuth2 and custom headers $authenticatedHeaders = $this->buildAuthenticatedHeaders($resourcePath); // for model (json/xml) if (isset($getVariationsRequestContent)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($getVariationsRequestContent)); } else { $httpBody = $getVariationsRequestContent; } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; foreach ($formParamValueItems as $formParamValueItem) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValueItem ]; } } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters $httpBody = json_encode($formParams); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); } } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers, $authenticatedHeaders ); $operationHost = $this->config->getHost(); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'POST', $operationHost . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Operation listFeeds * * @param string $xMarketplace Target Amazon Locale. (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['listFeeds'] to see the possible values for this operation * * @throws \Amazon\CreatorsAPI\v1\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return \Amazon\CreatorsAPI\v1\com\amazon\creators\model\ListFeedsResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent */ public function listFeeds($xMarketplace, string $contentType = self::contentTypes['listFeeds'][0]) { list($response) = $this->listFeedsWithHttpInfo($xMarketplace, $contentType); return $response; } /** * Operation listFeedsWithHttpInfo * * @param string $xMarketplace Target Amazon Locale. (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['listFeeds'] to see the possible values for this operation * * @throws \Amazon\CreatorsAPI\v1\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return array of \Amazon\CreatorsAPI\v1\com\amazon\creators\model\ListFeedsResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent, HTTP status code, HTTP response headers (array of strings) */ public function listFeedsWithHttpInfo($xMarketplace, string $contentType = self::contentTypes['listFeeds'][0]) { $request = $this->listFeedsRequest($xMarketplace, $contentType); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? (string) $e->getResponse()->getBody() : null ); } catch (ConnectException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), null, null ); } $statusCode = $response->getStatusCode(); switch($statusCode) { case 200: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ListFeedsResponseContent', $request, $response, ); case 400: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent', $request, $response, ); case 401: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent', $request, $response, ); case 403: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent', $request, $response, ); case 404: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent', $request, $response, ); case 500: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent', $request, $response, ); } if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, (string) $request->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ListFeedsResponseContent', $request, $response, ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ListFeedsResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 400: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 401: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 403: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 404: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 500: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; } throw $e; } } /** * Operation listFeedsAsync * * @param string $xMarketplace Target Amazon Locale. (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['listFeeds'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function listFeedsAsync($xMarketplace, string $contentType = self::contentTypes['listFeeds'][0]) { return $this->listFeedsAsyncWithHttpInfo($xMarketplace, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation listFeedsAsyncWithHttpInfo * * @param string $xMarketplace Target Amazon Locale. (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['listFeeds'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function listFeedsAsyncWithHttpInfo($xMarketplace, string $contentType = self::contentTypes['listFeeds'][0]) { $returnType = '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ListFeedsResponseContent'; $request = $this->listFeedsRequest($xMarketplace, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } ); } /** * Create request for operation 'listFeeds' * * @param string $xMarketplace Target Amazon Locale. (required) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['listFeeds'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function listFeedsRequest($xMarketplace, string $contentType = self::contentTypes['listFeeds'][0]) { // verify the required parameter 'xMarketplace' is set if ($xMarketplace === null || (is_array($xMarketplace) && count($xMarketplace) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $xMarketplace when calling listFeeds' ); } if (strlen($xMarketplace) > 1000) { throw new \InvalidArgumentException('invalid length for "$xMarketplace" when calling DefaultApi.listFeeds, must be smaller than or equal to 1000.'); } if (!preg_match("/.*\\S.*/", $xMarketplace)) { throw new \InvalidArgumentException("invalid value for \"xMarketplace\" when calling DefaultApi.listFeeds, must conform to the pattern /.*\\S.*/."); } $resourcePath = '/catalog/v1/listFeeds'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // header params if ($xMarketplace !== null) { $headerParams['x-marketplace'] = ObjectSerializer::toHeaderValue($xMarketplace); } $headers = $this->headerSelector->selectHeaders( ['application/json', ], $contentType, $multipart ); // Build OAuth2 and custom headers $authenticatedHeaders = $this->buildAuthenticatedHeaders($resourcePath); // for model (json/xml) if (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; foreach ($formParamValueItems as $formParamValueItem) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValueItem ]; } } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters $httpBody = json_encode($formParams); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); } } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers, $authenticatedHeaders ); $operationHost = $this->config->getHost(); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'POST', $operationHost . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Operation searchItems * * @param string $xMarketplace Target Amazon Locale. (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\SearchItemsRequestContent|null $searchItemsRequestContent searchItemsRequestContent (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['searchItems'] to see the possible values for this operation * * @throws \Amazon\CreatorsAPI\v1\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return \Amazon\CreatorsAPI\v1\com\amazon\creators\model\SearchItemsResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ThrottleExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent */ public function searchItems($xMarketplace, $searchItemsRequestContent = null, string $contentType = self::contentTypes['searchItems'][0]) { list($response) = $this->searchItemsWithHttpInfo($xMarketplace, $searchItemsRequestContent, $contentType); return $response; } /** * Operation searchItemsWithHttpInfo * * @param string $xMarketplace Target Amazon Locale. (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\SearchItemsRequestContent|null $searchItemsRequestContent (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['searchItems'] to see the possible values for this operation * * @throws \Amazon\CreatorsAPI\v1\ApiException on non-2xx response or if the response body is not in the expected format * @throws \InvalidArgumentException * @return array of \Amazon\CreatorsAPI\v1\com\amazon\creators\model\SearchItemsResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ThrottleExceptionResponseContent|\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent, HTTP status code, HTTP response headers (array of strings) */ public function searchItemsWithHttpInfo($xMarketplace, $searchItemsRequestContent = null, string $contentType = self::contentTypes['searchItems'][0]) { $request = $this->searchItemsRequest($xMarketplace, $searchItemsRequestContent, $contentType); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? (string) $e->getResponse()->getBody() : null ); } catch (ConnectException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), null, null ); } $statusCode = $response->getStatusCode(); switch($statusCode) { case 200: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\SearchItemsResponseContent', $request, $response, ); case 400: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent', $request, $response, ); case 401: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent', $request, $response, ); case 403: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent', $request, $response, ); case 404: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent', $request, $response, ); case 429: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ThrottleExceptionResponseContent', $request, $response, ); case 500: return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent', $request, $response, ); } if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, (string) $request->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } return $this->handleResponseWithDataType( '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\SearchItemsResponseContent', $request, $response, ); } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\SearchItemsResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 400: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ValidationExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 401: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\UnauthorizedExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 403: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\AccessDeniedExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 404: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ResourceNotFoundExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 429: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\ThrottleExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; case 500: $data = ObjectSerializer::deserialize( $e->getResponseBody(), '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\InternalServerExceptionResponseContent', $e->getResponseHeaders() ); $e->setResponseObject($data); throw $e; } throw $e; } } /** * Operation searchItemsAsync * * @param string $xMarketplace Target Amazon Locale. (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\SearchItemsRequestContent|null $searchItemsRequestContent (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['searchItems'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function searchItemsAsync($xMarketplace, $searchItemsRequestContent = null, string $contentType = self::contentTypes['searchItems'][0]) { return $this->searchItemsAsyncWithHttpInfo($xMarketplace, $searchItemsRequestContent, $contentType) ->then( function ($response) { return $response[0]; } ); } /** * Operation searchItemsAsyncWithHttpInfo * * @param string $xMarketplace Target Amazon Locale. (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\SearchItemsRequestContent|null $searchItemsRequestContent (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['searchItems'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function searchItemsAsyncWithHttpInfo($xMarketplace, $searchItemsRequestContent = null, string $contentType = self::contentTypes['searchItems'][0]) { $returnType = '\Amazon\CreatorsAPI\v1\com\amazon\creators\model\SearchItemsResponseContent'; $request = $this->searchItemsRequest($xMarketplace, $searchItemsRequestContent, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { if ($returnType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize($content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), (string) $response->getBody() ); } ); } /** * Create request for operation 'searchItems' * * @param string $xMarketplace Target Amazon Locale. (required) * @param \Amazon\CreatorsAPI\v1\com\amazon\creators\model\SearchItemsRequestContent|null $searchItemsRequestContent (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['searchItems'] to see the possible values for this operation * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function searchItemsRequest($xMarketplace, $searchItemsRequestContent = null, string $contentType = self::contentTypes['searchItems'][0]) { // verify the required parameter 'xMarketplace' is set if ($xMarketplace === null || (is_array($xMarketplace) && count($xMarketplace) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $xMarketplace when calling searchItems' ); } if (strlen($xMarketplace) > 1000) { throw new \InvalidArgumentException('invalid length for "$xMarketplace" when calling DefaultApi.searchItems, must be smaller than or equal to 1000.'); } if (!preg_match("/.*\\S.*/", $xMarketplace)) { throw new \InvalidArgumentException("invalid value for \"xMarketplace\" when calling DefaultApi.searchItems, must conform to the pattern /.*\\S.*/."); } $resourcePath = '/catalog/v1/searchItems'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // header params if ($xMarketplace !== null) { $headerParams['x-marketplace'] = ObjectSerializer::toHeaderValue($xMarketplace); } $headers = $this->headerSelector->selectHeaders( ['application/json', ], $contentType, $multipart ); // Build OAuth2 and custom headers $authenticatedHeaders = $this->buildAuthenticatedHeaders($resourcePath); // for model (json/xml) if (isset($searchItemsRequestContent)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($searchItemsRequestContent)); } else { $httpBody = $searchItemsRequestContent; } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; foreach ($formParamValueItems as $formParamValueItem) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValueItem ]; } } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters $httpBody = json_encode($formParams); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); } } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers, $authenticatedHeaders ); $operationHost = $this->config->getHost(); $query = ObjectSerializer::buildQuery($queryParams); return new Request( 'POST', $operationHost . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Create http client option * * @throws \RuntimeException on file opening failure * @return array of http client options */ protected function createHttpClientOption() { $options = []; if ($this->config->getDebug()) { $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a'); if (!$options[RequestOptions::DEBUG]) { throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile()); } } return $options; } private function handleResponseWithDataType( string $dataType, RequestInterface $request, ResponseInterface $response ): array { if ($dataType === '\SplFileObject') { $content = $response->getBody(); //stream goes to serializer } else { $content = (string) $response->getBody(); if ($dataType !== 'string') { try { $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR); } catch (\JsonException $exception) { throw new ApiException( sprintf( 'Error JSON decoding server response (%s)', $request->getUri() ), $response->getStatusCode(), $response->getHeaders(), $content ); } } } return [ ObjectSerializer::deserialize($content, $dataType, []), $response->getStatusCode(), $response->getHeaders() ]; } private function responseWithinRangeCode( string $rangeCode, int $statusCode ): bool { $left = (int) ($rangeCode[0].'00'); $right = (int) ($rangeCode[0].'99'); return $statusCode >= $left && $statusCode <= $right; } }