zendesk / zendesk_api_client_php

Official Zendesk API v2 client library for PHP
336 stars 259 forks source link

Possible bug in PUTting tags #343

Closed arthens closed 7 years ago

arthens commented 7 years ago

Hey there,

we are trying to append tags to a ticket, but can't get it to work. Looking at the code we suspect it might be a bug, but we aren't sure.

This is the code we are using:

$client->tickets($ticketId)->tags()->update(null, [$tag1, $tag2]);

but nothing happens.

Debugging the code we realised that the client is sending a PUT request to /tickets/{$id}/tags with data

[
    'tag' => [
        $tag1,
        $tag2,
    ], 
]

The API docs say the request content should contain tags, not tag, but the client is sending tas instead.

The culprit seems to be objectName in Update. This trait expects the including class to define objectName, but Tags doesn't explicitly do that, and relies on ResourceAbstract, which singularise it by default.

We can't see any obvious way of changing this behaviour, but we can see that using reflections to "fix" objectName solves our problem:

$tags = $client->tickets($ticketId)->tags();
$reflection = new \ReflectionProperty(get_class($tags), 'objectName');
$reflection->setAccessible(true);
$reflection->setValue($tags, 'tags'); // the magic happens here

$tags->update(null, [$tag1, $tag2]);

Is this a bug? Or are we misusing the client? (we are on 2.20 btw)

Thank you

donjose24 commented 7 years ago

Hello! Will try to recreate this issue. will get back to you asap!

arthens commented 7 years ago

@jmramos02 did you have any luck reproducing it? Let me know if you need anything else from us

joseconsador commented 7 years ago

@arthens Thanks for this, we've confirmed the issue on our end. We were not able to reproduce the tas issue though. We'll have a PR out for the objectName.

joseconsador commented 7 years ago

PR merged. Marking this as closed.

arthens commented 7 years ago

Thank you!