Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Upload an attachment into ServiceNow

kjmauriello
Mega Expert

I am writing an integration and receiving JSON in a scripted REST API.

Part of the inbound JSON has an attachment url, a long string starting with https://.......

When I click the url the file downloads to my local system properly, How do I take that url and add the attachment to the sys_attachment table in ServiceNow.

I will know the SN table and sys_id, the JSON also has the content type, I am not sure how to get the attachment into ServiceNow.

3 REPLIES 3

SanjivMeher
Mega Patron
Mega Patron

You should be able to use the out of box attachment API in Servicenow

 

find_real_file.png


Please mark this response as correct or helpful if it assisted you with your question.

Thats what I thought, but I keep getting a bad content type.

But when I take the file url and place it in a browser the file downloads properly.

{
  "error": {
    "message": "Invalid file type: application/vnd.openxmlformats-officedocument.wordprocessingml.document",
    "detail": null
  },
  "status": "failure"
}

These are the parameters for the url that is passed to me in the JSON
?X-Amz-Algorithm=AWS4-HMAC-SHA256
&X-Amz-Credential=ASIAU2ZWJDBAA6YVVMK3%2F20181013%2Fus-east-1%2Fs3%2Faws4_request
&X-Amz-Date=20181013T134429Z
&X-Amz-Expires=86400
&X-Amz-Security-Token=FQoGZXIvYXdzEPH%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaDN60ChXrDXPpTsn0HCK3A5WxDBWg9%2BI2IMBsNQN0ljNftDoWnLn6%2Fnax29LOJ7%2BF8woB8BBoEOXkMabdKFXJTvPuE8S797FcyYZVFJBTZ%2FhzM4Z0%2Bkypuew8gEPUW47Y7UBkRvHZkNa92iSJ7Gi8GFkhSEjOs%2Fk10zmAZmk8odd1nlDMx23KIJl25wSa8mwqItX1llheD7j7J%2FX1h99r9X7GGdK6gVHnprXPLtqZ%2Fk%2Fgk6WNg5BEMRs2L6NrLx6t%2FxoiWSv6AjqJxM5ULNT76bVJ7yIZCdEQg3HFI9bZg15dhJiYuDq9qHh7Ght71lN%2F8ST9KAwcOXyX1ZvK%2BUW6ym8vwEXl%2B1SZF0hgaXRS4rQUAv7cpZSKx8T4Q9UnGE7l1ZiV8D6A29r0hjFjsBA6lKncITtyF7Rv34J0BfmsvUq4yVT603dHfTtz4MhXyMq4iPMmsqQnTi%2FrRt2Z2ZHB%2BXn9JPJo45C7ayRAlYByyTjsprKXxwYNmU0pnw%2F6%2FNkisz3ykQFjcPLLD%2BaCmDZaXK12%2Bh7P1IxjXySmhD%2BVWfUq36zothg9hTpL2PVgixrSBlC5zI%2Fdav%2BpK3JFPHrNVyIgcKueT%2BQoz8yG3gU%3D
&X-Amz-Signature=479bd05b1b2f18ea0fc7baef425f0676f3f6d5587dd68892728c7583dadc6c8f
&X-Amz-SignedHeaders=Host

find_real_file.png

I added a Request Body paramater of Location (the value is the full https URL).  When I did that I received a 200 status and a file was attached to the incident record.  However, the file is corrupt.  It is a docx file and I am using a content-type of application/vnd.openxmlformats-officedocument.wordprocessingml.document.

Any ideas??