Rest api - add issue to epic

Hi,

Im working with some automation so we can import network vulnerability scan results into a zenhub board. Im using both the github and zenhub rest APIs to get the results I need. Each vulnerability from our scan results corresponds to a github issue. Im also creating Epics via the zenhub api to group multiple issues. My problem is adding an issue to an epic - I just cannot get the zenhub api to add a current issue to a current epic. Ive tried multiple ways to form the request based on the documentation in the “add-or-remove-issues-to-epic” section of the ZenhubIO/API documentation.

I can create the endpoint ok but when trying to form the request body I run into trouble. From the API documentation outlined above it says I need to create one object (issue) within an array (array of issues) within an object (add_issues). Im doing this with powershell using hashtables to form the key/value pairs and a powershell array - then converting the result to json. I end up with this:
{
“add_issues”: [
{
“repo_id”: 12345,
“issue_number”: 123
}
],
“remove_issues”: [
{}
]
}

This is an example request body according to the documentation:
{
“remove_issues”: [{ “repo_id”: 13550592, “issue_number”: 3 }],
“add_issues”: [
{ “repo_id”: 13550592, “issue_number”: 2 },
{ “repo_id”: 13550592, “issue_number”: 1 }
]
}

" * add_issues is an array that indicates with issues we want to add to the specified Epic. They should be specified as an array containing objects with the issue’s repo_id and issue_number."

To me they seem pretty identical in json terms…but when the request is executed the response comes back empty.
@{removed_issues=System.Object; added_issues=System.Object}

Ive used to hashtables to form request bodies for other Zenhub API requests (move issue to another pipeline) and it has worked fine. Granted I have not done one whereby I have a hashtable within an array within a hashtable before.

Any help or assistance greatly appreciated!

Hey Donal-keane!

We’ve actually got a new GraphQL Public API that may work better for your use case. I understand that REST and GraphQL are fundamentally different, but I think it’s worth taking a look at the documentation which can be found at https://developers.zenhub.com/

We’ve also got a specific page outlining the equivalent queries for GraphQL from our REST API. Here is a link to access the sample queries for Epics Moving from REST to GraphQL | Zenhub Developers