Postman Attachment API Example

guythatusesserv
Tera Contributor
  1. Create a new HTTP request
  2. Set type to "Post"
  3. Set URL to https://[INSTANCE_NAME].service-now.com/api/now/attachment/upload
  4. Add these headers:
    1. Accept = */*
    2. Content-type = application/json
  5. Switch to body tab, set to "form-data"
  6. Add these to body:
    1. table_name = [table name of record you want to attach the file to]
    2. table_sys_id = [sys_id of record you want to attach the file to]
    3. file = [upload a file]
      1. Change this type to "file" instead of text (see image below)
  7. Authorization - I'll give 2 ways to use basic auth
    1. Basic Auth - Unencrypted
      1. Open "Authorization" tab
      2. Set type to "Basic Auth"
      3. Add User Name and Password
      4. This will add "Authorization" to the headers tab after you click Send
    2. Basic Auth - Encrypted
      1. In the Authorization tab, set Type to "No Auth"
      2. Use the script below to encrypt your basic auth credentials
      3. In the headers, add "Authorization", set value to "Basic [INSERT OUTPUT OF SCRIPT]" 
  8. Click send

 

SCRIPT

var username = "my_username";
var password = "my_password";
encodedAuth = GlideStringUtil.base64Encode(username + ':' + password);
gs.print(encodedAuth);
 
BodyBodySet to type fileSet to type fileHeadersHeaders
1 REPLY 1

leontgiscombe
Giga Contributor

Hi,

 

Do you have a working example for powershell please? I have been looking at this thread SOLUTION - How to attach a file to a record using ... - Page 2 - ServiceNow Community

 

However this does not work for me as I need all the oauth2 string for the code to gather the access token.