Create a Standard Change request via custom REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2023 09:59 AM
Create a Standard Change request via custom REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2023 02:49 PM
To create a standard change request via a custom REST API, you can create a Scripted REST API in ServiceNow that accepts the necessary parameters and then creates a change request record. Here's a step-by-step guide to creating a Scripted REST API for this purpose:
Step 1: Create a Scripted REST API
- In ServiceNow, navigate to "System Web Services > Scripted REST APIs" and click "New".
- Provide a name and an API ID for your new Scripted REST API, then click "Submit".
- Click on "Resources" under the Related Links, then click "New".
- Provide the following details for the new resource:
- HTTP Method: "POST"
- Name: "Create Standard Change Request"
- Script:
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) { var requestBody = request.body.data; // Input validation if (!requestBody.short_description || !requestBody.description || !requestBody.assignment_group || !requestBody.requested_by) { response.setStatus(400); response.setBody({ status: 'error', message: 'Missing required parameters. Ensure short_description, description, assignment_group, and requested_by are provided.' }); return; } // Create the standard change request var changeRequest = new GlideRecord('change_request'); changeRequest.initialize(); changeRequest.short_description = requestBody.short_description; changeRequest.description = requestBody.description; changeRequest.assignment_group = requestBody.assignment_group; changeRequest.requested_by = requestBody.requested_by; changeRequest.type = 'standard'; // Set the change request type to "standard" changeRequest.setValue('state', 1); // Set the state to "New" var changeRequestSysId = changeRequest.insert(); response.setStatus(201); response.setContentType('application/json'); response.setBody({ status: 'success', message: 'Standard change request created.', change_request_sys_id: changeRequestSysId }); })();
- Click "Submit" to save the resource.
Step 2: Call the Scripted REST API
You can now call the custom Scripted REST API to create a standard change request. Here's an example of calling the API using a REST client:
- Endpoint: https://your_instance.service-now.com/api/your_api_id/create_standard_change_request
- HTTP Method: POST
- Headers:
- Content-Type: application/json
- Authorization: Basic base64(username:password) (Replace base64(username:password) with the Base64-encoded value of your ServiceNow username and password)
- Body:
jsonCopy code { "short_description": "New Standard Change Request", "description": "This is a description of the standard change request.", "assignment_group": "assignment_group_sys_id", "requested_by": "requested_by_user_sys_id" }
Replace the placeholders in the endpoint and body with the actual values. The Scripted REST API will create a new standard change request with the provided parameters and return a response containing the sys_id of the created change request.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2023 11:54 PM
Hello,
Here is a link to the documentation for ServiceNow's Rest API for Change Management. Change Management API.
Utilizing this will spare you the need to create a custom end-point.
For Standard Change you could use the following method as this is based on a template:
POST /sn_chg_rest/change/standard/{standard_change_template_id}