insomniacc / PSSnow

A powershell module for interacting with the ServiceNow REST API
GNU General Public License v3.0
41 stars 9 forks source link

Create a new Incident #56

Closed twproject closed 10 months ago

twproject commented 10 months ago

Could you help me to use New-SNOWIncident with some custom fields, see attachments

image

How I can fill the catalog item and the ICT Operation Service?

After successfull auth i tried the a New-SNOWIncident with no luck

PS C:\Windows\system32> New-SNOWIncident -caller "checkMK" -short_description "ticket short desc" -description "prova123"  -verbose
VERBOSE: POST https://careldev.service-now.com/api/now/v2/table/incident with -1-byte payload
Invoke-SNOWTableCREATE : The remote server returned an error: (403) Forbidden. [https://careldev.service-now.com/api/now/v2/table/incident]
At line:5520 char:9
+         Invoke-SNOWTableCREATE -table $table -Parameters $PSBoundPara ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-SNOWTableCREATE
insomniacc commented 10 months ago

'403 Forbidden' - This is a permission related error message. I would lookup the official docs for the API and read up on the headings covered by 'REST API Security', 'REST API Roles' etc. It appears that whatever account you're using the access the API does not have write permission to that table.

If you have the ability in dev, for testing purposes, I would give the account full admin permissions and see if it still persists, if it doesnt you know for sure it's permission related, at which point you can remove admin and strip it back to what is required - although I'm not sure what you'd need on that front, each instance is configured different and i'm a little rustry, havent worked with SNOW for quite some time now.

insomniacc commented 10 months ago

Regarding how to fill those custom fields, I'd refer you to the docs for this module: https://github.com/insomniacc/PSSnow/blob/main/docs/UserGuide.MD#new-snowobject

Take a look at using a hashtable and the -properties parameter.

twproject commented 10 months ago

Thanks for the quick tips, the user had the correct rights and with New-SNOWObject i'm now able to create the incident.

I'll test again with New-SNOWIncident but I don't understand if with this function i'm able to fill custom fields.

insomniacc commented 10 months ago

@twproject - I think you may be confusing my comment a little, so the document I referenced for New-SnowObject was'nt a suggestion to use that (even though you can), but more so, it was reference documentation for how to use New-SNOWIncident (under the hood it's the same thing). New-SNOWIncident just has specific parameters and certain intellisense that New-SNOWObject wont have.

Either way, you can use either function, and the method to update custom fields is exactly the same. You'll need to use the -Properties parameter with the fields you wish to update.

For example -Properties @{customfield1 = "value1"}

Hope this clears up the confusion!

twproject commented 10 months ago

ok thanks i'll go deeper into New-SNOWIncident and i'll rewrite my test code before going into production.

Thanks a lot for the big help!!