API Call through powershell/vbs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2017 02:58 AM
Hello experts,
Is there an API Key/call we could use to pull data from Service now, specifically just tickets/incidents per user. Either via Powershell/vbs or PHP?
If it is possible can I have some links which could guide me in a proper direction?
Thanks
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2017 04:15 AM
Hi Khozema,
Yes ServiceNow provides table api using which you can expose the table and get values from particular record.
EndPoint - https://instanceName.service-now.com/api/now/table/incident?sysparm_query=number=INC0010062
Method - GET
Authentication - give username and password
sysparm_query give it as per your need and check the response
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2017 04:29 AM
Hi Khozema,
Following is the example using PHP using cURL library. I have fetched information from incident table where number is INC0010062
What is cURL library:
1) name of package on server
2) used to access data from outside web pages
3) mostly used for accessing third party systems using API
4) supports http, https protocol
Execute it here online to verify: Free Online IDE and Terminal
past the php code and execute it
Sample php Code:
<html>
<head>
<title>Online PHP Script Execution</title>
</head>
<body>
<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://instanceName.service-now.com/api/now/table/incident?sysparm_query=number=INC0010062");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl,CURLOPT_USERPWD,"rest.user:rest.user"); // username:password format
$result = curl_exec($curl);
curl_close($curl);
print($result);
?>
</body>
</html>
Sample output:
<body>
{"result":[{"parent":"","made_sla":"true","caused_by":"","watch_list":"6816f79cc0a8016401c5a33be04be441,e0459c414f962200fc11fa218110c726","upon_reject":"cancel","sys_updated_on
":"2017-08-18 12:52:33","child_incidents":"0","approval_history":"","skills":"","number":"INC0010062","resolved_by":"","sys_updated_by":"admin","opened_by":{"link":"https://instanceName.service-now.com/api/now/table/sys_user/6816f79cc0a8016401c5a33be04be441","value":"6816f79cc0a8016401c5a33be04be441"},"user_input":"","sys_created_on":"2017-08-18 12:52:33
","sys_domain":{"link":"https://instanceName.service-now.com/api/now/table/domain/09ff3d105f231000b12e3572f2b4775d","value":"09ff3d105f231000b12e3572f2b4775d"},"state":"1","task_fo
r":"","sys_created_by":"admin","knowledge":"false","order":"","calendar_stc":"","closed_at":"","cmdb_ci":"","impact":"3","active":"true","work_notes_list":"","business_service"
:"","priority":"5","sys_domain_path":"!!!/!!!/!!#/","rfc":"","time_worked":"","expected_start":"","opened_at":"2017-08-18 12:52:33","business_duration":"","group_list":"","vz_r
elease_for_test_datetime":"","work_end":"","caller_id":"","resolved_at":"","approval_set":"","subcategory":"","work_notes":"","short_description":"Incident created from web ser
vice","close_code":"","correlation_display":"","work_start":"","assignment_group":"","additional_assignee_list":"","business_stc":"","description":"","calendar_duration":"","vz
_release_for_test":"","close_notes":"","notify":"1","sys_class_name":"incident","closed_by":"","follow_up":"","parent_incident":"","sys_id":"19d1eed74fe40300fc11fa218110c768","
incident_state":"1","urgency":"3","problem_id":"","u_dell_correlation_id":"","company":"","reassignment_count":"0","activity_due":"","assigned_to":"","severity":"3","comments":
"","approval":"not requested","sla_due":"","comments_and_work_notes":"","due_date":"","sys_mod_count":"0","reopen_count":"0","sys_tags":"","u_my_currency":"0","escalation":"0",
"upon_approval":"proceed","correlation_id":"","location":"","category":"inquiry"}]}</body>
</html>
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2017 04:42 AM
Hi Khozema,
The REST api explorer can generate powershell code for you
# Eg. User name="admin", Password="admin" for this code sample.
$user = "admin"
$pass = "admin"
# Build auth header
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user, $pass)))
# Set proper headers
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Authorization',('Basic {0}' -f $base64AuthInfo))
$headers.Add('Accept','application/json')
# Specify endpoint uri
# Specify HTTP method
$method = "get"
{request.body ? "$body = \"" :""}}
# Send HTTP request
$response = Invoke-WebRequest -Headers $headers -Method $method -Uri $uri
# Print response
$response.RawContent
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2017 04:49 AM
Also you can use the REST Aggregate api to pull back stats for the incident table - and generate the powershell code in the same way as my earlier update..