30. ServiceNow Outbound REST API
1 .Pre-requisites
- Be familiar with the REST API and the parameters it accepts before attempting to define a REST message in a ServiceNow instance
- Role required to access System Web Services modules : web_service_admin
- REST API explorer
2. Rest explorer : Outbound Message
Note: HTTP Headers
- Accept : application/json
- Content-Type: application/json
- User-Agent : ServiceNow
2. REST APIs
2.1 Get customer request by id or key
- API : GET /rest/servicedeskapi/request/{issueIdOrKey}
- Returns the customer request for a given request Id/key.
- Authentication : Basic ( UserName and password)
- Accept : application/json
- Content-Type : application/json
- User-Agent : ServiceNow
- Response: json response with issue details
For example: http://empyratestjira.eastus.cloudapp.azure.com/rest/servicedeskapi/request/SNOW-1
- SNOW-1 is the name of the ServiecDesk Issue Number.
- Method : GET
2.2 Create customer request
POST /rest/servicedeskapi/request
Description : Creates a customer request in a service desk. The service desk and request type are required. The fields that are mandatory for the request type are also required
Authentication : Basic ( UserName and password)
- Accept : application/json
- Content-Type : application/json
- User-Agent : ServiceNow
- Response: Json response of created issue in Jira SD
For example : http://empyratestjira.eastus.cloudapp.azure.com/rest/servicedeskapi/request
Authorization: basic
Accept : application/json
Content-Type : application/json
User-Agent : ServiceNow
HTTP Query Parameters: Content
{
"serviceDeskId": "6",
"requestTypeId": "63",
"requestFieldValues": {
"summary": "Request JSD help via REST",
"description": "I need a new mouse for my Mac"
},
"requestParticipants": [
"admin"
]
}
Note:
- serviceDeskId : Project Id
- requestTypeId : Request Type Id
2.3 Update Customer Request
POST /rest/api/2/issue/SNOW-1
Description : Updates customer request in a service desk. The service desk and request type are required. The fields that are mandatory for the request type are also required
Authentication : Basic ( UserName and password)
- Accept : application/json
- Content-Type : application/json
- User-Agent : ServiceNow
For example : http://empyratestjira.eastus.cloudapp.azure.com/rest/api/2/issue/SNOW-1
Authorization: basic
Accept : application/json
Content-Type : application/json
User-Agent : ServiceNow
HTTP Query Parameters: Content
{
"fields": {
"summary": "Update the Jira Service Desk request"
}
}
**Note: At present, there no service desk api to update the service request. We have to use standard Jira REST API to update the issue with issue key
2.4 Business Rules
- Create Business Rule
- When to run
- Actions
- Advanced
Sample Code
var r = new sn_ws.RESTMessageV2('JIRA ServiceDesk', 'Create Issue');
r.setStringParameter("serviceDeskId","6");
r.setStringParameter("requestTypeId","63");
var requestBody ='{"serviceDeskId":"${serviceDeskId}","requestTypeId":"${requestTypeId}","requestFieldValues": {"summary": "'+current.short_description+'","description": "'+current.description+'"},"requestParticipants": ["admin"]}';
r.setRequestBody(requestBody) ;
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.log(responseBody);