mirror of
https://github.com/netbirdio/docs.git
synced 2026-04-16 15:36:36 +00:00
add some guides pages to the API
This commit is contained in:
@@ -365,7 +365,16 @@ export const docsNavigation = [
|
||||
|
||||
export const apiNavigation = [
|
||||
{
|
||||
title: 'API',
|
||||
title: 'Guides',
|
||||
links: [
|
||||
{ title: 'Quickstart', href: '/quickstart' },
|
||||
{ title: 'Authentication', href: '/authentication' },
|
||||
{ title: 'Errors', href: '/errors' },
|
||||
// { title: 'Events', href: '/accounts' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Resources',
|
||||
links: [
|
||||
{ title: 'Accounts', href: '/accounts' },
|
||||
{ title: 'Users', href: '/users' },
|
||||
|
||||
33
src/pages/authentication.mdx
Normal file
33
src/pages/authentication.mdx
Normal file
@@ -0,0 +1,33 @@
|
||||
export const description =
|
||||
'In this guide, we’ll look at how authentication works. Protocol offers two ways to authenticate your API requests: Basic authentication and OAuth2 with a token.'
|
||||
|
||||
# Authentication
|
||||
|
||||
You'll need to authenticate your requests to access any of the endpoints in the Protocol API. In this guide, we'll look at how authentication works. Protocol offers two ways to authenticate your API requests: Basic authentication and OAuth2 with a token — OAuth2 is the recommended way. {{ className: 'lead' }}
|
||||
|
||||
## OAuth2 with bearer token
|
||||
|
||||
The recommended way to authenticate with the Protocol API is by using OAuth2. When establishing a connection using OAuth2, you will need your access token — you will find it in the [Protocol dashboard](#) under API settings. Here's how to add the token to the request header using cURL:
|
||||
|
||||
```bash {{ title: 'Example request with bearer token' }}
|
||||
curl https://api.netbird.io/api/users \
|
||||
-H "Authorization: Bearer {token}"
|
||||
```
|
||||
|
||||
Always keep your token safe and reset it if you suspect it has been compromised.
|
||||
|
||||
## Using personal access tokens
|
||||
|
||||
The recommended way to authenticate with the Protocol API is by using OAuth2. When establishing a connection using OAuth2, you will need your access token — you will find it in the [Protocol dashboard](#) under API settings. Here's how to add the token to the request header using cURL:
|
||||
|
||||
```bash {{ title: 'Example request with personal access token' }}
|
||||
curl https://api.netbird.io/api/users \
|
||||
-H "Authorization: Token {token}"
|
||||
```
|
||||
|
||||
Always keep your token safe and reset it if you suspect it has been compromised.
|
||||
|
||||
<div className="not-prose mb-16 mt-6 flex gap-3">
|
||||
<Button href="/quickstart" arrow="right" children="How to create tokens" />
|
||||
</div>
|
||||
|
||||
67
src/pages/errors.mdx
Normal file
67
src/pages/errors.mdx
Normal file
@@ -0,0 +1,67 @@
|
||||
export const description =
|
||||
'In this guide, we will talk about what happens when something goes wrong while you work with the API.'
|
||||
|
||||
# Errors
|
||||
|
||||
In this guide, we will talk about what happens when something goes wrong while you work with the API. Mistakes happen, and mostly they will be yours, not ours. Let's look at some status codes and error types you might encounter. {{ className: 'lead' }}
|
||||
|
||||
You can tell if your request was successful by checking the status code when receiving an API response. If a response comes back unsuccessful, you can use the error type and error message to figure out what has gone wrong and do some rudimentary debugging (before contacting support).
|
||||
|
||||
<Note>
|
||||
Before reaching out to support with an error, please be aware that 99% of all
|
||||
reported errors are, in fact, user errors. Therefore, please carefully check
|
||||
your code before contacting Protocol support.
|
||||
</Note>
|
||||
|
||||
---
|
||||
|
||||
## Status codes
|
||||
|
||||
Here is a list of the different categories of status codes returned by the Protocol API. Use these to understand if a request was successful.
|
||||
|
||||
<Properties>
|
||||
<Property name="2xx">
|
||||
A 2xx status code indicates a successful response.
|
||||
</Property>
|
||||
<Property name="4xx">
|
||||
A 4xx status code indicates a client error — this means it's a _you_
|
||||
problem.
|
||||
</Property>
|
||||
<Property name="5xx">
|
||||
A 5xx status code indicates a server error — you won't be seeing these.
|
||||
</Property>
|
||||
</Properties>
|
||||
|
||||
---
|
||||
|
||||
## Error types
|
||||
|
||||
<Row>
|
||||
<Col>
|
||||
|
||||
Whenever a request is unsuccessful, the Protocol API will return an error response with an error type and message. You can use this information to understand better what has gone wrong and how to fix it. Most of the error messages are pretty helpful and actionable.
|
||||
|
||||
Here is a list of the two error types supported by the Protocol API — use these to understand what you have done wrong.
|
||||
|
||||
<Properties>
|
||||
<Property name="api_error">
|
||||
This means that we made an error, which is highly speculative and unlikely.
|
||||
</Property>
|
||||
<Property name="invalid_request">
|
||||
This means that you made an error, which is much more likely.
|
||||
</Property>
|
||||
</Properties>
|
||||
|
||||
</Col>
|
||||
<Col>
|
||||
|
||||
```bash {{ title: "Error response" }}
|
||||
{
|
||||
"type": "api_error",
|
||||
"message": "No way this is happening!?",
|
||||
"documentation_url": "https://protocol.chat/docs/errors/api_error"
|
||||
}
|
||||
```
|
||||
|
||||
</Col>
|
||||
</Row>
|
||||
101
src/pages/quickstart.mdx
Normal file
101
src/pages/quickstart.mdx
Normal file
@@ -0,0 +1,101 @@
|
||||
export const description =
|
||||
'This guide will get you all set up and ready to use the Protocol API. We’ll cover how to get started an API client and how to make your first API request.'
|
||||
|
||||
# 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' }}
|
||||
|
||||
<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 » API](#).
|
||||
</Note>
|
||||
|
||||
## Choose your client
|
||||
|
||||
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.
|
||||
|
||||
<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>
|
||||
|
||||
## 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.
|
||||
|
||||
<CodeGroup tag="GET" label="/v1/conversations">
|
||||
|
||||
```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();
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
<div className="not-prose">
|
||||
<Button
|
||||
href="/conversations"
|
||||
variant="text"
|
||||
arrow="right"
|
||||
children="Read the docs for the Conversations 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:
|
||||
|
||||
- [Grab your API key from the Protocol dashboard](#)
|
||||
- [Check out the Conversations endpoint](/conversations)
|
||||
- [Learn about the different error messages in Protocol](/errors)
|
||||
Reference in New Issue
Block a user