Create ticket w/ email flow via API

Infos:

  • Used Zammad version: 3.0.x
  • Used Zammad installation source: Docker image
  • Operating system: Amazon Linux (CentOS-based)
  • Browser + version: Chrome

Hello Zammad community,

We’re currently trying to migrate to a self-hosted Zammad setup from an existing email-based workflow. We want to use Zammad’s API to create tickets (initiated by logged-in customers visiting a “support” page), but all follow-up communication should be done via email.

For this first step, I am trying to create a ticket article via the API as if it was received from the client via email. Unfortunately this doesn’t seem to work - I’d be thankful for any hints how this could be achieved.

When I am posting this:

{
    article: {
        from: "customer@customer.com",
        to: "support@company.com",
        body: "body",
        internal: false,
        subject: "subject",
        type: "email"
    },
    customer_id: 123,
    group: "Users",
    title: "subject"
}

the article instead appears in the system like so

{
    from: "\"Support\" <support@company.com>",
    to: "support@company.com",
    type: "email",
    ...
}

(Note how this replaced the user’s email with the company’s email for both sender and receiver. This means that pressing the Reply button in Zammad’s interface won’t work - as it doesn’t pre-populate the customer’s email address when it is pressed.)

If I am instead trying to send the same JSON on behalf of the customer user (using the X-On-Behalf-Of header), the article even remains a note (which is also not desirable).

{
    from: "Customer Name",
    to: "support@company.com",
    type: "note",
    ...
}

Any ideas? Thanks in advance!

I think that when you use the API, tickets will be created with the credentials you used to access the API. You need to set the attribute on behalf of user to actually change the person creating the ticket.

This is the PHP Zammad client, check the end of the page.

I hope this help!

Thank you for your reply @edneymatias.

I have since figured out that I can add an email to a ticket via the API when I set

{
    article: {
        sender: 'Customer'
        ...

However - this still does not work when I am doing what you suggest I do, namely set the header to act on behalf of the customer. In this case, the ticket article will still only show up as a note - and I don’t know why :(

You might want to create the affected stuff on behalf :wink:

https://docs.zammad.org/en/latest/api-intro.html#example-curl-request-on-behalf-of-a-different-user

Thank you @MrGeneration. I did that. But when I try to create the ticket on behalf of the customer, I find myself unable to create an email-type article (they are always turned into notes). Any ideas?

This is what I am sending in effect:

{
    article: {
        from: "customer@customer.com",
        to: "support@company.com",
        body: "body",
        internal: false,
        sender: "Customer",
        subject: "subject",
        type: "email"
    },
    customer_id: 123,
    group: "Users",
    title: "subject"
}

But when acting on behalf of the customer, the article ends up as like so - this only occurs when acting on behalf - doing this as the logged-in user works fine:

{
    from: "Customer Name",
    to: "support@company.com",
    type: "note",
    ...
}

And not as an email.

You might also want to set “type_id” to the ID that correspondences to “email” inside of your installation.

The following discussion might be helpfull, at the end you can also find a full payload that is working is you want to fiddle around :slight_smile:

Thank you @MrGeneration - I’ll try this Monday and report back.

1 Like

@MrGeneration This doesn’t seem to work for me unfortunately - the article still comes back as a note. Please let me know anything I should try out!

This is the ticket I am creating:

{
    "article": {
        "body": "foo",
        "from": "foo@bar.com",
        "internal": false,
        "subject": "foo",
        "to": "support@company.com",
        "sender": "Customer",
        "type": "email",
        "type_id": 1
    },
    "customer_id": 1358,
    "group": "Users",
    "status": 1,
    "title": "foo"
}

But this is the article that I get back:

{
    "id": 8812,
    "ticket_id": 4016,
    "type_id": 10,
    "sender_id": 2,
    "from": " ",
    "to": "support@company.com",
    "cc": null,
    "subject": "foo",
    "reply_to": null,
    "message_id": null,
    "message_id_md5": null,
    "in_reply_to": null,
    "content_type": "text\/plain",
    "references": null,
    "body": "asd",
    "internal": false,
    "preferences": {},
    "updated_by_id": 1358,
    "created_by_id": 1358,
    "origin_by_id": 1358,
    "created_at": "2019-07-22T17:33:35.925Z",
    "updated_at": "2019-07-22T17:33:35.925Z",
    "attachments": [],
    "type": "note",
    "sender": "Customer",
    "created_by": "foo@bar.com",
    "updated_by": "foo@bar.com",
    "origin_by": "foo@bar.com"
}

Maybe you want to have a look here https://github.com/zammad/zammad/issues/1909

Hello @edneymatias - thank you for the pointer to this GitHub issue.

With this information I was able to get it to work, not perfectly, but sufficient for our needs. What we do now, that does the trick:

  • set type to web
  • set from and to to the customer’s email
  • submit the article on behalf of the user’s account

The second point is a bit counter-intutive, as pressing reply will pick up the email address from the to field. The third point was needed for the case when the customer had an admin-level account, for some reason.

Hope this is the most correct way to proceed. Thanks again.

2 Likes

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