Skip to content

Commit 2d2ccf2

Browse files
authored
Merge pull request #48 from pipedrive/GRAL-2200-person-optional-fields
GRAL-2200: fix updating deals/persons/organizations optional and custom fields
2 parents 8b9b83e + ae441b4 commit 2d2ccf2

File tree

5 files changed

+40
-55
lines changed

5 files changed

+40
-55
lines changed

README.md

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

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

1541-
> 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>.
1541+
> 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>.
15421542
15431543

15441544
```php
@@ -4247,7 +4247,7 @@ $organizations->getDetailsOfAnOrganization($id);
42474247

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

4250-
> Updates the properties of an organization.
4250+
> 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.
42514251
42524252

42534253
```php
@@ -5182,7 +5182,7 @@ $persons->getDetailsOfAPerson($id);
51825182

51835183
### <a name="update_a_person"></a>![Method: ](https://apidocs.io/img/method.png ".PersonsController.updateAPerson") updateAPerson
51845184

5185-
> Updates the properties of a person. For more information on how to update a person, see <a href="https://pipedrive.readme.io/docs/updating-a-person" target="_blank" rel="noopener noreferrer">this tutorial</a>.
5185+
> Updates the properties of a person. 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 personFields and look for 'key' values. For more information on how to update a person, see <a href="https://pipedrive.readme.io/docs/updating-a-person" target="_blank" rel="noopener noreferrer">this tutorial</a>.
51865186
51875187

51885188
```php

src/Controllers/BaseController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class BaseController
2424
* User-agent to be sent with API calls
2525
* @var string
2626
*/
27-
const USER_AGENT = 'Pipedrive-SDK-PHP-3.1.1';
27+
const USER_AGENT = 'Pipedrive-SDK-PHP-3.2.0';
2828

2929
/**
3030
* HttpCallBack instance associated with this controller

src/Controllers/DealsController.php

Lines changed: 12 additions & 22 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,43 +561,28 @@ 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);
565570

566571
//prepare headers
567572
$_headers = array (
568573
'user-agent' => BaseController::USER_AGENT,
569-
'Accept' => 'application/json',
574+
'content-type' => 'application/json; charset=utf-8',
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+
'content-type' => 'application/json; charset=utf-8',
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);

src/Controllers/PersonsController.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,12 @@ public function getDetailsOfAPerson(
401401
* href="https://pipedrive.readme.io/docs/updating-a-person" target="_blank" rel="noopener
402402
* noreferrer">this tutorial</a>.
403403
*
404-
* @param array $options Array with all options for search
404+
* Note that you can supply additional custom fields along with the request that are
405+
* not described here. These custom fields are different for each Pipedrive account and can be
406+
* recognized by long hashes as keys. To determine which custom fields exists, fetch the personFields
407+
* and look for 'key' values.
408+
*
409+
* @param array $options Array with all options for search
405410
* @param integer $options['id'] ID of a person
406411
* @param string $options['name'] (optional) Person name
407412
* @param integer $options['ownerId'] (optional) ID of the user who will be marked as the owner of this person.
@@ -429,36 +434,27 @@ public function updateAPerson(
429434

430435
//process optional query parameters
431436
$_queryBuilder = APIHelper::appendUrlWithTemplateParameters($_queryBuilder, array (
432-
'id' => $this->val($options, 'id'),
433-
));
437+
'id' => $this->val($options, 'id'),
438+
));
434439

435440
//validate and preprocess url
436441
$_queryUrl = APIHelper::cleanUrl(Configuration::getBaseUri() . $_queryBuilder);
437442

438443
//prepare headers
439444
$_headers = array (
440445
'user-agent' => BaseController::USER_AGENT,
446+
'content-type' => 'application/json; charset=utf-8',
441447
'Authorization' => sprintf('Bearer %1$s', Configuration::$oAuthToken->accessToken)
442448
);
443449

444-
//prepare parameters
445-
$_parameters = array (
446-
'name' => $this->val($options, 'name'),
447-
'owner_id' => $this->val($options, 'ownerId'),
448-
'org_id' => $this->val($options, 'orgId'),
449-
'email' => array_values($this->val($options, 'email')),
450-
'phone' => array_values($this->val($options, 'phone')),
451-
'visible_to' => APIHelper::prepareFormFields($this->val($options, 'visibleTo'))
452-
);
453-
454450
//call on-before Http callback
455-
$_httpRequest = new HttpRequest(HttpMethod::PUT, $_headers, $_queryUrl, $_parameters);
451+
$_httpRequest = new HttpRequest(HttpMethod::PUT, $_headers, $_queryUrl, $options);
456452
if ($this->getHttpCallBack() != null) {
457453
$this->getHttpCallBack()->callOnBeforeRequest($_httpRequest);
458454
}
459455

460456
//and invoke the API call request to fetch the response
461-
$response = Request::put($_queryUrl, $_headers, Request\Body::Form($_parameters));
457+
$response = Request::put($_queryUrl, $_headers, Request\Body::Json($options));
462458

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

0 commit comments

Comments
 (0)