Answers: <p>From my understanding of <a href="https://developer.github.com/enterprise/2.13/v3/issues/labels/#add-labels-to-an-issue" rel="nofollow noreferrer">the docs</a>, you should directly send an array (which is valid JSON), without wrapping it in an object. That is <code>["bug"]</code> instead of <code>{"labels": ["bug"]}</code>.</p>
  
  <p>So, the proper request should be:</p>
  
  <pre><code>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></pre>
  
Answers: CC BY-SA 4.0
Answers: 2019-02-03T18:18:33.610Z
Answers: Thanks for sharing this, I was following https://developer.github.com/v3/issues/labels/#add-labels-to-an-issue
Answers: Nilesh
Answers: CC BY-SA 4.0
Answers: 2019-02-03T21:23:54.700Z
Answers: Interesting @Nilesh. As an Enterprise client, you should maybe open a ticket with the assistance to know more about the discrepancy between the two docs. Let us know the outcome if you do so ;)
Answers: Sylvain Leroux
Answers: CC BY-SA 4.0
Answers: 2019-02-04T17:03:06.450Z
Answers: I will check, may be I have to look for `enterprise` version of API and I was looking for some other docs :)
Answers: Nilesh
Answers: CC BY-SA 4.0
Answers: 2019-02-02T23:53:01.010Z
Answers: 2019-02-02T23:53:01.010Z
Answers: Sylvain Leroux
Body: <p>We are hosting GitHub enterprise for our development. I am able to access the reset api and create jira, create PR etc. </p>
  
  <p>When I <a href="https://developer.github.com/v3/issues/labels/#add-labels-to-an-issue" rel="nofollow noreferrer">try to add label</a> to my PR, it gives error for array.</p>
  
  <pre><code>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\"=&gt;[\"bug\"]} is not an array.",
    "documentation_url": "https://developer.github.com/enterprise/2.13/v3/issues/labels/#add-labels-to-an-issue"
  }
  </code></pre>
  
  <p>I check, <code>bug</code> is valid label.</p>
  
  <pre><code>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
      }
  ]
  </code></pre>
  
  <p>I tried with other combinations, like string only, string with coma etc.. but its same error.</p>
  
  <p>Actual command:
      <a href="https://i.sstatic.net/X3urQ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/X3urQ.png" alt="actual command"></a></p>
  
Tags: <git><github><api>
Title: Github rest api post label gives error for array input
UserDisplayName: Nilesh
ThreadText: # Github rest api post label gives error for array input
  
  (Asked by: username_0 on 2019-02-01)
  
  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](https://developer.github.com/v3/issues/labels/#add-labels-to-an-issue) 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](https://i.sstatic.net/X3urQ.png)](https://i.sstatic.net/X3urQ.png)
  
  **Tags:** git, github, api
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-02-02. Score: 2 | Accepted answer
  
  From my understanding of [the docs](https://developer.github.com/enterprise/2.13/v3/issues/labels/#add-labels-to-an-issue), you should directly send an array (which is valid JSON), without wrapping it in an object. That is `["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"
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks for sharing this, I was following https://developer.github.com/v3/issues/labels/#add-labels-to-an-issue  
  > **username_1**: Interesting @username_0. As an Enterprise client, you should maybe open a ticket with the assistance to know more about the discrepancy between the two docs. Let us know the outcome if you do so ;)  
  > **username_0**: I will check, may be I have to look for `enterprise` version of API and I was looking for some other docs :)  
  
  ---
  
  