Skip to content

Commit 76eb14c

Browse files
committed
GRAL-2200: fix updateADeal and updateAnorganization optional and custom fields
1 parent c255012 commit 76eb14c

File tree

3 files changed

+26
-37
lines changed

3 files changed

+26
-37
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ $result = $deals->getDetailsOfADeal($id);
13501350

13511351
### <a name="update_a_deal"></a>![Method: ](https://apidocs.io/img/method.png ".DealsController.updateADeal") updateADeal
13521352

1353-
> Updates the properties of a deal. For more information on how to update a deal, see <a href="https://pipedrive.readme.io/docs/updating-a-deal" target="_blank" rel="noopener noreferrer">this tutorial</a>.
1353+
> Updates the properties of a deal. Note that you can supply additional custom fields along with the request that are not described here. These custom fields are different for each Pipedrive account and can be recognized by long hashes as keys. To determine which custom fields exists, fetch the dealFields and look for 'key' values. For more information on how to update a deal, see <a href="https://pipedrive.readme.io/docs/updating-a-deal" target="_blank" rel="noopener noreferrer">this tutorial</a>.
13541354
13551355

13561356
```php
@@ -4059,7 +4059,7 @@ $organizations->getDetailsOfAnOrganization($id);
40594059

40604060
### <a name="update_an_organization"></a>![Method: ](https://apidocs.io/img/method.png ".OrganizationsController.updateAnOrganization") updateAnOrganization
40614061

4062-
> Updates the properties of an organization.
4062+
> Updates the properties of an organization. Note that you can supply additional custom fields along with the request that are not described here. These custom fields are different for each Pipedrive account and can be recognized by long hashes as keys. To determine which custom fields exists, fetch the organizationFields and look for 'key' values.
40634063
40644064

40654065
```php

src/Controllers/DealsController.php

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,12 @@ public function getDetailsOfADeal(
518518
* //pipedrive.readme.io/docs/updating-a-deal" target="_blank" rel="noopener noreferrer">this
519519
* tutorial</a>.
520520
*
521-
* @param array $options Array with all options for search
521+
* Note that you can supply additional custom fields along with the request that are
522+
* not described here. These custom fields are different for each Pipedrive account and can be
523+
* recognized by long hashes as keys. To determine which custom fields exists, fetch the dealFields and
524+
* look for 'key' values.
525+
*
526+
* @param array $options Array with all options for search
522527
* @param integer $options['id'] ID of the deal
523528
* @param string $options['title'] (optional) Deal title
524529
* @param string $options['value'] (optional) Value of the deal. If omitted, value will be set to 0.
@@ -556,9 +561,9 @@ public function updateADeal(
556561
$_queryBuilder = '/deals/{id}';
557562

558563
//process optional query parameters
559-
$_queryBuilder = APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array (
560-
'id' => $this->val($options, 'id'),
561-
));
564+
$_queryBuilder = APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array(
565+
'id' => $this->val($options, 'id'),
566+
));
562567

563568
//validate and preprocess url
564569
$_queryUrl = APIHelper::cleanUrl(Configuration::getBaseUri() . $_queryBuilder);
@@ -570,29 +575,14 @@ public function updateADeal(
570575
'Authorization' => sprintf('Bearer %1$s', Configuration::$oAuthToken->accessToken)
571576
);
572577

573-
//prepare parameters
574-
$_parameters = array (
575-
'title' => $this->val($options, 'title'),
576-
'value' => $this->val($options, 'value'),
577-
'currency' => $this->val($options, 'currency'),
578-
'user_id' => $this->val($options, 'userId'),
579-
'person_id' => $this->val($options, 'personId'),
580-
'org_id' => $this->val($options, 'orgId'),
581-
'stage_id' => $this->val($options, 'stageId'),
582-
'status' => APIHelper::prepareFormFields($this->val($options, 'status')),
583-
'probability' => $this->val($options, 'probability'),
584-
'lost_reason' => $this->val($options, 'lostReason'),
585-
'visible_to' => APIHelper::prepareFormFields($this->val($options, 'visibleTo'))
586-
);
587-
588578
//call on-before Http callback
589-
$_httpRequest = new HttpRequest(HttpMethod::PUT, $_headers, $_queryUrl, $_parameters);
579+
$_httpRequest = new HttpRequest(HttpMethod::PUT, $_headers, $_queryUrl, $options);
590580
if ($this->getHttpCallBack() != null) {
591581
$this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
592582
}
593583

