Skip to content

Commit c255012

Browse files
committed
GRAL-2200: fix updateAPerson optional and custom fields
1 parent b5fe565 commit c255012

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4994,7 +4994,7 @@ $persons->getDetailsOfAPerson($id);
49944994

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

4997-
> 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>.
4997+
> 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>.
49984998
49994999

50005000
```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.0.0';
27+
const USER_AGENT = 'Pipedrive-SDK-PHP-3.0.1';
2828

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

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)