0

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.

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
    },
    {
        "id": 426113,
        "url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/Staging%20Bug",
        "name": "Staging Bug",
        "color": "d6021a",
        "default": false
    },
    {
        "id": 163457,
        "url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/bug",
        "name": "bug",
        "color": "fc2929",
        "default": true
    },
    {
        "id": 163458,
        "url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/duplicate",
        "name": "duplicate",
        "color": "cccccc",
        "default": true
    },
    {
        "id": 163459,
        "url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/enhancement",
        "name": "enhancement",
        "color": "84b6eb",
        "default": true
    },
    {
        "id": 163460,
        "url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/help%20wanted",
        "name": "help wanted",
        "color": "159818",
        "default": true
    },
    {
        "id": 163463,
        "url": "https://github.mycompany.com/api/v3/repos/team/repo/labels/wontfix",
        "name": "wontfix",
        "color": "ffffff",
        "default": true
    }
]

I tried with other combinations, like string only, string with coma etc.. but its same error.

Actual command: actual command

Nilesh
  • 20,521
  • 16
  • 92
  • 148

2 Answers2

2

Python working example

import requests

url = f'https://api.github.com/repos/your/url/issues/{issue_number/pr_number}'
data = {"labels": [your_label/list_of_labels]}
requests.patch(url, auth=auth, json=data)
Rea Krakover
  • 113
  • 2
  • 13
  • can you try with `curl` ? – Nilesh Jan 20 '20 at 16:31
  • @nilesh - it looks like your curl is ok except that you are using POST instead of PATCH. Try to use patch request. see - https://developer.github.com/v3/issues/#edit-an-issue and https://stackoverflow.com/questions/16306624/how-to-use-patch-verb-with-curl – Rea Krakover Jan 21 '20 at 08:27
0

It works with

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"

The docs which I was following https://developer.github.com/v3/issues/labels/#add-labels-to-an-issue has example as

{
  "labels": ["bug", "enhancement"]
}

But there is another Enterprise doc https://developer.github.com/enterprise/2.13/v3/issues/labels/#add-labels-to-an-issue which shows it should be only ["bug"] instead of dictionary.

Nilesh
  • 20,521
  • 16
  • 92
  • 148