add quickstart for api

This commit is contained in:
Pascal Fischer
2023-05-09 12:17:28 +02:00
parent 4d189d2e39
commit 7f5c373631
13 changed files with 66 additions and 120 deletions

View File

@@ -68,7 +68,7 @@ curl -X <%- operation.operation.toUpperCase() %> <%- operation.fullPath %> \\<%
-H 'Accept: application/json' \\<% }; -%>
<% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ %>
-H 'Content-Type: application/json' \\<% }; %>
-H "Authorization: Token <TOKEN>" <% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ %>\\\n--data-raw '<%- JSON.stringify(components.get(operation.requestBody?.content['application/json'].schema.$ref?.split('/').pop())?.example, null, 2) -%>'<% }; %>
-H 'Authorization: Token <TOKEN>' <% if(operation.requestBody?.content && operation.requestBody?.content['application/json']){ %>\\\n--data-raw '<%- JSON.stringify(components.get(operation.requestBody?.content['application/json'].schema.$ref?.split('/').pop())?.example, null, 2) -%>'<% }; %>
\`\`\`
\`\`\`js

View File

@@ -18,7 +18,7 @@ export const title = 'Accounts'
```bash {{ title: 'cURL' }}
curl -X GET https://api.netbird.io/api/accounts \
-H 'Accept: application/json' \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js
@@ -237,7 +237,7 @@ echo $response;
curl -X PUT https://api.netbird.io/api/accounts/{accountId} \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: Token <TOKEN>" \
-H 'Authorization: Token <TOKEN>' \
--data-raw '{
"peer_login_expiration_enabled": true,
"peer_login_expiration": 43200

View File

