Labels

newrelic_api.labels

class newrelic_api.labels.Labels(api_key=None)

An interface for interacting with the NewRelic label API.

__init__(api_key=None)
Parameters:api_key (str) – The API key. If no key is passed, the environment variable NEW_RELIC_API_KEY is used.
Raises:If the api_key parameter is not present, and no environment variable is present, a newrelic_api.exceptions.ConfigurationException is raised.
create(name, category, applications=None, servers=None)

This API endpoint will create a new label with the provided name and category

Parameters:
  • name (str) – The name of the label
  • category (str) – The Category
  • applications (list of int) – An optional list of application ID’s
  • servers (list of int) – An optional list of server ID’s
Return type:

dict

Returns:

The JSON response of the API

{
    "label": {
        "key": "string",
        "category": "string",
        "name": "string",
        "links": {
            "applications": [
                "integer"
            ],
            "servers": [
                "integer"
            ]
        }
    }
}
delete(key)

When applications are provided, this endpoint will remove those applications from the label.

When no applications are provided, this endpoint will remove the label.

Parameters:key (str) – Label key. Example: ‘Language:Java’
Return type:dict
Returns:The JSON response of the API
{
    "label": {
        "key": "string",
        "category": "string",
        "name": "string",
        "links": {
            "applications": [
                "integer"
            ],
            "servers": [
                "integer"
            ]
        }
    }
}
list(page=None)

This API endpoint returns a paginated list of the Labels associated with your New Relic account.

Parameters:page (int) – Pagination index
Return type:dict
Returns:The JSON response of the API, with an additional ‘pages’ key if there are paginated results
{
    "labels": [
        {
            "key": "string",
            "category": "string",
            "name": "string",
            "links": {
                "applications": [
                    "integer"
                ],
                "servers": [
                    "integer"
                ]
            }
        }
    ],
    "pages": {
        "last": {
            "url": "https://api.newrelic.com/v2/labels.json?page=2",
            "rel": "last"
        },
        "next": {
            "url": "https://api.newrelic.com/v2/labels.json?page=2",
            "rel": "next"
        }
    }
}