API - create ticket with attachment JSON

I’m successful in using the API to create tickets.

I have a need now to add attachments with some tickets. I’ve reviewed the docs and see that it can be done with a PUT. Yet, the docs are vague after that. I’m not sure what the PUT JSON would look like because I do not see any examples.

I thought that I could create a ticket manually with an attachment and then GET it to look at the JSON. But that doesn’t provide much help.

I can mouseover the attachment in the web gui to see this - https://zammad/api/v1/ticket_attachment/ticket#/142003/216604?disposition=attachment

But I can’t really understand how I’d PUT a ticket with an attachment.

Does anyone have any examples of the JSON to create a ticket with attachment?

Can you please help me understand at which point the documentation gets vague in your opinion?

Are you saying that you can’t find the relevant information listed?

1 Like

Maybe I’m confused. Is an Article a Ticket? Or a sub-item of a Ticket? And then an Attachment has to be a part of an Article?

And, in your Articles link above… it appears the Ticket needs to be created first, and then an Article with Attachment can be added/updated to it. Is this correct?

I think this is where my confusion is coming from.

What I’m trying to accomplish is this - We are working on a Tech return process for creation of a UPS shipping label PDF (currently via CSV on UPS, future via API). The label needs to have a Ticket # in a Reference line.
Then we can to keep a copy of this PDF of the UPS shipping label in an open Ticket. We’re just looking for the most efficient method to create the Ticket, note the ticket #, put that in the UPS label creation Ref line (manual CSV process), then attach those labels back into the tickets.

hi!
Tickets are containers for articles.
Here a visualization of the data structure

1 Like

I wanted to piggy back on this post because I am also having trouble attaching a PDF file to an article to update a ticket. I’m able to make tickets with the API, but what specifically do you need to pass to tell the location/file path of the pdf I want to attach?

The documentation says it’s identical to “POST”, but I’m getting confused because it still seems like I need to provide the API with more data, like a file path?

Thank you for all the help in advance! I can provide more info if needed!

Here’s the Python code I’m using (Currently throwing 500 Internal Server Error). I may not be using the Requests or File objects correctly but any help on what I’m doing incorrectly would be greatly appreciated!!

    update_params = {
    "title": "update Test title",
    "state": "open",
    "priority": "2 normal",
    "article": {
        "subject": f"update Test subject {update_type}",
        "body": "RMS Test body",
        "internal": True
        }
    }
sl_file_obj = open(d['attachment'], "rb").read()
message_files = {'attachment': sl_file_obj}
response = requests.request("PUT", ticket_url, headers=zammad_headers, json=update_params, files=message_files)

Andrew

Quick update, I think I found my problem…

I’m going to look more into the article endpoint and report back if I have issues. Thanks so much for the info @MrGeneration !!!

1 Like

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