594584
//and invoke the API call request to fetch the response
595-
$response = Request::put($_queryUrl, $_headers, Request\Body::Form($_parameters));
585+
$response = Request::put($_queryUrl, $_headers, Request\Body::Json($options));
596586

597587
$_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
598588
$_httpContext = new HttpContext($_httpRequest, $_httpResponse);

src/Controllers/OrganizationsController.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,12 @@ public function getDetailsOfAnOrganization(
397397
/**
398398
* Updates the properties of an organization.
399399
*
400-
* @param array $options Array with all options for search
400+
* Note that you can supply additional custom fields along with the request
401+
* that are not described here. These custom fields are different for each Pipedrive account and can be
402+
* recognized by long hashes as keys. To determine which custom fields exists, fetch the
403+
* organizationFields and look for 'key' values.
404+
*
405+
* @param array $options Array with all options for search
401406
* @param integer $options['id'] ID of the organization
402407
* @param string $options['name'] (optional) Organization name
403408
* @param integer $options['ownerId'] (optional) ID of the user who will be marked as the owner of this
@@ -406,7 +411,7 @@ public function getDetailsOfAnOrganization(
406411
* set to the default visibility setting of this item type for the authorized
407412
* user.<dl class=\"fields-list\"><dt>1</dt><dd>Owner &amp; followers
408413
* (private)</dd><dt>3</dt><dd>Entire company (shared)</dd></dl>
409-
* @return void response from the API call
414+
* @return mixed response from the API call
410415
* @throws APIException Thrown if API call fails
411416
*/
412417
public function updateAnOrganization(
@@ -419,34 +424,28 @@ public function updateAnOrganization(
419424
$_queryBuilder = '/organizations/{id}';
420425

421426
//process optional query parameters
422-
$_queryBuilder = APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array (
423-
'id' => $this->val($options, 'id'),
424-
));
427+
$_queryBuilder = APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array(
428+
'id' => $this->val($options, 'id'),
429+
));
425430

426431
//validate and preprocess url
427432
$_queryUrl = APIHelper::cleanUrl(Configuration::getBaseUri() . $_queryBuilder);
428433

429434
//prepare headers
430435
$_headers = array (
431436
'user-agent' => BaseController::USER_AGENT,
437+
'Accept' => 'application/json',
432438
'Authorization' => sprintf('Bearer %1$s', Configuration::$oAuthToken->accessToken)
433439
);
434440

435-
//prepare parameters
436-
$_parameters = array (
437-
'name' => $this->val($options, 'name'),
438-
'owner_id' => $this->val($options, 'ownerId'),
439-
'visible_to' => APIHelper::prepareFormFields($this->val($options, 'visibleTo'))
440-
);
441-
442441
//call on-before Http callback
443-
$_httpRequest = new HttpRequest(HttpMethod::PUT, $_headers, $_queryUrl, $_parameters);
442+
$_httpRequest = new HttpRequest(HttpMethod::PUT, $_headers, $_queryUrl, $options);
444443
if ($this->getHttpCallBack() != null) {
445444
$this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
446445
}
447446

448447
//and invoke the API call request to fetch the response
449-
$response = Request::put($_queryUrl, $_headers, Request\Body::Form($_parameters));
448+
$response = Request::put($_queryUrl, $_headers, Request\Body::Json($options));
450449

451450
$_httpResponse = new HttpResponse($response->code, $response->headers, $response->raw_body);
452451
$_httpContext = new HttpContext($_httpRequest, $_httpResponse);

0 commit comments

Comments
 (0)