How can I create a ticket or add a note to a ticket with an attachment using Powershell

Hello dear reader,

I hope you are well and safe

I am trying to add a note to a ticket with an attachment in Powershell but I always receive a 400 HTTP code (bad request)

I’ve already used a lot FreshService’s API and I always managed to make it work (adding note without attachment, creating service requests…).
But this time, attachments are really making me struggling a lot.

I’ve never send an attachment through an API (FreshService or something else) in any programming languages.
I’ve some problem understanding what should I send (type of object ?, path of the file ?, bytesof the files ?) in the body so FreshService’s API can recognize my file and I even tried to achieve that with other method (such as cURL) but I always failed.

If you have any tips or PowerShell code sample to help me, it would be very cool from you

Have a great day and stay safe



1 Like

Hello Lucas,
Good day!

Welcome to Freshworks Developer Community :smiley:

This link contains code samples ( with attachment use-cases ) for few programming languages -

I don’t have much experience with Powershell code, I will leave that part to others who might know :sweat_smile:.


Newbie to the whole Fresh universe, me & Google are pretty OK with Powershell.

What I’m attempting to do is, with PowerShell, using a Managed Identity on an Azure VM, mapped to an Az AD object, after having a ticket number in the mix from a support person, write a note to the Change, with the results of my validation script that runs against a newly created database in SQL Server.

Reading configuration out of an Azure SQL database, validating against SQL Server and writing to a PowerShell custom object.

1 piece left. The note on the change.

I would certainly appreciate anyone pointing me in a direction.

Thanks in advance for any pointing!

Hello @DisconentFSuser

Firstly, welcome to the Freshworks community :tada:
Thank you for reaching out here.

I wasn’t very clear as to what you were trying to achieve, with Fresh *, but my best guess is that you were trying to add a note to an existing ticket on Freshdesk, for which you have a ticket number?

If that is indeed the case, have you checked out the Create Note API yet to see if that may help you?

A similar API is available for Freshservice in case I got the product line wrong from your question.

Do let us know if you are able to get this working. All the best!

1 Like

Thanks Satwik!

Yes, yes, used that link to get where I am so far.
Unbelievable fast response too; I didn’t expect that.

Yes, yes, I am trying to post a note to an existing Change by change number, with Powershell.

I’ve made progress, meaning I got past credentialing with API-Key.
I’m using Invoke-RestMethod
Response I’m getting is:
StatusCode: 400
StatusDescription: Bad Request

I’m also using Powershell ConvertTo-Json.

I’m thinking that’s where the issue is.
I can hardly spell JSON, much less know what it is.

Output of the ConvertTo-JSON is (edited):

““note”: {“id”: X,“created_at”: “2022-04-29 16:43:29Z”,“updated_at”: “2022-04-29 16:43:29Z”,“body”: “\u003cdiv\u003e Database Validation Routine \u003c/div\u003e” ,“body_text”: “These are results”,“user_id”: xxxxxxxxxxx,
“notify_emails” : null”

Not sure what it’s supposed to look like, but I think this is where my issue lies.

Any guidance would be most appreciated.


Thanks for trying this out and updating this thread, @DisconentFSuser .

Since you mention trying to update a Change, it is now clear that you are working with Freshservice, not Freshdesk.

In that case, you want work with this Create Note API instead. No wonder you are receiving a 400 Bad Request.

Do you mind trying this one and letting us know how it goes?

Thanks for reaching out.

I have been using FreshService and that exact link you sent.

I’m trying to match the API key, instead of user name.

Eventually I want to run this as a service and create a new account to use the API.

I also know you keep referencing curl.

Here in the M$ world, its all Powershell.

Thanks again


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