Send attachment through REST API if Content-Type is Multipart/form-data

aks4
Tera Contributor

Hi

I am trying to integrate Freshdesk with ServiceNow using REST API. We have a requirement to create a ticket along with attachment. We have configured a REST Message and a post method to do so. I am able to create a ticket without attachment using normal content-type as application/json. We have to send the attachments also from the incident to Freshdesk ticket using the same method. 

Now the issue is, we have to send the data as Content-type - Multipart/form-data

I have tried changing application/json to multipart/form-data but its not being sent

Alternatively, I have created a REST Action using Flow Designer to send the same data but the same error 400.

Freshdesk supports attachment picked up from Local machines as File type.

I am able to create the ticket with attachment using postman. I checked the code and it uses variable new formdata() which does not work inn ServiceNow script include or business rule.

Appreciate your suggestions

 

6 REPLIES 6

aks4
Tera Contributor

@Ankur Bawiskar 

Thanks for the suggestion links. I tried creating a Scripted REST API and a script include to convert the attachment in multipart/form-data. But it's still not working. Not sure how do I test it further.

I need to build a payload of Content-Type : multipart/form-data, which should have contain email and attachment. 

I am able to do it with postman but tried every possible way. I even built a REST Action using Flow Designer to send Multipart but it's not working.

 

find_real_file.png

 

Could you please take a look at it.

Hi,

in postman you are using form-data for POST

But I believe you need to use content body containing JSON from ServiceNow

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

aks4
Tera Contributor

@Ankur Bawiskar I am not able to generate that JSON which can be sent. I tried several ways to generate JSON containing EMail and Attachment but that is not working. Not sure how can I convert my attachment to form data type and Email in it to encode as JSON and send it. I tried using IntegrationHUB as well but it is always giving Error 400.