Search code examples
pythonapigithubzenhub

How to set an issue pipeline with ZenHub API


We use ZenHub with our enterprise GitHub installation. I'm writing a script to move issues from one GitHub repo to another, including the ZenHub info. I've gotten the issues copied, labels and milestones set. I then use the ZenHub API to set estimates and create epics. All that works fine. My final step is to assign the issues to ZenHub pipelines. The following works fine (to get info about an issue):

zenhub_headers = {"X-Authentication-Token": "%s" % zenhub_token}
url = '%s/p1/repositories/%d/issues/15' % (zenhub_endpoint, repo)
response = requests.get(url, headers=zenhub_headers, verify=False)

However, when I attempt to move the same issue to a pipeline with the following:

params = json.dumps({"pipeline_id": "5a36d8584b9b9e57bc9729f9"} )
zenhub_headers = {"X-Authentication-Token": "%s" % zenhub_token}
url = '%s/p1/repositories/%d/issues/15/moves' % (zenhub_endpoint, repo)
response = requests.post(url, headers=zenhub_headers, data=params, verify=False)

I get a 400 with: b'{"message":"Invalid Field for pipeline_id: undefined"}'. I've verified that pipeline 5a36d8584b9b9e57bc9729f9 does exist in the target repo.

The API is still in a beta state. I'm wondering if this is a bug in the API or something I'm doing wrong.


Solution

  • Pablo from ZenHub here. The problem here is that the request is not well-formed. The position parameter is missing, and you don’t need to encode the request body as a string, you can just send the dictionary directly:

    import requests
    
    # No need to stringify
    params = {
        "pipeline_id": "5a36d8584b9b9e57bc9729f9",
        "position": "top"
    }
    
    # some code omitted here...
    
    response = requests.post(url, headers=zenhub_headers, data=params, verify=False)
    

    The documentation of the move issues endpoint is available here. Cheers,