Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Integration/RESTMessageV2/Create Email POST/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Send Email via API:

This is a ServiceNow script that uses the sn_ws.RESTMessageV2 API to send an email via a REST endpoint. It is configured to send an email for the "Hacktoberfest 2025" event, addressing two specific users and linking the email to an incident record in ServiceNow.

Prerequisites:

A ServiceNow instance with a REST API endpoint for sending emails (/api/now/v1/email).
A valid user and password for basic authentication.
The script should be executed within a ServiceNow context (e.g., in a Business Rule, Script Include, or background script).

Installation and Usage:

Navigate to your script location (e.g., a Business Rule or background script).
Copy and paste the entire script into the script field.
Modify the variables to match your instance and requirements:
Endpoint URL: Replace instance_name.service-now.com with your actual instance name.
Credentials: Provide a valid username and password for the setBasicAuth method.
Recipient and Subject: Update the to array and subject in the body variable as needed.
Table and Record ID: Ensure the table_name and table_record_id correspond to an existing record in your instance.
22 changes: 22 additions & 0 deletions Integration/RESTMessageV2/Create Email POST/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://instance_name.service-now.com/api/now/v1/email');
request.setHttpMethod('POST');
//Eg. UserName="admin", Password="admin" for this code sample.
var user = '';
var password = '';
var body = {
"to": [
"admin@example.com",
"andrew.och@example.com"
],
"subject": "Hacktoberfest 2025",
"text": "Lets gooooooooooo!",
"table_name": "incident",
"table_record_id": "d71f7935c0a8016700802b64c67c11c6"
}
request.setBasicAuth(user,password);
request.setRequestHeader("Accept","application/json");
request.setRequestHeader('Content-Type','application/json');request.setRequestBody(JSON.stringify(body));
var response = request.execute();
gs.log(response.getBody());
gs.log(response.getStatusCode());
Loading