Giter VIP home page Giter VIP logo

Comments (6)

rbw avatar rbw commented on July 22, 2024

Hello!

Are you getting a 400 back? Do you have an example?

I'm pretty sure the SN REST API previously, when this library was first built, sent a 2xx response back upon those types of errors (bad request / malformed body), instead of a 400, and included the error in the OK-response.

Perhaps this behavior has changed in more recent versions of the SN API. The documentation still doesn't mention anything about 400 errors on POST requests, as far as I can see.

Anyway - I'll do some testing and look into this. Thanks for reporting :)

from pysnow.

sandwormusmc avatar sandwormusmc commented on July 22, 2024

Hey there. I was kind of stumbling in the dark without knowing the data policy for the payload, so I was getting quite a few of these errors in my initial attempts, before I got access to their API Explorer and realized there was more to the error than I originally thought.

To start with, I didn't know what was necessary in the payload to open an incident in ServiceNow. After some poking, I was just getting back the default errors from the API about unexpected response codes (403 in my case).

As an example, if I comment out some required values from my payload, with the updates I mentioned above I get some useful details back, rather than just the UnexpectedResponse message.

With the script as is, you can possibly reproduce the error by calling insert(table='incident',payload=payloadWithMissingRequiredData) and get a 403 back.

In my case, the following are required fields to open an incident:

category
description
caller_id
u_impacted_service
cmdb_ci
subcategory
impact
severity
contact_type
priority
location
assignment_group
short_description
urgency
u_affected_user

Here is the output when I include all of the required fields:

[me@somewhere ~]$ python openone.py 
{'impact': 3, 'subcategory': 'Service Request', 'caller_id': u'33115a0d3d2d0600f4a09f32609319a2', 'u_impacted_service': u'1b66b8ed6f0a46007dce01dfde3ee4a0', 'cmdb_ci': u'1b66b8ed6f0a46007dce01dfde3ee4a0', 'description': 'A much longer description', 'category': 'Inquiry/Help', 'severity': 3, 'contact_type': 'Other', 'priority': 3, 'location': u'4e472b3f6f6102007dce01dfde3ee4cd', 'assignment_group': u'630c048e6ff94200cec3f941be3ee4c2', 'short_description': 'some request from someone with some team', 'urgency': 3, 'u_affected_user': u'33115a0d3d2d0600f4a09f32609319a2'}
INC0697332

And below is the output when I omit short description and affected user. Without the updates above all I get is the Expected: 201, got 403.

[me@somewhere ~]$ python openone.py 
{'impact': 3, 'subcategory': 'Service Request', 'caller_id': u'33115a0d3d2d0600f4a09f32609319a2', 'u_impacted_service': u'1b66b8ed6f0a46007dce01dfde3ee4a0', 'cmdb_ci': u'1b66b8ed6f0a46007dce01dfde3ee4a0', 'description': 'A much longer description', 'category': 'Inquiry/Help', 'severity': 3, 'contact_type': 'Other', 'priority': 3, 'location': u'4e472b3f6f6102007dce01dfde3ee4cd', 'assignment_group': u'630c048e6ff94200cec3f941be3ee4c2'}
Traceback (most recent call last):
  File "openone.py", line 53, in <module>
    response = snobj.insert(table='incident',payload=ourpayload)
  File "/usr/lib/python2.7/site-packages/pysnow.py", line 99, in insert
    return r.insert(payload)
  File "/usr/lib/python2.7/site-packages/pysnow.py", line 165, in insert
    return self._get_content(response)   # @TODO - update to return first key (API breakage)
  File "/usr/lib/python2.7/site-packages/pysnow.py", line 260, in _get_content
    content_json['error']['detail']))
pysnow.UnexpectedResponse: Unexpected HTTP response code. Expected: 201, got 403. 
Error: Operation Failed
Details: Data Policy Exception:  Short description is mandatory, Affected User is mandatory

from pysnow.

rbw avatar rbw commented on July 22, 2024

I've been away for awhile but now looking into this again.
And thanks for the really good input. I'll have this implemented asap.

from pysnow.

sandwormusmc avatar sandwormusmc commented on July 22, 2024

from pysnow.

rbw avatar rbw commented on July 22, 2024

Implemented in d113137 , which will be released in version 0.2.2.

message and detail will be accessible in the UnexpectedResponse exception object using error_summary and error_details.

Also, documentation and examples coming up.

from pysnow.

rbw avatar rbw commented on July 22, 2024

Fixed.

from pysnow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.