Powershell script RestAPI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2017 07:35 AM
Hi ,
Using powershell scripts I need to insert data into INCIDENT table using REST API .
Please let me know how to achieve this ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2017 05:51 AM
Hi try this:
$SNowUser = "USERNAME"
$SNowPass = ConvertTo-SecureString —String "PASSWORD" —AsPlainText -Force
$SNowCreds = New-Object —TypeName System.Management.Automation.PSCredential —ArgumentList $SNowUser, $SNowPass
$headers = @{ Accept = "application/xml" }
$uri "https://YOR-LINK.servicenow.com/api/YOURS_API"
$method = "POST" # to Create Incident use POST , to update use PATCH
$body = @{ #Create body of the POST request
description= "Simple API Test"
}
$bodyJson = $body | ConvertTo-Json
Invoke-RestMethod -Credential $SNowCreds -Headers $headers -Method $method -Uri $uri -Body $bodyJson -ContentType "application/json"
$response.result
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2017 07:34 AM
Hi ,
Thanks for your response .
I am able POST (add) the entry but I am unable to update the same with the web_service_admin, rest_api_explorer roles .
Only with Admin role I am able to update (PUT or PATCH) .
May I know how to resolve this ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2017 07:42 AM
Only with Admin role I am able to update (PUT or PATCH) .
That's incorrect - check the ACLs for table accessibility. You'll find there are a number of roles that can perform updates (e.g.: itil role).
Your best bet is to create a separate role that has write access to this table and confer that to the account being used for the API call.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2017 08:22 AM
Hi Dave ,
Current I have default permissions . I did not make any changes to the ACLs.
I tried with all the roles like web_service_admin, rest_api_explorer and ITIL but while updating I am getting 403 Forbidden error .
I believe I am having write access to the table as I am able to POST (add) the entry in incident table but only problem with updating the record .