Ticket API Injection

When injecting a new ticket in to Zammad, the ticket is created as a channel note.

How does ones define that the new ticket being created is in channel email so that the autoresponder works and the formatting of the ticket is correct?

Hey @InsaneSplash,

somewhere in your article array you need to define the type of the article created. The default is note. If you set it to mail or email (you need to test this because i didn’t) this should work. You probably need to configure further settings though (receipent f. e.) but that shouldn’t be that hard.

Mini example of a note-type article:

   article=@{
                subject="my subject"
                body="my body"
                type="note"
    }

How does your current post body look like?

cheers

Thanks!

I tried the attribute “channel” but will give “type” a go.

I tried

'type'        => "mail",
'type'        => "email",
'channel'        => "mail",
'channel'        => "email",

None of the above changed the channel from Note to Email.

‘type’ => “email”, worked once I moved the option under article :)…

  1. What I have noticed is that I am unable to create a ticket with the status new. Each time I create a ticket, it uses the open status.

  2. I am also trying to figure out how to source the ticket from the customers email address so that the auto-responder sends back a response to the original sender. Currently it keeps using the groups email address…but shows the ticket was logged on behalf of.

  3. If I add a from attribute its ignored.

  4. If I use the customers from: address as the to: then the email is set to the customer as well as it being created.

It seems to me that the from and to fields are swapped around? Does anyone have an example to inject a ticket in to Zammad using the API instead of email, as if it were to be an email?

$client = new Client($zammad_api_client_config);
#$ticket = $client->setOnBehalfOfUser($email);

$ticket_data = [
    'group_id'    => 7, #Support Group
    'priority_id' => $priority_id,
    'state_id'    => 1,
    'title'       => $subject,
    'customer_id'    => "guess:$email",
    'article'     => [
        'to'      => $email,
        'from'    => $email,
        'subject' => $subject,
        'body'    => $ticket_text,
   'content_type' => "text/html",
        'type'    => "email",
    ],
];

$ticket = $client->resource( ResourceType::TICKET );
$ticket->setValues($ticket_data);
$ticket->save();

:slight_smile: any ideas on how to inject a new ticket in to the helpdesk as if it were to be an email?

Ah sorry! Been missing that way too often.
You’d want to add "type_id": 1, inside article{} and you should be fine!

1 Like

Thanks,

I see that the ticket is created using the API user instead of the email address entered. For example the auto-reply is being sent to support@xxxx.com instead of the users email address. The “From” is also showing the support group as the sender…This causes a loop…:frowning:

$client = new Client($zammad_api_client_config);

$ticket_data = [
    'group_id'    => 7, #Support Group
    'priority_id' => $priority_id,
    'state_id'    => 1,
    'title'       => $subject,
    'customer_id'    => "guess:$email",
    'article'     => [
        'to'      => $email,
        'from'    => $email,
        'subject' => $subject,
        'body'    => $ticket_text,
   'content_type' => "text/html",
        'type'    => "email",
        'type_id' => 1,
    ],
];

$ticket = $client->resource( ResourceType::TICKET );
$ticket->setValues($ticket_data);
$ticket->save();

Here’s my full payload. What I see is that your “TO” and “FROM” is the same based on your variable.
I guess you don’t want that, because TO and FROM should differ if you don’t want to write to yourself. :slight_smile:

{
    "group_id": 1,
    "priority_id": 3,
    "state_id": 2,
    "organization_id": 2,
    "title": "API-Test that works anyway",
    "owner_id": 3,
    "customer_id": 6,
    "note": null,
    "first_response_at": null,
    "first_response_escalation_at": "2019-01-31T10:50:28.000Z",
    "first_response_in_min": null,
    "first_response_diff_in_min": null,
    "close_at": null,
    "close_escalation_at": "2019-02-06T10:50:28.000Z",
    "close_in_min": null,
    "close_diff_in_min": null,
    "update_escalation_at": "2019-02-01T11:20:28.000Z",
    "update_in_min": null,
    "update_diff_in_min": null,
    "last_contact_at": "2019-01-14T15:50:28.000Z",
    "last_contact_agent_at": null,
    "last_contact_customer_at": "2019-01-14T15:50:28.000Z",
    "last_owner_update_at": null,
    "create_article_type_id": 5,
    "create_article_sender_id": 2,
    "article_count": 1,
    "escalation_at": "2019-01-31T10:50:28.000Z",
    "pending_time": null,
    "type": "email",
    "time_unit": null,
    "preferences": {
        "escalation_calculation": {
            "first_response_at": null,
            "last_update_at": "2019-01-14T15:50:28.000Z",
            "close_at": null,
            "sla_id": 1,
            "sla_updated_at": "2019-01-15T08:30:55.830Z",
            "calendar_id": 1,
            "calendar_updated_at": "2019-01-17T10:53:45.906Z",
            "escalation_disabled": false
        }
    },
    "updated_by_id": 3,
    "created_by_id": 3,
    "created_at": "2019-01-14T15:50:28.000Z",
    "updated_at": "2019-01-18T17:49:29.928Z",
	"tags": "gets,ignored,anyway",
	"article": {
        "type_id": 1,
        "sender_id": 2,
        "from": "LeTest <alias@secret.tld>",
        "to": "Users",
        "cc": null,
        "subject": null,
        "reply_to": null,
        "message_id": null,
        "message_id_md5": null,
        "in_reply_to": null,
        "content_type": "text/html",
        "references": null,
        "internal": false,
        "preferences": {},
        "updated_by_id": 3,
        "created_by_id": 3,
        "origin_by_id": 5,
        "created_at": "2019-01-14T15:51:50.000Z",
        "updated_at": "2019-01-14T15:51:50.341Z",
        "attachments": [],
        "type": "email",
        "sender": "Customer",
        "created_by": "alias@secret.tld",
        "updated_by": "alias@secret.tld",
        "origin_by": "test2@test.com"
    }
}

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