Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem in calling Service Now with custom API Name #189

Open
rlthompson-godaddy opened this issue Sep 30, 2022 · 1 comment
Open

Problem in calling Service Now with custom API Name #189

rlthompson-godaddy opened this issue Sep 30, 2022 · 1 comment

Comments

@rlthompson-godaddy
Copy link

I am trying to make a query to a custom API name in our servicenow instance like the following:

https://$COMPANY.service-now.com/api/now/on_call_rota/current?group_name=$GROUPNAME

However, am getting back empty responses or exceptions. I've tried the following methods:

import pysnow

snow = pysnow.client.Client(instance="$COMPANY", user="$USER", password="$PASSWORD")
oncall = snow.resource(api_path="/on_call_rota/current")
response = oncall.get(query={"group_name": "$GROUPNAME"})
response.all()

Which results in a 200, but the result is empty.

import pysnow

snow = pysnow.client.Client(instance="$COMPANY", user="$USER", password="$PASSWORD")
oncall = snow.resource(api_path="/on_call_rota/current")
oncall.request("GET", path_append="?group_name=$GROUPNAME"

which results in an exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/$USER/projects/.venv/lib/python3.8/site-packages/pysnow/resource.py", line 162, in request
    return self._request.custom(
  File "/home/$USER/projects/.venv/lib/python3.8/site-packages/pysnow/request.py", line 167, in custom
    self._url = self._get_custom_endpoint(path_append)
  File "/home/$USER/projects/.venv/lib/python3.8/site-packages/pysnow/request.py", line 83, in _get_custom_endpoint
    return self._url_builder.get_appended_custom(segment)
  File "/home/$USER/projects/.venv/lib/python3.8/site-packages/pysnow/url_builder.py", line 59, in get_appended_custom
    self.validate_path(path_component)
  File "/home/$USER/projects/.venv/lib/python3.8/site-packages/pysnow/url_builder.py", line 31, in validate_path
    raise InvalidUsage(
pysnow.exceptions.InvalidUsage: Path validation failed - Expected: '/<component>[/component], got: /?group_name=$GROUPNAME

How can I do this query?

@rlthompson-godaddy
Copy link
Author

Ok, I might have figured out my own question. This seems to work:

import pysnow

snow = pysnow.client.Client(instance="$COMPANY", user="$USER", password="$PASSWORD")
response = snow.session.get(f"{snow.base_url}/api/now/on_call_rota/current?group_name=$GROUPNAME")
response.json()

However, my question then becomes is the best way to handle this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant