Create ticket via API for Zammad 3.6.x

Infos:

  • Used Zammad version: 3.6.x
  • Used Zammad installation source: package
  • Operating system: Zammad runs on a Linux distro, i’m accessing the API from Windows 10 WSL
  • Browser + version: Firefox 85.0.2 (not relevant)

I’m trying to create a ticket programmatically from Python on our self-hosted Zammad server running 3.6.x
The token i’m using is for my account which is admin on the server.

I’m going by the documentation at https://docs.zammad.org/en/latest/api/ticket.html#create

That documentation is incorrect. When i provide just the indicated fields, my request is refused because the field “customer_id” is missing.

I’ve made progress by being able to create a user automatically, and providing that new user’s id as “customer_id”. The Ticket is created but not the Article, and i get an HTTP 500 return code with an explanation: “error”:“no implicit conversion of Symbol into Integer”. I’ve tried tens of combinations and cannot figure out which field is causing the problem.

Expected behavior:

  • Ticket and article should be created by API POST /api/v1/tickets

Actual behavior:

  • Ticket is created, new, no owner, priority 2, in the correct group, with the correct customer. But the article is not created. I get an HTTP 500 return code with an explanation: “error”:“no implicit conversion of Symbol into Integer”.

Steps to reproduce the behavior:

#! /usr/bin/python3

import json, requests

token = 'MRk..."                                    # enter my token here. my account is admin and agent
auth  = f'Token token={token}'

def create_ticket():
    url = 'https://support.example.com/api/v1/tickets'
    new_ticket = {
        "title": "Request access",
        "group": "Access to service",
        "customer_id": customer_id,   # fetched previously, an int = 1234
        "article": {
            "from": "user@example.com",   # this is the email and login of customer 1234
            "subject": "Request access",
            "internal": False,
            "sender": 'Customer',
            "type": "note",                            # note or web or email or phone
            "body": "TEST TICKET"
        }
    }

    print(json.dumps(new_ticket, indent=4))
    req = requests.post(url, headers={'Authorization' : auth}, data = new_ticket)

    if (req.status_code != 201):
        print(f"Error: {req.status_code} {req.reason}")
        print(f"{req.text}")
        print(req.json())
        return(0)

create_ticket()
1 Like

from the error message, either customer_id or internal’s value Could be the issue

Hi elvis, thanks for the reply. I’m pretty sure the customer_id is correct. It’s an integer, and i verified its value manually. As for Internal, i’ve tried False, “false”, 0. Not sure what the ruby representation of false is.

The documentation is not wrong, but you’re using invalid JSON data.

I tested the payload:

{
        "title": "Request access",
        "group": "Sales",
        "customer_id": 3,
        "article": {
            "from": "user@example.com",
            "subject": "Request access",
            "internal": false,
            "sender": "Customer",
            "type": "note",
            "body": "TEST TICKET"
        }
    }

So to translate that into yours:

{
        "title": "Request access",
        "group": "Access to service",
        "customer_id": customer_id,
        "article": {
            "from": "user@example.com",
            "subject": "Request access",
            "internal": false,
            "sender": "Customer",
            "type": "note",
            "body": "TEST TICKET"
        }
    }

Please note that comments have no place in your JSON payload.
If it still fails, you may want to look into the production.log of Zammad.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.