zendesk / zendesk/zendesk_api_client_php
Unable to send PATCH for custom objects
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 344
- Forks
- 247
- Avg merge
- 27m
- Merged PRs (30d)
- 1
Description
We are attempting to update custom objects following the documentation for updated by external id (https://developer.zendesk.com/api-reference/custom-data/custom-objects/custom_object_records/#set-custom-object-record-by-external-id-or-name)
However, the only way to send a PATCH method is to do something like this:
$client->post($url, $data, ['method' => 'PATCH']);
But when I try that, I'm getting this error:
An error occurred calling API. Error: Client error: `POST https://bubblebinzfranchisellc.zendesk.com/api/v2/custom_objects/service_request/records?external_id=20693` resulted in a `422 Unprocessable Entity` response:
{"error":"RecordInvalid","description":"Record validation errors","details":{"external_id":[{"description":"This externa (truncated...)
[details] {"error":"RecordInvalid","description":"Record validation errors","details":{"external_id":[{"description":"This external ID is already in use."}]}}
So I looked into the HttpClient class and check the post method there. You have the array_merge backwards I think. The $options being sent in containing 'method' => 'PATCH' is getting overridden by the POST method in the second array.
$extraOptions = array_merge($options, [
'postFields' => $postData,
'method' => 'POST'
]);
In my local system, I modified the class and reversed it as such:
$extraOptions = array_merge([
'postFields' => $postData,
'method' => 'POST'
], $options);
And it works perfectly fine. But I don't have a way to do that on the server because this is controlled by composer.
Can you please make this adjustment ASAP?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in the HttpClient class and inspect the post method's option merging, reproducing the PATCH request described in the issue. Verify that the requested method is preserved instead of being treated as POST, then confirm the custom-object update no longer produces the duplicate external-ID validation error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100