Contents

How to Create a Incident in Servicenow Using Servicenow API (Powershell and Python)

Below I’m sharing some simple methods to create Servicenow Incidents using JSONv2. Both scripts can be found in the following Github repository folder iservicenow/Incidents.

What is ServiceNow?

ServiceNow é uma plataforma baseada em nuvem que fornece soluções de gerenciamento de serviços de TI (ITSM) em nível empresarial. Ela foi projetada para automatizar e simplificar fluxos de trabalho de TI, como gerenciamento de incidentes, gerenciamento de problemas, gerenciamento de mudanças e gerenciamento de solicitações de serviço.

ServiceNow permite que as organizações de TI centralizem e gerenciem seus serviços de TI por meio de uma única plataforma integrada. Ela inclui uma ampla gama de recursos e módulos, como catálogo de serviços, gerenciamento de conhecimento, gerenciamento de ativos e gerenciamento de configuração.

Um dos principais benefícios do ServiceNow é sua capacidade de melhorar a eficiência e a produtividade, automatizando tarefas e fluxos de trabalho manuais. Ele também fornece visibilidade em tempo real das operações de TI, permitindo que as organizações monitorem e acompanhem o desempenho de seus serviços de TI.

Além do ITSM, o ServiceNow também oferece soluções para outras áreas da empresa, como RH, finanças e operações de segurança. Ele pode ser personalizado e configurado para atender às necessidades específicas de diferentes organizações e se integra a outros sistemas e ferramentas empresariais populares.

No geral, o ServiceNow é uma ferramenta poderosa para organizações que desejam simplificar suas operações de TI e melhorar a entrega de serviços de TI aos seus usuários.

Creating Incidents in Servicenow using Python

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import json
import requests
from requests.auth import HTTPBasicAuth

auth = HTTPBasicAuth("youruser@yourcompany.com", "Y#urPwd1234")
uri = "https://demo.service-now.com/incident.do?JSONv2"

headers = {
    "Accept": "application/json;charset=utf-8",
    "Content-Type": "application/json"
}

# define payload for request, note we are passing the sysparm_action variable in the body of the request
payload = {
    "sysparm_action": "insert",
    "category": "Infrastructure",
    "impact": "1",
    "urgency": "2",
    "short_description": "Automated ticket Short Description",
    "description": "Automated ticket Description",
    "cmdb_ci": "Email",
    "caller_id": "Allan Schwantd",
    "contact_type": "Email",
    "company_name": "CMPv2",
}

r = requests.post(url=uri, data=json.dumps(payload), auth=auth, verify=False, headers=headers)
content = r.json()
assert (r.status_code == 200)
print ("Response Status Code: " + str(r.status_code))
print ("Response JSON Content: " + str(content))

Creating Incidents in Servicenow using Powershell

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "youruser@yourcompany.com", "Y#urPwd1234")))
$headers.Add("Authorization", "Basic $base64AuthInfo")
$headers.Add("Content-Type", "application/json")

# define payload for request, note we are passing the sysparm_action variable in the body of the request
$body = @"
{
	"sysparm_action": "insert",
	"category": "Software",
	"impact": "1",
	"urgency": "2",
	"short_description": "Automated ticket Short Description",
	"description": "Automated ticket Description",
	"cmdb_ci": "Email",
	"caller_id": "Arnold Schwarzenegger",
	"contact_type": "Email",
	"company_name": "CompanyName"
}
"@

$response = Invoke-RestMethod 'https://myservicenowinstance.service-now.com/incident.do?JSONv2' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json