Not able to create linode instance using linode API

Not able to create linode instance using linode API,
I am using API Token which has all the permission i.e read and write ,
but when i try to create linode instance i am getting the following error
"message": "Request failed with status code 401"

the code which i am using to make post request
const response = await axios.post('https://api.linode.com/v4/linode/instances', {
headers: {
Authorization: Bearer ${TOKEN}
},
data: {
region: 'ap-west',
type: 'g6-nanode-1',
image: 'linode/centos7',
root_pass: 'Amitesh@14124.',
interfaces: [
{
purpose: 'public',
label: '',
ipam_address: ''
},
{
purpose: 'vlan',
label: 'vlan-1',
ipam_address: '10.0.0.1/24'
}
]
}
});

1 Reply

Based on the error code you've provided, it states that you've failed to authenticate to that resource. Our API documentation mentions this specific error. According to this guide, the HTTP response status code indicates that the client request has not been completed because it lacks valid authentication credentials for the requested resource. In this case, you would generate a new token with read/write permissions enabled for creating Linodes on your account, then configure Linode CLI with the new token.

I don't use APIs on a day-to-day basis, so my syntax to create a Linode was slightly different than yours. I've provided the syntax below that I personally used to create a Nanode in Mumbai.

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": "aComplexP@ssword", "label": "prod-1"}'

For reference, I've used our Linode API tutorial video to help me create a Linode. It goes into detail on how to create an API token, familiarizing yourself with the commands, and spinning up your own Linode. It's quite helpful if you're a visual learner like me:

You could also refer to our API documentation and follow along with the commands they have provided, which describe in depth what each command does:

Hopefully, these resources can get you down the right path to deploy a Linode!

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct