zendesk / zendesk_api_client_php

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

Can't create a tagger field #392

Closed darksnow closed 5 months ago

darksnow commented 6 years ago

I'm trying to create a drop down field with set options.

    $this->client->ticketFields()->create([
        'title' => 'Notification Type',
        'type' => 'tagger',
        'field_options' => [
            ['name' => 'feed', 'title' => 'Feed'],
            ['name' => 'food', 'title' => 'Food']
        ]
     ]);

The client in my PHP object is working and I can list tickets and fields, so my connection is good. From the API call I'm getting the following error:

Zendesk\API\Exceptions\ApiResponseException: Client error: `POST https://mydomain.zendesk.com/api/v2/ticket_fields.json` resulted in a `422 Unprocessable Entity` response: {"error":"RecordInvalid","description":"Record validation errors","details":{"field_options":[{"description":"Field opti (truncated...) [details] {"error":"RecordInvalid","description":"Record validation errors","details":{"field_options":[{"description":"Field options: must contain at least one option","error":"EmptyValue"}]}} in /app/vendor/zendesk/zendesk_api_client_php/src/Zendesk/API/Http.php on line 95

TL;DR Field options: must contain at least one option

So, the issue is, how do I create a tagger field and can you include an example of creating a field, and a tagger field, in the examples supplied with the code base? The JSON API tells me I need to supply an object literal to the custom_field_options attribute, but I can't really do that in PHP, also, the option appears to have been changes to just field_options which I just guessed and it got me a little further.

Any help would be appreciated, and some clarification in the docs.

Thanks.

darksnow commented 6 years ago

For clarification, if I do use custom_field_options the error message changes to:

'Field options: must have a tag`

But there's no mention if a tag for the values list in the JSON API docs. Adding a tag to the field does nothing and I get the same error message whether I use an array keyed to name and title or if I use an associative array like

'feed' => 'Feed'
rahulpatel033 commented 5 years ago

Use this.

{
    "ticket_field":{
        "raw_title":"Test Dropdown",
        "raw_title_in_portal":"",
        "raw_description":"",
        "agent_description":"",
        "visible_in_portal":false,
        "editable_in_portal":false,
        "required":false,
        "required_in_portal":false,
        "type":"tagger",
        "custom_field_options":[
            {
                "name":"Test",
                "raw_name":"Test",
                "value":"test",
                "default":false

            },
            {
                "name":"Test1",
                "raw_name":"Test1",
                "value":"test1",
                "default":false

            }
        ]
    }
}
roo-oliv commented 3 years ago

I'm having a similar problem. When I try to add a custom field option or to update one the API will return this error:

{
  "error": "RecordInvalid",
  "description": "Record validation errors",
  "details": {
    "custom_field_options": [
      {
        "description": "Custom field options must have a tag",
        "error": "BlankValue"
      }
    ]
  }
}

Interestingly, the option gets created/updated despite the error.

roo-oliv commented 3 years ago

For anyone else having this problem, there is a workaround detailed here. Zendesk API doesn't accept that any of the options (edited/created or not) have other attributes other than name and value. So basically, the workaround is to recreate the entire list of custom field options with just "name" and "value".

This is most likely a bug in the API which should be fixed or if not this should be explained in the documentation at least.

ecoologic commented 5 months ago

Hi,

thank you for your request, are you still interested in a solution for this issue?