Linode API - Get Started

Programmatic access to the Linode platform, allowing you to automate tasks through a fully-documented REST API.

Create a Linode account to try this guide with a $ credit.
This credit will be applied to any valid services used during your first  days.

The Linode API allows you to automate any task that can be performed by the Cloud Manager. This includes creating and managing all of our products (like Compute Instances and Managed Databases), your customer account (like adding new users or viewing invoices), and even creating support tickets. As an example of an API call, the command below deploys a new 2GB Compute Instance in the Newark data center using the Debian 11 image.

curl -X POST https://api.linode.com/v4/linode/instances \
    -H "Authorization: Bearer $TOKEN" -H "Content-type: application/json" \
    -d '{"type": "g6-standard-2", "region": "us-east", "image": "linode/debian11", "root_pass": "[password]", "label": "[label]"}'

This guide helps you get set up to run this example. Note that if you run this command, you create and are charged for a 2GB Compute Instance. See Linode Pricing for details on these charges.

Note

Within the Linode API documentation, including this guide, the json_pp utility is used with the curl command to process JSON data into a more human-readable format. An example is shown below:

curl [options] | json_pp

Using json_pp is optional. You can remove | json_pp from the command and the output is instead displayed without proper indentation. Other alternatives exist, such as the jsonpp utility, or you can save the output as a file and open the file with a JSON-compatible file viewer. To install either of these utilities, see the json_pp or jsonpp documentation.

Get an Access Token

Authorization for the Linode API is handled through personal access tokens. Personal access tokens grant permissions to read or write to an API endpoint. All API requests to non-public resources must be authenticated with an access token.

Note
If you are building an application which needs to authenticate multiple users (for example, a custom interface to Linode’s infrastructure for your organization), you can set up an OAuth authentication flow to generate tokens for each user.

For full instructions on creating and managing personal access tokens, see Manage Personal Access Tokens.

  1. Log in to the Cloud Manager.

  2. Click on your username at the top of the screen and select My Profile.

  3. Select the API Tokens tab:

  4. Click on Create Personal Access Token and choose the access rights you want users authenticated with the new token to have.

  5. When you have finished, click Create to generate an API token string. Copy the token and save it in a secure location. You will not be able to view the token through the Cloud Manager after closing the popup.

Authenticate Requests

Once you have created a personal access token, it needs to be sent along in the header of most API requests. The header should use the format:

Authorization: Bearer <token-string>

Store the token as a temporary shell variable to simplify repeated requests. Replace <token-string> in this example:

export TOKEN=<token-string>

Get Configuration Parameters

Specify the type, region, and image for the new Compute Instance.

  1. Review the list of available images:

    curl https://api.linode.com/v4/images/ | json_pp

    Choose one of the images from the resulting list and make a note of the id field.

  2. Repeat this procedure to choose a type:

    curl https://api.linode.com/v4/linode/types/ | json_pp
  3. Choose a region:

    curl https://api.linode.com/v4/regions | json_pp

Build the Final Query

Replace the values in the command below with your chosen type, region, image, label, and a secure root password.

curl -X POST https://api.linode.com/v4/linode/instances \
    -H "Authorization: Bearer $TOKEN" -H "Content-type: application/json" \
    -d '{"type": "g5-standard-2", "region": "us-east", "image": "linode/debian9", "root_pass": "root_password", "label": "prod-1"}'

See Send an API Request with cURL for additional instructions on making API calls through the cURL command.

This page was originally published on


Your Feedback Is Important

Let us know if this guide was helpful to you.