How to add an attachment to a Change Note via Freshservice v2 API?

Hello,

Is it possible to add an attachment to a Change Note via the Freshservice v2 API ?

I was able to add the attachment via the UI. However, was not able to find any references to do the same via API in the docs - https://api.freshservice.com/#note_attributes.

1 Like

Hi @Dan

Can you please try with the below cURL ?

curl -X POST \
  https://domain.freshservice.com/api/v2/changes/{id}/notes \
  -H 'Accept: */*' \
  -H 'Accept-Encoding: gzip, deflate' \
  -H 'Authorization: Basic <base 64 encoded admin API key>' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Content-Length: 352' \
  -H 'Content-Type: application/json' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F body=hello \
  -F 'attachments[]=@/testfile.txt'

NodeJS request for the above cURL:

var request = require("request");

var options = { method: 'POST',
  url: 'https://domain.freshservice.com/api/v2/changes/{id}/notes',
  headers: { 
     'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW',
     'Content-Type': 'application/json',
     Authorization: 'Basic <base 64 encoded admin API key>',
     'Accept-Encoding': 'gzip, deflate',
     Accept: '*/*' },
  formData: { 
     body: 'hello',
     'attachments[]': { 
        value: 'fs.createReadStream("/path/to/file/testfile.txt")', // NOTE : this is file content
        options: { 
           filename: '/path/to/file/testfile.txt',
           contentType: text/plain } } } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);
  console.log(body);
});

Note : Request and fs npm modules might have been deprecated please use alternatives
Please reach out for any queries!

Thanks and Regards,
Mughela Chandresh

2 Likes

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