diff --git a/CHANGELOG.md b/CHANGELOG.md index 3962400..be145e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- Added `deal_id` query parameter to the GET `/v2/persons` endpoint ### Fixed <<<<<<< HEAD - Prepared `nullable: true` to fields that can return null values in schemas for Field and Roles schemas diff --git a/docs/versions/v2/Api/PersonsApi.md b/docs/versions/v2/Api/PersonsApi.md index 8481b0a..847a638 100644 --- a/docs/versions/v2/Api/PersonsApi.md +++ b/docs/versions/v2/Api/PersonsApi.md @@ -490,7 +490,7 @@ Name | Type | Description | Notes ## `getPersons()` ```php -getPersons($filter_id, $ids, $owner_id, $org_id, $updated_since, $updated_until, $sort_by, $sort_direction, $include_fields, $custom_fields, $limit, $cursor): \Pipedrive\versions\v2\Model\GetPersons +getPersons($filter_id, $ids, $owner_id, $org_id, $deal_id, $updated_since, $updated_until, $sort_by, $sort_direction, $include_fields, $custom_fields, $limit, $cursor): \Pipedrive\versions\v2\Model\GetPersons ``` Get all persons @@ -523,6 +523,7 @@ $filter_id = 56; // int | If supplied, only persons matching the specified filte $ids = 'ids_example'; // string | Optional comma separated string array of up to 100 entity ids to fetch. If filter_id is provided, this is ignored. If any of the requested entities do not exist or are not visible, they are not included in the response. $owner_id = 56; // int | If supplied, only persons owned by the specified user are returned. If filter_id is provided, this is ignored. $org_id = 56; // int | If supplied, only persons linked to the specified organization are returned. If filter_id is provided, this is ignored. +$deal_id = 56; // int | If supplied, only persons linked to the specified deal are returned. If filter_id is provided, this is ignored. $updated_since = 'updated_since_example'; // string | If set, only persons with an `update_time` later than or equal to this time are returned. In RFC3339 format, e.g. 2025-01-01T10:20:00Z. $updated_until = 'updated_until_example'; // string | If set, only persons with an `update_time` earlier than this time are returned. In RFC3339 format, e.g. 2025-01-01T10:20:00Z. $sort_by = 'id'; // string | The field to sort by. Supported fields: `id`, `update_time`, `add_time`. @@ -533,7 +534,7 @@ $limit = 100; // int | For pagination, the limit of entries to be returned. If n $cursor = 'cursor_example'; // string | For pagination, the marker (an opaque string value) representing the first item on the next page try { - $result = $apiInstance->getPersons($filter_id, $ids, $owner_id, $org_id, $updated_since, $updated_until, $sort_by, $sort_direction, $include_fields, $custom_fields, $limit, $cursor); + $result = $apiInstance->getPersons($filter_id, $ids, $owner_id, $org_id, $deal_id, $updated_since, $updated_until, $sort_by, $sort_direction, $include_fields, $custom_fields, $limit, $cursor); print_r($result); } catch (Exception $e) { echo 'Exception when calling PersonsApi->getPersons: ', $e->getMessage(), PHP_EOL; @@ -548,6 +549,7 @@ Name | Type | Description | Notes **ids** | **string**| Optional comma separated string array of up to 100 entity ids to fetch. If filter_id is provided, this is ignored. If any of the requested entities do not exist or are not visible, they are not included in the response. | [optional] **owner_id** | **int**| If supplied, only persons owned by the specified user are returned. If filter_id is provided, this is ignored. | [optional] **org_id** | **int**| If supplied, only persons linked to the specified organization are returned. If filter_id is provided, this is ignored. | [optional] + **deal_id** | **int**| If supplied, only persons linked to the specified deal are returned. If filter_id is provided, this is ignored. | [optional] **updated_since** | **string**| If set, only persons with an `update_time` later than or equal to this time are returned. In RFC3339 format, e.g. 2025-01-01T10:20:00Z. | [optional] **updated_until** | **string**| If set, only persons with an `update_time` earlier than this time are returned. In RFC3339 format, e.g. 2025-01-01T10:20:00Z. | [optional] **sort_by** | **string**| The field to sort by. Supported fields: `id`, `update_time`, `add_time`. | [optional] [default to 'id'] diff --git a/docs/versions/v2/Api/ProductsApi.md b/docs/versions/v2/Api/ProductsApi.md index c907246..62a663c 100644 --- a/docs/versions/v2/Api/ProductsApi.md +++ b/docs/versions/v2/Api/ProductsApi.md @@ -11,6 +11,7 @@ Method | HTTP request | Description [**deleteProductFollower()**](ProductsApi.md#deleteProductFollower) | **DELETE** /products/{id}/followers/{follower_id} | Delete a follower from a product [**deleteProductImage()**](ProductsApi.md#deleteProductImage) | **DELETE** /products/{id}/images | Delete an image of a product [**deleteProductVariation()**](ProductsApi.md#deleteProductVariation) | **DELETE** /products/{id}/variations/{product_variation_id} | Delete a product variation +[**duplicateProduct()**](ProductsApi.md#duplicateProduct) | **POST** /products/{id}/duplicate | Duplicate a product [**getProduct()**](ProductsApi.md#getProduct) | **GET** /products/{id} | Get one product [**getProductFollowers()**](ProductsApi.md#getProductFollowers) | **GET** /products/{id}/followers | List followers of a product [**getProductFollowersChangelog()**](ProductsApi.md#getProductFollowersChangelog) | **GET** /products/{id}/followers/changelog | List followers changelog of a product @@ -487,6 +488,71 @@ Name | Type | Description | Notes [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) +## `duplicateProduct()` + +```php +duplicateProduct($id): \Pipedrive\versions\v2\Model\ProductResponse +``` + +Duplicate a product + +Creates a duplicate of an existing product including all variations, prices, and custom fields. + +### Example + +```php +setApiKey('x-api-token', 'YOUR_API_KEY'); +// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed +// $config = (new Pipedrive\versions\v2\Configuration())->setApiKeyPrefix('x-api-token', 'Bearer'); + +// Configure OAuth2 access token for authorization: oauth2 +$config = (new Pipedrive\versions\v2\Configuration())->setAccessToken('YOUR_ACCESS_TOKEN'); + + +$apiInstance = new Pipedrive\versions\v2\Api\ProductsApi( + // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`. + // This is optional, `GuzzleHttp\Client` will be used as default. + new GuzzleHttp\Client(), + $config +); +$id = 56; // int | The ID of the product + +try { + $result = $apiInstance->duplicateProduct($id); + print_r($result); +} catch (Exception $e) { + echo 'Exception when calling ProductsApi->duplicateProduct: ', $e->getMessage(), PHP_EOL; +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **id** | **int**| The ID of the product | + +### Return type + +[**\Pipedrive\versions\v2\Model\ProductResponse**](../Model/ProductResponse.md) + +### Authorization + +[api_key](../README.md#api_key), [oauth2](../README.md#oauth2) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: `application/json` + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) +[[Back to Model list]](../README.md#documentation-for-models) +[[Back to README]](../README.md) + ## `getProduct()` ```php diff --git a/docs/versions/v2/README.md b/docs/versions/v2/README.md index aca516b..b04ddf4 100644 --- a/docs/versions/v2/README.md +++ b/docs/versions/v2/README.md @@ -347,6 +347,7 @@ Class | Method | HTTP request | Description *ProductsApi* | [**deleteProductFollower**](Api/ProductsApi.md#deleteproductfollower) | **DELETE** /products/{id}/followers/{follower_id} | Delete a follower from a product *ProductsApi* | [**deleteProductImage**](Api/ProductsApi.md#deleteproductimage) | **DELETE** /products/{id}/images | Delete an image of a product *ProductsApi* | [**deleteProductVariation**](Api/ProductsApi.md#deleteproductvariation) | **DELETE** /products/{id}/variations/{product_variation_id} | Delete a product variation +*ProductsApi* | [**duplicateProduct**](Api/ProductsApi.md#duplicateproduct) | **POST** /products/{id}/duplicate | Duplicate a product *ProductsApi* | [**getProduct**](Api/ProductsApi.md#getproduct) | **GET** /products/{id} | Get one product *ProductsApi* | [**getProductFollowers**](Api/ProductsApi.md#getproductfollowers) | **GET** /products/{id}/followers | List followers of a product *ProductsApi* | [**getProductFollowersChangelog**](Api/ProductsApi.md#getproductfollowerschangelog) | **GET** /products/{id}/followers/changelog | List followers changelog of a product diff --git a/lib/versions/v2/Api/PersonsApi.php b/lib/versions/v2/Api/PersonsApi.php index 03d4bc8..575157e 100644 --- a/lib/versions/v2/Api/PersonsApi.php +++ b/lib/versions/v2/Api/PersonsApi.php @@ -2303,6 +2303,7 @@ public function getPersonFollowersChangelogRequest($id, $limit = null, $cursor = * @param string|null $ids Optional comma separated string array of up to 100 entity ids to fetch. If filter_id is provided, this is ignored. If any of the requested entities do not exist or are not visible, they are not included in the response. (optional) * @param int|null $owner_id If supplied, only persons owned by the specified user are returned. If filter_id is provided, this is ignored. (optional) * @param int|null $org_id If supplied, only persons linked to the specified organization are returned. If filter_id is provided, this is ignored. (optional) + * @param int|null $deal_id If supplied, only persons linked to the specified deal are returned. If filter_id is provided, this is ignored. (optional) * @param string|null $updated_since If set, only persons with an `update_time` later than or equal to this time are returned. In RFC3339 format, e.g. 2025-01-01T10:20:00Z. (optional) * @param string|null $updated_until If set, only persons with an `update_time` earlier than this time are returned. In RFC3339 format, e.g. 2025-01-01T10:20:00Z. (optional) * @param string|'id' $sort_by The field to sort by. Supported fields: `id`, `update_time`, `add_time`. (optional, default to 'id') @@ -2316,9 +2317,9 @@ public function getPersonFollowersChangelogRequest($id, $limit = null, $cursor = * @throws InvalidArgumentException|GuzzleException * @return \Pipedrive\versions\v2\Model\GetPersons */ - public function getPersons($filter_id = null, $ids = null, $owner_id = null, $org_id = null, $updated_since = null, $updated_until = null, $sort_by = 'id', $sort_direction = 'asc', $include_fields = null, $custom_fields = null, $limit = null, $cursor = null) + public function getPersons($filter_id = null, $ids = null, $owner_id = null, $org_id = null, $deal_id = null, $updated_since = null, $updated_until = null, $sort_by = 'id', $sort_direction = 'asc', $include_fields = null, $custom_fields = null, $limit = null, $cursor = null) { - list($response) = $this->getPersonsWithHttpInfo($filter_id, $ids, $owner_id, $org_id, $updated_since, $updated_until, $sort_by, $sort_direction, $include_fields, $custom_fields, $limit, $cursor); + list($response) = $this->getPersonsWithHttpInfo($filter_id, $ids, $owner_id, $org_id, $deal_id, $updated_since, $updated_until, $sort_by, $sort_direction, $include_fields, $custom_fields, $limit, $cursor); return $response; } @@ -2331,6 +2332,7 @@ public function getPersons($filter_id = null, $ids = null, $owner_id = null, $or * @param string|null $ids Optional comma separated string array of up to 100 entity ids to fetch. If filter_id is provided, this is ignored. If any of the requested entities do not exist or are not visible, they are not included in the response. (optional) * @param int|null $owner_id If supplied, only persons owned by the specified user are returned. If filter_id is provided, this is ignored. (optional) * @param int|null $org_id If supplied, only persons linked to the specified organization are returned. If filter_id is provided, this is ignored. (optional) + * @param int|null $deal_id If supplied, only persons linked to the specified deal are returned. If filter_id is provided, this is ignored. (optional) * @param string|null $updated_since If set, only persons with an `update_time` later than or equal to this time are returned. In RFC3339 format, e.g. 2025-01-01T10:20:00Z. (optional) * @param string|null $updated_until If set, only persons with an `update_time` earlier than this time are returned. In RFC3339 format, e.g. 2025-01-01T10:20:00Z. (optional) * @param string|'id' $sort_by The field to sort by. Supported fields: `id`, `update_time`, `add_time`. (optional, default to 'id') @@ -2344,9 +2346,9 @@ public function getPersons($filter_id = null, $ids = null, $owner_id = null, $or * @throws InvalidArgumentException|GuzzleException * @return array of \Pipedrive\versions\v2\Model\GetPersons, HTTP status code, HTTP response headers (array of strings) */ - public function getPersonsWithHttpInfo($filter_id = null, $ids = null, $owner_id = null, $org_id = null, $updated_since = null, $updated_until = null, $sort_by = 'id', $sort_direction = 'asc', $include_fields = null, $custom_fields = null, $limit = null, $cursor = null) + public function getPersonsWithHttpInfo($filter_id = null, $ids = null, $owner_id = null, $org_id = null, $deal_id = null, $updated_since = null, $updated_until = null, $sort_by = 'id', $sort_direction = 'asc', $include_fields = null, $custom_fields = null, $limit = null, $cursor = null) { - $request = $this->getPersonsRequest($filter_id, $ids, $owner_id, $org_id, $updated_since, $updated_until, $sort_by, $sort_direction, $include_fields, $custom_fields, $limit, $cursor); + $request = $this->getPersonsRequest($filter_id, $ids, $owner_id, $org_id, $deal_id, $updated_since, $updated_until, $sort_by, $sort_direction, $include_fields, $custom_fields, $limit, $cursor); try { $options = $this->createHttpClientOption(); @@ -2355,7 +2357,7 @@ public function getPersonsWithHttpInfo($filter_id = null, $ids = null, $owner_id } catch (RequestException $e) { if ($e->getCode() === 401 && $this->config->isRefreshPossible()) { $this->config->refreshToken(); - $request = $this->getPersonsRequest($filter_id, $ids, $owner_id, $org_id, $updated_since, $updated_until, $sort_by, $sort_direction, $include_fields, $custom_fields, $limit, $cursor); + $request = $this->getPersonsRequest($filter_id, $ids, $owner_id, $org_id, $deal_id, $updated_since, $updated_until, $sort_by, $sort_direction, $include_fields, $custom_fields, $limit, $cursor); $response = $this->client->send($request, $options); } else { throw new ApiException( @@ -2443,6 +2445,7 @@ public function getPersonsWithHttpInfo($filter_id = null, $ids = null, $owner_id * @param string|null $ids Optional comma separated string array of up to 100 entity ids to fetch. If filter_id is provided, this is ignored. If any of the requested entities do not exist or are not visible, they are not included in the response. (optional) * @param int|null $owner_id If supplied, only persons owned by the specified user are returned. If filter_id is provided, this is ignored. (optional) * @param int|null $org_id If supplied, only persons linked to the specified organization are returned. If filter_id is provided, this is ignored. (optional) + * @param int|null $deal_id If supplied, only persons linked to the specified deal are returned. If filter_id is provided, this is ignored. (optional) * @param string|null $updated_since If set, only persons with an `update_time` later than or equal to this time are returned. In RFC3339 format, e.g. 2025-01-01T10:20:00Z. (optional) * @param string|null $updated_until If set, only persons with an `update_time` earlier than this time are returned. In RFC3339 format, e.g. 2025-01-01T10:20:00Z. (optional) * @param string|'id' $sort_by The field to sort by. Supported fields: `id`, `update_time`, `add_time`. (optional, default to 'id') @@ -2455,9 +2458,9 @@ public function getPersonsWithHttpInfo($filter_id = null, $ids = null, $owner_id * @throws InvalidArgumentException|OAuthProviderException * @return PromiseInterface */ - public function getPersonsAsync($filter_id = null, $ids = null, $owner_id = null, $org_id = null, $updated_since = null, $updated_until = null, $sort_by = 'id', $sort_direction = 'asc', $include_fields = null, $custom_fields = null, $limit = null, $cursor = null): PromiseInterface + public function getPersonsAsync($filter_id = null, $ids = null, $owner_id = null, $org_id = null, $deal_id = null, $updated_since = null, $updated_until = null, $sort_by = 'id', $sort_direction = 'asc', $include_fields = null, $custom_fields = null, $limit = null, $cursor = null): PromiseInterface { - return $this->getPersonsAsyncWithHttpInfo($filter_id, $ids, $owner_id, $org_id, $updated_since, $updated_until, $sort_by, $sort_direction, $include_fields, $custom_fields, $limit, $cursor) + return $this->getPersonsAsyncWithHttpInfo($filter_id, $ids, $owner_id, $org_id, $deal_id, $updated_since, $updated_until, $sort_by, $sort_direction, $include_fields, $custom_fields, $limit, $cursor) ->then( function ($response) { return $response[0]; @@ -2474,6 +2477,7 @@ function ($response) { * @param string|null $ids Optional comma separated string array of up to 100 entity ids to fetch. If filter_id is provided, this is ignored. If any of the requested entities do not exist or are not visible, they are not included in the response. (optional) * @param int|null $owner_id If supplied, only persons owned by the specified user are returned. If filter_id is provided, this is ignored. (optional) * @param int|null $org_id If supplied, only persons linked to the specified organization are returned. If filter_id is provided, this is ignored. (optional) + * @param int|null $deal_id If supplied, only persons linked to the specified deal are returned. If filter_id is provided, this is ignored. (optional) * @param string|null $updated_since If set, only persons with an `update_time` later than or equal to this time are returned. In RFC3339 format, e.g. 2025-01-01T10:20:00Z. (optional) * @param string|null $updated_until If set, only persons with an `update_time` earlier than this time are returned. In RFC3339 format, e.g. 2025-01-01T10:20:00Z. (optional) * @param string|'id' $sort_by The field to sort by. Supported fields: `id`, `update_time`, `add_time`. (optional, default to 'id') @@ -2486,10 +2490,10 @@ function ($response) { * @throws InvalidArgumentException|OAuthProviderException * @return PromiseInterface */ - public function getPersonsAsyncWithHttpInfo($filter_id = null, $ids = null, $owner_id = null, $org_id = null, $updated_since = null, $updated_until = null, $sort_by = 'id', $sort_direction = 'asc', $include_fields = null, $custom_fields = null, $limit = null, $cursor = null): PromiseInterface + public function getPersonsAsyncWithHttpInfo($filter_id = null, $ids = null, $owner_id = null, $org_id = null, $deal_id = null, $updated_since = null, $updated_until = null, $sort_by = 'id', $sort_direction = 'asc', $include_fields = null, $custom_fields = null, $limit = null, $cursor = null): PromiseInterface { $returnType = '\Pipedrive\versions\v2\Model\GetPersons'; - $request = $this->getPersonsRequest($filter_id, $ids, $owner_id, $org_id, $updated_since, $updated_until, $sort_by, $sort_direction, $include_fields, $custom_fields, $limit, $cursor); + $request = $this->getPersonsRequest($filter_id, $ids, $owner_id, $org_id, $deal_id, $updated_since, $updated_until, $sort_by, $sort_direction, $include_fields, $custom_fields, $limit, $cursor); return $this->client ->sendAsync($request, $this->createHttpClientOption()) @@ -2532,6 +2536,7 @@ function ($exception) { * @param string|null $ids Optional comma separated string array of up to 100 entity ids to fetch. If filter_id is provided, this is ignored. If any of the requested entities do not exist or are not visible, they are not included in the response. (optional) * @param int|null $owner_id If supplied, only persons owned by the specified user are returned. If filter_id is provided, this is ignored. (optional) * @param int|null $org_id If supplied, only persons linked to the specified organization are returned. If filter_id is provided, this is ignored. (optional) + * @param int|null $deal_id If supplied, only persons linked to the specified deal are returned. If filter_id is provided, this is ignored. (optional) * @param string|null $updated_since If set, only persons with an `update_time` later than or equal to this time are returned. In RFC3339 format, e.g. 2025-01-01T10:20:00Z. (optional) * @param string|null $updated_until If set, only persons with an `update_time` earlier than this time are returned. In RFC3339 format, e.g. 2025-01-01T10:20:00Z. (optional) * @param string|'id' $sort_by The field to sort by. Supported fields: `id`, `update_time`, `add_time`. (optional, default to 'id') @@ -2544,7 +2549,7 @@ function ($exception) { * @throws InvalidArgumentException|OAuthProviderException * @return Request */ - public function getPersonsRequest($filter_id = null, $ids = null, $owner_id = null, $org_id = null, $updated_since = null, $updated_until = null, $sort_by = 'id', $sort_direction = 'asc', $include_fields = null, $custom_fields = null, $limit = null, $cursor = null): Request + public function getPersonsRequest($filter_id = null, $ids = null, $owner_id = null, $org_id = null, $deal_id = null, $updated_since = null, $updated_until = null, $sort_by = 'id', $sort_direction = 'asc', $include_fields = null, $custom_fields = null, $limit = null, $cursor = null): Request { $resourcePath = '/persons'; @@ -2588,6 +2593,14 @@ public function getPersonsRequest($filter_id = null, $ids = null, $owner_id = nu } // query params /* @phpstan-ignore-next-line */ + if (is_array($deal_id)) { + $deal_id = ObjectSerializer::serializeCollection($deal_id, '', true); + } + if ($deal_id !== null) { + $queryParams['deal_id'] = $deal_id; + } + // query params + /* @phpstan-ignore-next-line */ if (is_array($updated_since)) { $updated_since = ObjectSerializer::serializeCollection($updated_since, '', true); } diff --git a/lib/versions/v2/Api/ProductsApi.php b/lib/versions/v2/Api/ProductsApi.php index 8b1941c..bf85cae 100644 --- a/lib/versions/v2/Api/ProductsApi.php +++ b/lib/versions/v2/Api/ProductsApi.php @@ -2247,6 +2247,302 @@ public function deleteProductVariationRequest($id, $product_variation_id): Reque ); } + /** + * Operation duplicateProduct + * + * Duplicate a product + * + * @param int $id The ID of the product (required) + * + * @throws ApiException on non-2xx response + * @throws InvalidArgumentException|GuzzleException + * @return \Pipedrive\versions\v2\Model\ProductResponse + */ + public function duplicateProduct($id) + { + list($response) = $this->duplicateProductWithHttpInfo($id); + return $response; + } + + /** + * Operation duplicateProductWithHttpInfo + * + * Duplicate a product + * + * @param int $id The ID of the product (required) + * + * @throws ApiException on non-2xx response + * @throws InvalidArgumentException|GuzzleException + * @return array of \Pipedrive\versions\v2\Model\ProductResponse, HTTP status code, HTTP response headers (array of strings) + */ + public function duplicateProductWithHttpInfo($id) + { + $request = $this->duplicateProductRequest($id); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + if ($e->getCode() === 401 && $this->config->isRefreshPossible()) { + $this->config->refreshToken(); + $request = $this->duplicateProductRequest($id); + $response = $this->client->send($request, $options); + } else { + 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 201: + /* @phpstan-ignore-next-line */ + if ('\Pipedrive\versions\v2\Model\ProductResponse' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, '\Pipedrive\versions\v2\Model\ProductResponse', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + 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() + ); + } + + /* @phpstan-ignore-next-line */ + if ('\Pipedrive\versions\v2\Model\ProductResponse' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, '\Pipedrive\versions\v2\Model\ProductResponse', []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 201: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\Pipedrive\versions\v2\Model\ProductResponse', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation duplicateProductAsync + * + * Duplicate a product + * + * @param int $id The ID of the product (required) + * + * @throws InvalidArgumentException|OAuthProviderException + * @return PromiseInterface + */ + public function duplicateProductAsync($id): PromiseInterface + { + return $this->duplicateProductAsyncWithHttpInfo($id) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation duplicateProductAsyncWithHttpInfo + * + * Duplicate a product + * + * @param int $id The ID of the product (required) + * + * @throws InvalidArgumentException|OAuthProviderException + * @return PromiseInterface + */ + public function duplicateProductAsyncWithHttpInfo($id): PromiseInterface + { + $returnType = '\Pipedrive\versions\v2\Model\ProductResponse'; + $request = $this->duplicateProductRequest($id); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + /* @phpstan-ignore-next-line */ + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + 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 'duplicateProduct' + * + * @param int $id The ID of the product (required) + * + * @throws InvalidArgumentException|OAuthProviderException + * @return Request + */ + public function duplicateProductRequest($id): Request + { + // verify the required parameter 'id' is set + /* @phpstan-ignore-next-line */ + if ($id === null || (is_array($id) && count($id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $id when calling duplicateProduct' + ); + } + + $resourcePath = '/products/{id}/duplicate'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($id !== null) { + $resourcePath = str_replace( + '{' . 'id' . '}', + ObjectSerializer::toPathValue($id), + $resourcePath + ); + } + + + /* @phpstan-ignore-next-line */ + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + /* @phpstan-ignore-next-line */ + 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 ($headers['Content-Type'] === 'application/json') { + $httpBody = Utils::jsonEncode($formParams); + + } else { + // for HTTP post (form) + $httpBody = Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('x-api-token'); + if ($apiKey !== null) { + $headers['x-api-token'] = $apiKey; + } + // this endpoint requires OAuth (access token) + if ($this->config->getAccessToken() !== null) { + // If access token is expired + if ($this->config->isRefreshPossible() && $this->config->getExpiresAt() <= time()) { + $this->config->refreshToken(); + } + $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + /** * Operation getProduct *