Create labels for apps (v2)

You can create or apply labels to the applications in your account. You can also use the New Relic REST API Explorer (v2) to create labels.

Requirements

Creating or applying a label requires:

Create or apply labels

Use a command similar to the following example to apply a label to an application that exists in your account. Substitute your account's REST API key for ${API_KEY} and the application id in the location noted in the example.

You can use this command to apply the same label to applications and hosts simultaneously. You can also omit the "applications": section if not needed.

curl -X PUT 'https://api.newrelic.com/v2/labels.json' \
     -H "X-Api-Key:${API_KEY}" -i \
     -H 'Content-Type: application/json' \
     -d \
'{
  "label": {
    "category": "Production",
    "name": "Web01",
    "links": {
      "applications": [
        123456,7898765     <---<< application ids
      ],
    }
  }
}' 

View the output

The output for creating or applying a label will appear similar to the following example for a single application. The label output includes:

  • The full key name for the label (for example, Production:Main), as well as the component and name for the key
  • The application health_status (red, orange, green, gray) and the application IDs for the label in each category; for example, the health status for app ID 546917 is green (the app is fine)
  • Apps that have this label; for example, the label Production:Main has been applied to one application (546917)
{
  "label": {
    "key": "Production:Main",
    "category": "Production",
    "name": "Main",
    "application_health_status": {
      "green": [
        546917        <---application id
      ],
      "orange": [],
      "red": [],
      "gray": []
    },
    "links": {
      "applications": [
        546917        <--- application id
      ],
    }
  },
...
}

Review return status

There are two possible return statuses when creating labels:

Return status Definition
201 Create A label was successfully created.
304 Not Modified There was an attempt to re-create an existing label, but no change was needed or made.

For more help

Recommendations for learning more: