The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to add a sys_attachment from another ServiceNow instance programmatically

Dattatreya Trip
ServiceNow Employee
ServiceNow Employee

Hi All,

I have a use case, where I need to insert a .PEM file as a sys_attachment in a ServiceNow instance from another ServiceNow instance programmatically. I also, need to send the "table_sys_id" field of the sys_attachment to be inserted programmatically. Can SMEs please provide ways to achieve this?

Please let me know if any additional info is required.

2 REPLIES 2

Ratnakar7
Mega Sage
Mega Sage

Hello @Dattatreya Trip ,

 

To insert a .PEM file as a sys_attachment in a ServiceNow instance from another ServiceNow instance programmatically, you can use ServiceNow's REST API. Here are the steps you can follow:

 

  1. First, you need to authenticate with the instance you want to insert the attachment into. You can do this by sending a POST request to the instance's endpoint with the appropriate credentials.
  2. Once you have authenticated, you can use the '/api/now/attachment/file' endpoint to upload the attachment. You will need to include the following information in your request:
    • The file contents in the request body
    • The file name in the 'file_name' parameter
    • The table_sys_id field in the 'table_sys_id' parameter
    • The table name in the 'table_name' parameter
  3. Finally, you can check if the attachment was successfully uploaded by sending a GET request to the '/api/now/attachment' endpoint with the appropriate parameters.

I hope this helps! Let me know if you have any further questions.

 

Thanks,

Ratnakar

Thanks for the response. Will give it a try.