diff --git a/Integration/RESTMessageV2/Create Email POST/README.md b/Integration/RESTMessageV2/Create Email POST/README.md new file mode 100644 index 0000000000..ff01190134 --- /dev/null +++ b/Integration/RESTMessageV2/Create Email POST/README.md @@ -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. diff --git a/Integration/RESTMessageV2/Create Email POST/script.js b/Integration/RESTMessageV2/Create Email POST/script.js new file mode 100644 index 0000000000..8a777e6fbd --- /dev/null +++ b/Integration/RESTMessageV2/Create Email POST/script.js @@ -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());