debuggitMinor
Github rest api post label gives error for array input
Viewed 0 times
resterrorarraygithubinputpostgivesforlabelapi
Problem
We are hosting GitHub enterprise for our development. I am able to access the reset api and create jira, create PR etc.
When I try to add label to my PR, it gives error for array.
I check,
```
curl -u githuser:gittoken -X GET \
https://api.github.mycompany.com/repos/team/repo/labels
[
{
"id": 163461,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/+1",
"name": "+1",
"color": "c2e0c6",
"default": false
},
{
"id": 382069,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/Blocked",
"name": "Blocked",
"color": "fbca04",
"default": false
},
{
"id": 163462,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/Changes%20Requested",
"name": "Changes Requested",
"color": "cc317c",
"default": false
},
{
"id": 404926,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/Release%20Review",
"name": "Release Review",
"color": "5319e7",
"default": false
},
{
"id": 228780,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/Review%20Pass",
"name": "Review Pass",
"color": "009800",
"default": false
},
{
"id": 228781,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/Review%20Requested",
"name": "Review Requested",
"color": "eb6420",
"default": false
},
{
"i
When I try to add label to my PR, it gives error for array.
curl -X POST -u githuser:gittoken https://api.github.mycompany.com/repos/team/repo/issues/560/labels -H "Content-type: application/json" -k -d '{"labels": ["bug"]}' -H "Accept: application/json"
{
"message": "Invalid request.\n\nFor 'links/2/schema', {\"labels\"=>[\"bug\"]} is not an array.",
"documentation_url": "https://developer.github.com/enterprise/2.13/v3/issues/labels/#add-labels-to-an-issue"
}I check,
bug is valid label.```
curl -u githuser:gittoken -X GET \
https://api.github.mycompany.com/repos/team/repo/labels
[
{
"id": 163461,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/+1",
"name": "+1",
"color": "c2e0c6",
"default": false
},
{
"id": 382069,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/Blocked",
"name": "Blocked",
"color": "fbca04",
"default": false
},
{
"id": 163462,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/Changes%20Requested",
"name": "Changes Requested",
"color": "cc317c",
"default": false
},
{
"id": 404926,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/Release%20Review",
"name": "Release Review",
"color": "5319e7",
"default": false
},
{
"id": 228780,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/Review%20Pass",
"name": "Review Pass",
"color": "009800",
"default": false
},
{
"id": 228781,
"url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/Review%20Requested",
"name": "Review Requested",
"color": "eb6420",
"default": false
},
{
"i
Solution
From my understanding of the docs, you should directly send an array (which is valid JSON), without wrapping it in an object. That is
So, the proper request should be:
["bug"] instead of {"labels": ["bug"]}.So, the proper request should be:
curl -X POST -u githuser:gittoken \
https://api.github.mycompany.com/repos/team/repo/issues/560/labels \
-H "Content-type: application/json" -k \
-d '["bug"]' \
-H "Accept: application/json"Code Snippets
curl -X POST -u githuser:gittoken \
https://api.github.mycompany.com/repos/team/repo/issues/560/labels \
-H "Content-type: application/json" -k \
-d '["bug"]' \
-H "Accept: application/json"Context
StackExchange DevOps Q#6203, answer score: 2
Revisions (0)
No revisions yet.