How to create ticket with attachment?

Hi. I want to import some tickets along with attachments from another freshservice tenant.
I have an export of the attachments containing the following info:

ticket_id	54
id	21000006173
created_at	2022-06-21T09:14:03Z
updated_at	2022-06-21T09:14:07Z
name	UOS_CHN-68.pdf
content_type	application/pdf
size	178568

The create ticket documentation (Service Desk API for Developers | Freshservice) just says “array of attachments” as the attachment input. Can you clarify how I could import the above example alongside the ticket? (a curl example would be amazing)

Many thanks,
Michael D

Hi @dawsonweb

Following is from the Create Ticket API documentation

curl -v -u -F 'attachments[]=@/Users/user/Desktop/api_attach.png' -F 'subject=Support Needed...' -F 'description=Details about the issue...' -F '' -F 'priority=1' -F 'status=2' -X POST ''

In order to create ticket with attachment using the API, you need to download the attachments locally and then use the create ticket API as shown in example.

1 Like

Thanks @Sachin_Kumar can you tell me is each element of the attachments array a base64 encoded string?


Each element of the attachment array is the local file path.

Apologies i’m not being very clear. I’m actually using PowerShell to invoke the Post request to create a ticket with attachment. See below…

    foreach ($ticket in $tickets) {

        $body = @{
            "description" = $ticket.description
            "subject"     = $ticket.subject
            "email"       = $
            "priority"    = $ticket.priority
            "status"      = $ticket.status
            "attachments" = $data
        } | ConvertTo-Json
        $header = @{
            "Content-Type"  = "application/json"
            "Authorization" = "Basic azcyRk1tMk8zSUIyaDFMakE4bE06WA=="
        Invoke-RestMethod -Uri "" -Method 'Post' -Body $body -Headers $header | ConvertTo-HTML


Invoke-Restmethod supports an -Infile parameter, I just can’t understand how I need to encode the attachment in the same way curl does to Post it.

Thanks so much for your help.

Hi @dawsonweb

I am not so familiar with PowerShell however to create a ticket with attachment we need to set the header “content-type” as “multipart/form-data”.
I looked on internet and looks like PowerShell does not have the ability to do so.
Found one topic in stackoverflow on sending files using PowerShell and REST API.

Hope this helps.

1 Like