From ff31f59475a21e813e1bf3e0015c35caed73f476 Mon Sep 17 00:00:00 2001 From: pipedrive-bot Date: Tue, 18 Nov 2025 09:57:37 +0000 Subject: [PATCH] Build 292 - version-minor --- CHANGELOG.md | 2 + docs/versions/v1/Model/FieldResponse.md | 2 +- docs/versions/v1/Model/FieldResponseAllOf.md | 2 +- docs/versions/v2/Api/ProductsApi.md | 66 +++++ docs/versions/v2/README.md | 1 + lib/versions/v1/Api/ChannelsApi.php | 20 ++ lib/versions/v1/Configuration.php | 4 +- lib/versions/v1/Model/FieldResponse.php | 6 +- lib/versions/v1/Model/FieldResponseAllOf.php | 6 +- lib/versions/v2/Api/ProductsApi.php | 296 +++++++++++++++++++ lib/versions/v2/Configuration.php | 4 +- 11 files changed, 397 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03e749d..7ff548c 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 `POST /products/{id}/duplicate` endpoint for duplicating an existing product ## Added - Added `is_archived` field in search response schemas for deals and leads ### Fixed diff --git a/docs/versions/v1/Model/FieldResponse.md b/docs/versions/v1/Model/FieldResponse.md index c94f3a9..d44e796 100644 --- a/docs/versions/v1/Model/FieldResponse.md +++ b/docs/versions/v1/Model/FieldResponse.md @@ -5,6 +5,6 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **success** | **bool** | If the response is successful or not | [optional] -**data** | [**\Pipedrive\versions\v1\Model\Field**](Field.md) | | [optional] +**data** | [**\Pipedrive\versions\v1\Model\GetField**](GetField.md) | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/docs/versions/v1/Model/FieldResponseAllOf.md b/docs/versions/v1/Model/FieldResponseAllOf.md index ab15850..8aba12c 100644 --- a/docs/versions/v1/Model/FieldResponseAllOf.md +++ b/docs/versions/v1/Model/FieldResponseAllOf.md @@ -4,6 +4,6 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**data** | [**\Pipedrive\versions\v1\Model\Field**](Field.md) | | [optional] +**data** | [**\Pipedrive\versions\v1\Model\GetField**](GetField.md) | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 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/v1/Api/ChannelsApi.php b/lib/versions/v1/Api/ChannelsApi.php index d825aa3..4dbbf8e 100644 --- a/lib/versions/v1/Api/ChannelsApi.php +++ b/lib/versions/v1/Api/ChannelsApi.php @@ -132,6 +132,7 @@ public function getConfig(): Configuration * @throws ApiException on non-2xx response * @throws InvalidArgumentException|GuzzleException * @return \Pipedrive\versions\v1\Model\ChannelObjectResponse|\Pipedrive\versions\v1\Model\AddChannelBadRequestResponse|\Pipedrive\versions\v1\Model\AddChannelForbiddenErrorResponse + * @deprecated */ public function addChannel($channel_object = null) { @@ -149,6 +150,7 @@ public function addChannel($channel_object = null) * @throws ApiException on non-2xx response * @throws InvalidArgumentException|GuzzleException * @return array of \Pipedrive\versions\v1\Model\ChannelObjectResponse|\Pipedrive\versions\v1\Model\AddChannelBadRequestResponse|\Pipedrive\versions\v1\Model\AddChannelForbiddenErrorResponse, HTTP status code, HTTP response headers (array of strings) + * @deprecated */ public function addChannelWithHttpInfo($channel_object = null) { @@ -291,6 +293,7 @@ public function addChannelWithHttpInfo($channel_object = null) * * @throws InvalidArgumentException|OAuthProviderException * @return PromiseInterface + * @deprecated */ public function addChannelAsync($channel_object = null): PromiseInterface { @@ -311,6 +314,7 @@ function ($response) { * * @throws InvalidArgumentException|OAuthProviderException * @return PromiseInterface + * @deprecated */ public function addChannelAsyncWithHttpInfo($channel_object = null): PromiseInterface { @@ -358,6 +362,7 @@ function ($exception) { * * @throws InvalidArgumentException|OAuthProviderException * @return Request + * @deprecated */ public function addChannelRequest($channel_object = null): Request { @@ -461,6 +466,7 @@ public function addChannelRequest($channel_object = null): Request * @throws ApiException on non-2xx response * @throws InvalidArgumentException|GuzzleException * @return \Pipedrive\versions\v1\Model\DeleteChannelSuccess|\Pipedrive\versions\v1\Model\AddChannelBadRequestResponse + * @deprecated */ public function deleteChannel($id) { @@ -478,6 +484,7 @@ public function deleteChannel($id) * @throws ApiException on non-2xx response * @throws InvalidArgumentException|GuzzleException * @return array of \Pipedrive\versions\v1\Model\DeleteChannelSuccess|\Pipedrive\versions\v1\Model\AddChannelBadRequestResponse, HTTP status code, HTTP response headers (array of strings) + * @deprecated */ public function deleteChannelWithHttpInfo($id) { @@ -599,6 +606,7 @@ public function deleteChannelWithHttpInfo($id) * * @throws InvalidArgumentException|OAuthProviderException * @return PromiseInterface + * @deprecated */ public function deleteChannelAsync($id): PromiseInterface { @@ -619,6 +627,7 @@ function ($response) { * * @throws InvalidArgumentException|OAuthProviderException * @return PromiseInterface + * @deprecated */ public function deleteChannelAsyncWithHttpInfo($id): PromiseInterface { @@ -666,6 +675,7 @@ function ($exception) { * * @throws InvalidArgumentException|OAuthProviderException * @return Request + * @deprecated */ public function deleteChannelRequest($id): Request { @@ -779,6 +789,7 @@ public function deleteChannelRequest($id): Request * @throws ApiException on non-2xx response * @throws InvalidArgumentException|GuzzleException * @return \Pipedrive\versions\v1\Model\DeleteConversationSuccess|\Pipedrive\versions\v1\Model\DeleteConversationForbiddenErrorResponse|\Pipedrive\versions\v1\Model\DeleteConversationNotFoundErrorResponse + * @deprecated */ public function deleteConversation($channel_id, $conversation_id) { @@ -797,6 +808,7 @@ public function deleteConversation($channel_id, $conversation_id) * @throws ApiException on non-2xx response * @throws InvalidArgumentException|GuzzleException * @return array of \Pipedrive\versions\v1\Model\DeleteConversationSuccess|\Pipedrive\versions\v1\Model\DeleteConversationForbiddenErrorResponse|\Pipedrive\versions\v1\Model\DeleteConversationNotFoundErrorResponse, HTTP status code, HTTP response headers (array of strings) + * @deprecated */ public function deleteConversationWithHttpInfo($channel_id, $conversation_id) { @@ -940,6 +952,7 @@ public function deleteConversationWithHttpInfo($channel_id, $conversation_id) * * @throws InvalidArgumentException|OAuthProviderException * @return PromiseInterface + * @deprecated */ public function deleteConversationAsync($channel_id, $conversation_id): PromiseInterface { @@ -961,6 +974,7 @@ function ($response) { * * @throws InvalidArgumentException|OAuthProviderException * @return PromiseInterface + * @deprecated */ public function deleteConversationAsyncWithHttpInfo($channel_id, $conversation_id): PromiseInterface { @@ -1009,6 +1023,7 @@ function ($exception) { * * @throws InvalidArgumentException|OAuthProviderException * @return Request + * @deprecated */ public function deleteConversationRequest($channel_id, $conversation_id): Request { @@ -1136,6 +1151,7 @@ public function deleteConversationRequest($channel_id, $conversation_id): Reques * @throws ApiException on non-2xx response * @throws InvalidArgumentException|GuzzleException * @return \Pipedrive\versions\v1\Model\GetReceiveMessageSuccessResponse|\Pipedrive\versions\v1\Model\ReceiveMessageBadRequestErrorResponse + * @deprecated */ public function receiveMessage($message_object = null) { @@ -1153,6 +1169,7 @@ public function receiveMessage($message_object = null) * @throws ApiException on non-2xx response * @throws InvalidArgumentException|GuzzleException * @return array of \Pipedrive\versions\v1\Model\GetReceiveMessageSuccessResponse|\Pipedrive\versions\v1\Model\ReceiveMessageBadRequestErrorResponse, HTTP status code, HTTP response headers (array of strings) + * @deprecated */ public function receiveMessageWithHttpInfo($message_object = null) { @@ -1274,6 +1291,7 @@ public function receiveMessageWithHttpInfo($message_object = null) * * @throws InvalidArgumentException|OAuthProviderException * @return PromiseInterface + * @deprecated */ public function receiveMessageAsync($message_object = null): PromiseInterface { @@ -1294,6 +1312,7 @@ function ($response) { * * @throws InvalidArgumentException|OAuthProviderException * @return PromiseInterface + * @deprecated */ public function receiveMessageAsyncWithHttpInfo($message_object = null): PromiseInterface { @@ -1341,6 +1360,7 @@ function ($exception) { * * @throws InvalidArgumentException|OAuthProviderException * @return Request + * @deprecated */ public function receiveMessageRequest($message_object = null): Request { diff --git a/lib/versions/v1/Configuration.php b/lib/versions/v1/Configuration.php index bdda3a5..0a88676 100644 --- a/lib/versions/v1/Configuration.php +++ b/lib/versions/v1/Configuration.php @@ -111,11 +111,11 @@ class Configuration */ protected string $host = 'https://api.pipedrive.com/v1'; /** - * User agent of the HTTP request, set to "Pipedrive-SDK-PHP-13.x" by default + * User agent of the HTTP request, set to "Pipedrive-SDK-PHP-14.x" by default * * @var string */ - protected string $userAgent = 'Pipedrive-SDK-PHP-13.x'; + protected string $userAgent = 'Pipedrive-SDK-PHP-14.x'; /** * Debug switch (default set to false) diff --git a/lib/versions/v1/Model/FieldResponse.php b/lib/versions/v1/Model/FieldResponse.php index 78833d3..2af1c28 100644 --- a/lib/versions/v1/Model/FieldResponse.php +++ b/lib/versions/v1/Model/FieldResponse.php @@ -67,7 +67,7 @@ class FieldResponse implements ModelInterface, ArrayAccess, JsonSerializable */ protected static array $openAPITypes = [ 'success' => 'bool', - 'data' => '\Pipedrive\versions\v1\Model\Field' + 'data' => '\Pipedrive\versions\v1\Model\GetField' ]; /** @@ -261,7 +261,7 @@ public function setSuccess($success): self /** * Gets data * - * @return \Pipedrive\versions\v1\Model\Field|null + * @return \Pipedrive\versions\v1\Model\GetField|null */ public function getData() { @@ -271,7 +271,7 @@ public function getData() /** * Sets data * - * @param \Pipedrive\versions\v1\Model\Field|null $data data + * @param \Pipedrive\versions\v1\Model\GetField|null $data data * * @return self */ diff --git a/lib/versions/v1/Model/FieldResponseAllOf.php b/lib/versions/v1/Model/FieldResponseAllOf.php index 8e0cdc6..3daba19 100644 --- a/lib/versions/v1/Model/FieldResponseAllOf.php +++ b/lib/versions/v1/Model/FieldResponseAllOf.php @@ -66,7 +66,7 @@ class FieldResponseAllOf implements ModelInterface, ArrayAccess, JsonSerializabl * @phpsalm-var array */ protected static array $openAPITypes = [ - 'data' => '\Pipedrive\versions\v1\Model\Field' + 'data' => '\Pipedrive\versions\v1\Model\GetField' ]; /** @@ -231,7 +231,7 @@ public function valid(): bool /** * Gets data * - * @return \Pipedrive\versions\v1\Model\Field|null + * @return \Pipedrive\versions\v1\Model\GetField|null */ public function getData() { @@ -241,7 +241,7 @@ public function getData() /** * Sets data * - * @param \Pipedrive\versions\v1\Model\Field|null $data data + * @param \Pipedrive\versions\v1\Model\GetField|null $data data * * @return self */ 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 * diff --git a/lib/versions/v2/Configuration.php b/lib/versions/v2/Configuration.php index a94eade..1a2ebb3 100644 --- a/lib/versions/v2/Configuration.php +++ b/lib/versions/v2/Configuration.php @@ -111,11 +111,11 @@ class Configuration */ protected string $host = 'https://api.pipedrive.com/api/v2'; /** - * User agent of the HTTP request, set to "Pipedrive-SDK-PHP-13.x" by default + * User agent of the HTTP request, set to "Pipedrive-SDK-PHP-14.x" by default * * @var string */ - protected string $userAgent = 'Pipedrive-SDK-PHP-13.x'; + protected string $userAgent = 'Pipedrive-SDK-PHP-14.x'; /** * Debug switch (default set to false)