nbalas
nbalas

Reputation: 1263

create_hook Validation Error 422

I have been playing with the parameters for awhile now but I continue to get the same 422 Validation Error. I am using runscope to test if my webhooks work.

url_path = "https://k1lavjuzlcvj.runscope.net"

repo.create_hook(name="testhook",config={"url":url_path, "content_type":"json"})

This is the stack output that I receive from this call

09-29 13:35 github3      DEBUG    POST https://github.umn.edu/api/v3/repos/umn-csci-2041F14/testbalas/hooks with {"name": "testhook", "active": true, "config": {"content_type": "json", "url": "https://k1lavjuzlcvj.runscope.net"}, "events": ["push"]}, {}
09-29 13:35 requests.packages.urllib3.connectionpool DEBUG    "POST /api/v3/repos/umn-csci-2041F14/testbalas/hooks HTTP/1.1" 422 113
09-29 13:35 logger       ERROR    Failure while setting hook for testbalas:
Traceback (most recent call last):
  File "./createurlhooksbyuid", line 107, in <module>
    repo.create_hook(name="testhook",config={"url":args.url, "content_type":"json"})
  File "/Users/nate/Git-Projects/administration/dependencies/github3.py/github3/decorators.py", line 38, in auth_wrapper
    return func(self, *args, **kwargs)
  File "/Users/nate/Git-Projects/administration/dependencies/github3.py/github3/repos/repo.py", line 613, in create_hook
    json = self._json(self._post(url, data=data), 201)
  File "/Users/nate/Git-Projects/administration/dependencies/github3.py/github3/models.py", line 100, in _json
    if self._boolean(response, status_code, 404) and response.content:
  File "/Users/nate/Git-Projects/administration/dependencies/github3.py/github3/models.py", line 121, in _boolean
    raise GitHubError(response)
github3.models.GitHubError: 422 Validation Failed

Any help would be appreciated, thank you!

Upvotes: 0

Views: 996

Answers (1)

Ian Stapleton Cordasco
Ian Stapleton Cordasco

Reputation: 28757

I just had a chance to test this. If you inspect the response you receive from GitHub you'll see the following:

>>> e.response.json()
{u'documentation_url': u'https://developer.github.com/v3/repos/hooks/#create-a-hook', u'message': u'Validation Failed', u'errors': [{u'field': u'name', u'code': u'invalid', u'resource': u'Hook', u'value': u'requestbin'}]}

If you then look back to the documentation more closely, you'll see the name of the example hook is "web". When I change the name of my hook to "web", the hook creation works.

To be clear, to fix this change your create_hook call to:

repo.create_hook(name="web",config={"url":url_path, "content_type":"json"})

Upvotes: 2

Related Questions