Auto Create User from Ticket-API

Hi guys,

following this ticket:

I did exactly like bernd and try to create a ticket with an unknown user using the guess: way
Unfortunately it doesnt work.

Are there any changes with zammad 4.x that caused it to stop working?
If so, wouldnt make it support it again. Especially when providing Supports-Widget on web I love to not check/create for existing users but let the system do it right away.

Here is my request:

    request_body = {
        "title": f"Form Submission - {form_name}",
        "group": "Users",
        "customer_id": f"guess:{email}",
        "note": "Note",
        "article": {
            "subject": "Anfrage {form_name}",
            "body": f"{request.data}",
            "from": name,
            "to": email,
            "type": "email",
            "internal": False
        }
    }

    headers = {
        "Authorization": f"Token {settings.ZAMMAD_TOKEN}"
    }

    response = requests.post(url=f'{settings.ZAMMAD_URL}/api/v1/tickets',
                  json=request_body,
                  headers=headers
                  )

I tried with both X-Behalf-of header and without. The ticket is created is created when using x-behalf-of, but then with the existing account instead of the new one that should be created.

3 Likes

Oh yes, please.
We have an own “Create new ticket” form in our application and are jumping through the following hoops to create a ticket:

Check if user exists 
GET /api/v1/users/search?limit=1&query=email.keyword:potentiallyNewCustomer@example.com X-On-Behalf-Of null

if not exist, create it
POST /api/v1/users X-On-Behalf-Of null

create ticket with the user.id of the new or existing user from above:
POST /api/v1/tickets/ with X-On-Behalf-Of: user.id from above

Would be great to just do it in one shot.
The newly created ticket should belong to the customer (by email).

Initially I would have had expected that X-On-Behalf-Of would work like this, but it fails if the user does not exist yet.