@@ -18,7 +18,7 @@ export const title = 'DNS'
```bash {{ title: 'cURL' }}
curl -X GET https://api.netbird.io/api/dns/nameservers \
-H 'Accept: application/json' \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js
@@ -298,7 +298,7 @@ echo $response;
curl -X POST https://api.netbird.io/api/dns/nameservers \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: Token <TOKEN>" \
-H 'Authorization: Token <TOKEN>' \
--data-raw '{
"name": "Google DNS",
"description": "Google DNS servers",
@@ -658,7 +658,7 @@ echo $response;
```bash {{ title: 'cURL' }}
curl -X GET https://api.netbird.io/api/dns/nameservers/{nsgroupId} \
-H 'Accept: application/json' \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js
@@ -942,7 +942,7 @@ echo $response;
curl -X PUT https://api.netbird.io/api/dns/nameservers/{nsgroupId} \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: Token <TOKEN>" \
-H 'Authorization: Token <TOKEN>' \
--data-raw '{
"name": "Google DNS",
"description": "Google DNS servers",
@@ -1301,7 +1301,7 @@ echo $response;
<CodeGroup title="Request" tag="DELETE" label="/api/dns/nameservers/{nsgroupId}">
```bash {{ title: 'cURL' }}
curl -X DELETE https://api.netbird.io/api/dns/nameservers/{nsgroupId} \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js
@@ -1460,7 +1460,7 @@ echo $response;
```bash {{ title: 'cURL' }}
curl -X GET https://api.netbird.io/api/dns/settings \
-H 'Accept: application/json' \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js
@@ -1660,7 +1660,7 @@ echo $response;
curl -X PUT https://api.netbird.io/api/dns/settings \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: Token <TOKEN>" \
-H 'Authorization: Token <TOKEN>' \
--data-raw '{
"disabled_management_groups": [
"ch8i4ug6lnn4g9hqv7m0"

View File

@@ -18,7 +18,7 @@ export const title = 'Events'
```bash {{ title: 'cURL' }}
curl -X GET https://api.netbird.io/api/events \
-H 'Accept: application/json' \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js

View File

@@ -18,7 +18,7 @@ export const title = 'Groups'
```bash {{ title: 'cURL' }}
curl -X GET https://api.netbird.io/api/groups \
-H 'Accept: application/json' \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js
@@ -237,7 +237,7 @@ echo $response;
curl -X POST https://api.netbird.io/api/groups \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: Token <TOKEN>" \
-H 'Authorization: Token <TOKEN>' \
--data-raw '{
"name": "devs",
"peers": [
@@ -488,7 +488,7 @@ echo $response;
```bash {{ title: 'cURL' }}
curl -X GET https://api.netbird.io/api/groups/{groupId} \
-H 'Accept: application/json' \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js
@@ -711,7 +711,7 @@ echo $response;
curl -X PUT https://api.netbird.io/api/groups/{groupId} \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: Token <TOKEN>" \
-H 'Authorization: Token <TOKEN>' \
--data-raw '{
"name": "devs",
"peers": [
@@ -961,7 +961,7 @@ echo $response;
<CodeGroup title="Request" tag="DELETE" label="/api/groups/{groupId}">
```bash {{ title: 'cURL' }}
curl -X DELETE https://api.netbird.io/api/groups/{groupId} \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js

View File

@@ -18,7 +18,7 @@ export const title = 'Peers'
```bash {{ title: 'cURL' }}
curl -X GET https://api.netbird.io/api/peers \
-H 'Accept: application/json' \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js
@@ -252,7 +252,7 @@ echo $response;
```bash {{ title: 'cURL' }}
curl -X GET https://api.netbird.io/api/peers/{peerId} \
-H 'Accept: application/json' \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js
@@ -508,7 +508,7 @@ echo $response;
curl -X PUT https://api.netbird.io/api/peers/{peerId} \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: Token <TOKEN>" \
-H 'Authorization: Token <TOKEN>' \
--data-raw '{
"name": "stage-host-1",
"ssh_enabled": true,
@@ -777,7 +777,7 @@ echo $response;
<CodeGroup title="Request" tag="DELETE" label="/api/peers/{peerId}">
```bash {{ title: 'cURL' }}
curl -X DELETE https://api.netbird.io/api/peers/{peerId} \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js

View File

@@ -18,7 +18,7 @@ export const title = 'Policies'
```bash {{ title: 'cURL' }}
curl -X GET https://api.netbird.io/api/policies \
-H 'Accept: application/json' \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js
@@ -296,7 +296,7 @@ echo $response;
curl -X POST https://api.netbird.io/api/policies \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: Token <TOKEN>" \
-H 'Authorization: Token <TOKEN>' \
--data-raw '{
"name": "ch8i4ug6lnn4g9hqv7mg",
"description": "This is a default policy that allows connections between all the resources",
@@ -742,7 +742,7 @@ echo $response;
```bash {{ title: 'cURL' }}
curl -X GET https://api.netbird.io/api/policies/{policyId} \
-H 'Accept: application/json' \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js
@@ -1024,7 +1024,7 @@ echo $response;
curl -X PUT https://api.netbird.io/api/policies/{policyId} \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: Token <TOKEN>" \
-H 'Authorization: Token <TOKEN>' \
--data-raw '{
"name": "ch8i4ug6lnn4g9hqv7mg",
"description": "This is a default policy that allows connections between all the resources",
@@ -1473,7 +1473,7 @@ echo $response;
<CodeGroup title="Request" tag="DELETE" label="/api/policies/{policyId}">
```bash {{ title: 'cURL' }}
curl -X DELETE https://api.netbird.io/api/policies/{policyId} \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js

View File

@@ -1,104 +1,50 @@
import {HeroPattern} from "@/components/HeroPattern";
export const description =
'This guide will get you all set up and ready to use the Protocol API. Well cover how to get started an API client and how to make your first API request.'
'This guide will get you all set up and ready to use the NetBird API. Well cover how to get started and how to make your first API request.'
<HeroPattern/>
# Quickstart
This guide will get you all set up and ready to use the Protocol API. We'll cover how to get started using one of our API clients and how to make your first API request. We'll also look at where to go next to find all the information you need to take full advantage of our powerful REST API. {{ className: 'lead' }}
This guide will get you all set up and ready to use the NetBird API. We'll cover how to get started using cURL and how to make your first API request. We'll also look at where to go next to find all the information you need to take full advantage of our powerful REST API. {{ className: 'lead' }}
<Note>
Before you can make requests to the Protocol API, you will need to grab your
API key from your dashboard. You find it under [Settings &raquo; API](#).
</Note>
## Install cURL
## Choose your client
For this guide, we'll be using cURL to make our first API request. If you don't already have cURL installed, you can download it from the [cURL website](https://curl.se/download.html).
Before making your first API request, you need to pick which API client you will use. In addition to good ol' cURL HTTP requests, Protocol offers clients for JavaScript, Python, and PHP. In the following example, you can see how to install each client.
## Get an access token
<CodeGroup>
```bash {{ title: 'cURL' }}
# cURL is most likely already installed on your machine
curl --version
```
```bash {{ language: 'js' }}
# Install the Protocol JavaScript SDK
npm install @example/protocol-api --save
```
```bash {{ language: 'python' }}
# Install the Protocol Python SDK
pip install protocol_api
```
```bash {{ language: 'php' }}
# Install the Protocol PHP SDK
composer require protocol/sdk
```
</CodeGroup>
<div className="not-prose">
<Button
href="/sdks"
variant="text"
arrow="right"
children="Check out our list of first-party SDKs"
/>
</div>
Before making your first API request, you need to create an access token to authenticate requests to the API. You can create an access token in the [Netbird dashboard](https://app.netbird.io) under [Users &raquo; Me](https://app.netbird.io/users).
After the token was created successfully make sure to store it as we need it for the next step.
## Making your first API request
After picking your preferred client, you are ready to make your first call to the Protocol API. Below, you can see how to send a GET request to the Conversations endpoint to get a list of all your conversations. In the cURL example, results are limited to ten conversations, the default page length for each client.
After creating your access token, you are ready to make your first call to the NetBird API. Below, you can see how to send a GET request to the peers endpoint to get a list of all peers in your network.
<CodeGroup tag="GET" label="/v1/conversations">
<CodeGroup tag="GET" label="/api/peers">
```bash {{ title: 'cURL' }}
curl -G https://api.protocol.chat/v1/conversations \
-H "Authorization: Bearer {token}" \
-d limit=10
```
```js
import ApiClient from '@example/protocol-api'
const client = new ApiClient(token)
await client.conversations.list()
```
```python
from protocol_api import ApiClient
client = ApiClient(token)
client.conversations.list()
```
```php
$client = new \Protocol\ApiClient($token);
$client->conversations->list();
curl -X GET https://api.netbird.io/api/peers \
-H 'Accept: application/json' \
-H 'Authorization: Token <TOKEN>'
```
</CodeGroup>
<div className="not-prose">
<Button
href="/conversations"
href="/peers"
variant="text"
arrow="right"
children="Read the docs for the Conversations endpoint"
children="Read the docs for the peers endpoint"
/>
</div>
## What's next?
Great, you're now set up with an API client and have made your first request to the API. Here are a few links that might be handy as you venture further into the Protocol API:
Great, you're now set up with an API client and have made your first request to the API. Here are a few links that might be handy as you venture further into the NetBird API:
- [Grab your API key from the Protocol dashboard](#)
- [Check out the Conversations endpoint](/conversations)
- [Learn about the different error messages in Protocol](/errors)
- [Read how to properly authenticate against the NetBird API](/authentication)
- [Check out the users endpoint](/users)
- [Learn about the different error types](/errors)

View File

@@ -18,7 +18,7 @@ export const title = 'Routes'
```bash {{ title: 'cURL' }}
curl -X GET https://api.netbird.io/api/routes \
-H 'Accept: application/json' \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js
@@ -293,7 +293,7 @@ echo $response;
curl -X POST https://api.netbird.io/api/routes \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: Token <TOKEN>" \
-H 'Authorization: Token <TOKEN>' \
--data-raw '{
"description": "My first route",
"network_id": "Route 1",
@@ -592,7 +592,7 @@ echo $response;
```bash {{ title: 'cURL' }}
curl -X GET https://api.netbird.io/api/routes/{routeId} \
-H 'Accept: application/json' \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js
@@ -871,7 +871,7 @@ echo $response;
curl -X PUT https://api.netbird.io/api/routes/{routeId} \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: Token <TOKEN>" \
-H 'Authorization: Token <TOKEN>' \
--data-raw '{
"description": "My first route",
"network_id": "Route 1",
@@ -1169,7 +1169,7 @@ echo $response;
<CodeGroup title="Request" tag="DELETE" label="/api/routes/{routeId}">
```bash {{ title: 'cURL' }}
curl -X DELETE https://api.netbird.io/api/routes/{routeId} \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js

View File

@@ -18,7 +18,7 @@ export const title = 'Rules'
```bash {{ title: 'cURL' }}
curl -X GET https://api.netbird.io/api/rules \
-H 'Accept: application/json' \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js
@@ -285,7 +285,7 @@ echo $response;
curl -X POST https://api.netbird.io/api/rules \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: Token <TOKEN>" \
-H 'Authorization: Token <TOKEN>' \
--data-raw '{
"name": "Default",
"description": "This is a default rule that allows connections between all the resources",
@@ -594,7 +594,7 @@ echo $response;
```bash {{ title: 'cURL' }}
curl -X GET https://api.netbird.io/api/rules/{ruleId} \
-H 'Accept: application/json' \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js
@@ -865,7 +865,7 @@ echo $response;
curl -X PUT https://api.netbird.io/api/rules/{ruleId} \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: Token <TOKEN>" \
-H 'Authorization: Token <TOKEN>' \
--data-raw '{
"name": "Default",
"description": "This is a default rule that allows connections between all the resources",
@@ -1177,7 +1177,7 @@ echo $response;
<CodeGroup title="Request" tag="DELETE" label="/api/rules/{ruleId}">
```bash {{ title: 'cURL' }}
curl -X DELETE https://api.netbird.io/api/rules/{ruleId} \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js

View File

@@ -18,7 +18,7 @@ export const title = 'Setup Keys'
```bash {{ title: 'cURL' }}
curl -X GET https://api.netbird.io/api/setup-keys \
-H 'Accept: application/json' \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js
@@ -277,7 +277,7 @@ echo $response;
curl -X POST https://api.netbird.io/api/setup-keys \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: Token <TOKEN>" \
-H 'Authorization: Token <TOKEN>' \
--data-raw '{
"name": "Default key",
"type": "reusable",
@@ -568,7 +568,7 @@ echo $response;
```bash {{ title: 'cURL' }}
curl -X GET https://api.netbird.io/api/setup-keys/{keyId} \
-H 'Accept: application/json' \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js
@@ -831,7 +831,7 @@ echo $response;
curl -X PUT https://api.netbird.io/api/setup-keys/{keyId} \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: Token <TOKEN>" \
-H 'Authorization: Token <TOKEN>' \
--data-raw '{
"name": "Default key",
"type": "reusable",

View File

@@ -26,7 +26,7 @@ export const title = 'Tokens'
```bash {{ title: 'cURL' }}
curl -X GET https://api.netbird.io/api/users/{userId}/tokens \
-H 'Accept: application/json' \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js
@@ -251,7 +251,7 @@ echo $response;
curl -X POST https://api.netbird.io/api/users/{userId}/tokens \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: Token <TOKEN>" \
-H 'Authorization: Token <TOKEN>' \
--data-raw '{
"name": "My first token",
"expires_in": 30
@@ -492,7 +492,7 @@ echo $response;
```bash {{ title: 'cURL' }}
curl -X GET https://api.netbird.io/api/users/{userId}/tokens/{tokenId} \
-H 'Accept: application/json' \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js
@@ -693,7 +693,7 @@ echo $response;
<CodeGroup title="Request" tag="DELETE" label="/api/users/{userId}/tokens/{tokenId}">
```bash {{ title: 'cURL' }}
curl -X DELETE https://api.netbird.io/api/users/{userId}/tokens/{tokenId} \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js

View File

@@ -26,7 +26,7 @@ export const title = 'Users'
```bash {{ title: 'cURL' }}
curl -X GET https://api.netbird.io/api/users \
-H 'Accept: application/json' \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js
@@ -268,7 +268,7 @@ echo $response;
curl -X POST https://api.netbird.io/api/users \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: Token <TOKEN>" \
-H 'Authorization: Token <TOKEN>' \
--data-raw '{
"email": "demo@netbird.io",
"name": "Tom Schulz",
@@ -561,7 +561,7 @@ echo $response;
curl -X PUT https://api.netbird.io/api/users/{userId} \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: Token <TOKEN>" \
-H 'Authorization: Token <TOKEN>' \
--data-raw '{
"role": "admin",
"auto_groups": [
@@ -813,7 +813,7 @@ echo $response;
<CodeGroup title="Request" tag="DELETE" label="/api/users/{userId}">
```bash {{ title: 'cURL' }}
curl -X DELETE https://api.netbird.io/api/users/{userId} \
-H "Authorization: Token <TOKEN>"
-H 'Authorization: Token <TOKEN>'
```
```js