Files
netbird-docs/src/pages/ipa/resources/users.mdx
2024-03-19 10:13:43 +01:00

1127 lines
21 KiB
Plaintext

export const title = 'Users'
## List all Users {{ tag: 'GET' , label: '/api/users' }}
<Row>
<Col>
Returns a list of all users
#### Query Parameters
<Properties>
<Property name="service_user" type="boolean" required={false}>
Filters users and returns either regular users or service users
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup title="Request" tag="GET" label="/api/users">
```bash {{ title: 'cURL' }}
curl -X GET https://api.netbird.io/api/users \
-H 'Accept: application/json' \
-H 'Authorization: Token <TOKEN>'
```
```js
const axios = require('axios');
let config = {
method: 'get',
maxBodyLength: Infinity,
url: '/api/users',
headers: {
'Accept': 'application/json',
'Authorization': 'Token <TOKEN>'
}
};
axios(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
```
```python
import requests
import json
url = "https://api.netbird.io/api/users"
headers: {
'Accept': 'application/json',
'Authorization': 'Token <TOKEN>'
}
response = requests.request("GET", url, headers=headers)
print(response.text)
```
```go
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.netbird.io/api/users"
method := "GET"
client := &http.Client {
}
req, err := http.NewRequest(method, url, nil)
if err != nil {
fmt.Println(err)
return
{
req.Header.Add("Accept", "application/json")
req.Header.Add("Authorization", "Token <TOKEN>")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
```
```ruby
require "uri"
require "json"
require "net/http"
url = URI("https://api.netbird.io/api/users")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Accept"] = "application/json"
request["Authorization"] = "Token <TOKEN>"
response = https.request(request)
puts response.read_body
```
```java
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
Request request = new Request.Builder()
.url("https://api.netbird.io/api/users")
.method("GET")
.addHeader("Accept", "application/json")
.addHeader("Authorization: Token <TOKEN>")
.build();
Response response = client.newCall(request).execute();
```
```php
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.netbird.io/api/users',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Accept: application/json',
'Authorization: Token <TOKEN>'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Example' }}
[
{
"id": "google-oauth2|277474792786460067937",
"email": "demo@netbird.io",
"name": "Tom Schulz",
"role": "admin",
"status": "active",
"last_login": "2023-05-05T09:00:35.477782Z",
"auto_groups": [
"ch8i4ug6lnn4g9hqv7m0"
],
"is_current": true,
"is_service_user": false,
"is_blocked": false,
"issued": "api"
}
]
```
```json {{ title: 'Schema' }}
[
{
"id": "string",
"email": "string",
"name": "string",
"role": "string",
"status": "string",
"last_login": "string",
"auto_groups": [
"string"
],
"is_current": "boolean",
"is_service_user": "boolean",
"is_blocked": "boolean",
"issued": "string"
}
]
```
</CodeGroup>
</Col>
</Row>
---
## Create a User {{ tag: 'POST' , label: '/api/users' }}
<Row>
<Col>
Creates a new service user or sends an invite to a regular user
#### Request-Body Parameters
<Properties><Property name="email" type="string" required={false}>
User's Email to send invite to
</Property>
<Property name="name" type="string" required={false}>
User's full name
</Property>
<Property name="role" type="string" required={true}>
User's NetBird account role
</Property>
<Property name="auto_groups" type="string[]" required={true}>
Group IDs to auto-assign to peers registered by this user
</Property>
<Property name="is_service_user" type="boolean" required={true}>
Is true if this user is a service user
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup title="Request" tag="POST" label="/api/users">
```bash {{ title: 'cURL' }}
curl -X POST https://api.netbird.io/api/users \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Token <TOKEN>' \
--data-raw '{
"email": "demo@netbird.io",
"name": "Tom Schulz",
"role": "admin",
"auto_groups": [
"ch8i4ug6lnn4g9hqv7m0"
],
"is_service_user": false
}'
```
```js
const axios = require('axios');
let data = JSON.stringify({
"email": "demo@netbird.io",
"name": "Tom Schulz",
"role": "admin",
"auto_groups": [
"ch8i4ug6lnn4g9hqv7m0"
],
"is_service_user": false
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: '/api/users',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Token <TOKEN>'
},
data : data
};
axios(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
```
```python
import requests
import json
url = "https://api.netbird.io/api/users"
payload = json.dumps({
"email": "demo@netbird.io",
"name": "Tom Schulz",
"role": "admin",
"auto_groups": [
"ch8i4ug6lnn4g9hqv7m0"
],
"is_service_user": false
})
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Token <TOKEN>'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
```
```go
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.netbird.io/api/users"
method := "POST"
payload := strings.NewReader(`{
"email": "demo@netbird.io",
"name": "Tom Schulz",
"role": "admin",
"auto_groups": [
"ch8i4ug6lnn4g9hqv7m0"
],
"is_service_user": false
}`)
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
{
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Accept", "application/json")
req.Header.Add("Authorization", "Token <TOKEN>")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
```
```ruby
require "uri"
require "json"
require "net/http"
url = URI("https://api.netbird.io/api/users")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/json"
request["Accept"] = "application/json"
request["Authorization"] = "Token <TOKEN>"
request.body = JSON.dump({
"email": "demo@netbird.io",
"name": "Tom Schulz",
"role": "admin",
"auto_groups": [
"ch8i4ug6lnn4g9hqv7m0"
],
"is_service_user": false
})
response = https.request(request)
puts response.read_body
```
```java
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, '{
"email": "demo@netbird.io",
"name": "Tom Schulz",
"role": "admin",
"auto_groups": [
"ch8i4ug6lnn4g9hqv7m0"
],
"is_service_user": false
}');
Request request = new Request.Builder()
.url("https://api.netbird.io/api/users")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "application/json")
.addHeader("Authorization: Token <TOKEN>")
.build();
Response response = client.newCall(request).execute();
```
```php
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.netbird.io/api/users',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => '{
"email": "demo@netbird.io",
"name": "Tom Schulz",
"role": "admin",
"auto_groups": [
"ch8i4ug6lnn4g9hqv7m0"
],
"is_service_user": false
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Token <TOKEN>'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Example' }}
{
"id": "google-oauth2|277474792786460067937",
"email": "demo@netbird.io",
"name": "Tom Schulz",
"role": "admin",
"status": "active",
"last_login": "2023-05-05T09:00:35.477782Z",
"auto_groups": [
"ch8i4ug6lnn4g9hqv7m0"
],
"is_current": true,
"is_service_user": false,
"is_blocked": false,
"issued": "api"
}
```
```json {{ title: 'Schema' }}
{
"id": "string",
"email": "string",
"name": "string",
"role": "string",
"status": "string",
"last_login": "string",
"auto_groups": [
"string"
],
"is_current": "boolean",
"is_service_user": "boolean",
"is_blocked": "boolean",
"issued": "string"
}
```
</CodeGroup>
</Col>
</Row>
---
## Update a User {{ tag: 'PUT' , label: '/api/users/{userId}' }}
<Row>
<Col>
Update information about a User
#### Path Parameters
<Properties>
<Property name="userId" type="string" required={true}>
The unique identifier of a user
</Property>
</Properties>
#### Request-Body Parameters
<Properties><Property name="role" type="string" required={true}>
User's NetBird account role
</Property>
<Property name="auto_groups" type="string[]" required={true}>
Group IDs to auto-assign to peers registered by this user
</Property>
<Property name="is_blocked" type="boolean" required={true}>
If set to true then user is blocked and can't use the system
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup title="Request" tag="PUT" label="/api/users/{userId}">
```bash {{ title: 'cURL' }}
curl -X PUT https://api.netbird.io/api/users/{userId} \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Token <TOKEN>' \
--data-raw '{
"role": "admin",
"auto_groups": [
"ch8i4ug6lnn4g9hqv7m0"
],
"is_blocked": false
}'
```
```js
const axios = require('axios');
let data = JSON.stringify({
"role": "admin",
"auto_groups": [
"ch8i4ug6lnn4g9hqv7m0"
],
"is_blocked": false
});
let config = {
method: 'put',
maxBodyLength: Infinity,
url: '/api/users/{userId}',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Token <TOKEN>'
},
data : data
};
axios(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
```
```python
import requests
import json
url = "https://api.netbird.io/api/users/{userId}"
payload = json.dumps({
"role": "admin",
"auto_groups": [
"ch8i4ug6lnn4g9hqv7m0"
],
"is_blocked": false
})
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Token <TOKEN>'
}
response = requests.request("PUT", url, headers=headers, data=payload)
print(response.text)
```
```go
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.netbird.io/api/users/{userId}"
method := "PUT"
payload := strings.NewReader(`{
"role": "admin",
"auto_groups": [
"ch8i4ug6lnn4g9hqv7m0"
],
"is_blocked": false
}`)
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
{
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Accept", "application/json")
req.Header.Add("Authorization", "Token <TOKEN>")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
```
```ruby
require "uri"
require "json"
require "net/http"
url = URI("https://api.netbird.io/api/users/{userId}")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Content-Type"] = "application/json"
request["Accept"] = "application/json"
request["Authorization"] = "Token <TOKEN>"
request.body = JSON.dump({
"role": "admin",
"auto_groups": [
"ch8i4ug6lnn4g9hqv7m0"
],
"is_blocked": false
})
response = https.request(request)
puts response.read_body
```
```java
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, '{
"role": "admin",
"auto_groups": [
"ch8i4ug6lnn4g9hqv7m0"
],
"is_blocked": false
}');
Request request = new Request.Builder()
.url("https://api.netbird.io/api/users/{userId}")
.method("PUT", body)
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "application/json")
.addHeader("Authorization: Token <TOKEN>")
.build();
Response response = client.newCall(request).execute();
```
```php
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.netbird.io/api/users/{userId}',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS => '{
"role": "admin",
"auto_groups": [
"ch8i4ug6lnn4g9hqv7m0"
],
"is_blocked": false
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Accept: application/json',
'Authorization: Token <TOKEN>'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
```
</CodeGroup>
<CodeGroup title="Response">
```json {{ title: 'Example' }}
{
"id": "google-oauth2|277474792786460067937",
"email": "demo@netbird.io",
"name": "Tom Schulz",
"role": "admin",
"status": "active",
"last_login": "2023-05-05T09:00:35.477782Z",
"auto_groups": [
"ch8i4ug6lnn4g9hqv7m0"
],
"is_current": true,
"is_service_user": false,
"is_blocked": false,
"issued": "api"
}
```
```json {{ title: 'Schema' }}
{
"id": "string",
"email": "string",
"name": "string",
"role": "string",
"status": "string",
"last_login": "string",
"auto_groups": [
"string"
],
"is_current": "boolean",
"is_service_user": "boolean",
"is_blocked": "boolean",
"issued": "string"
}
```
</CodeGroup>
</Col>
</Row>
---
## Delete a User {{ tag: 'DELETE' , label: '/api/users/{userId}' }}
<Row>
<Col>
This method removes a user from accessing the system. For this leaves the IDP user intact unless the `--user-delete-from-idp` is passed to management startup.
#### Path Parameters
<Properties>
<Property name="userId" type="string" required={true}>
The unique identifier of a user
</Property>
</Properties>
</Col>
<Col sticky>
<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>'
```
```js
const axios = require('axios');
let config = {
method: 'delete',
maxBodyLength: Infinity,
url: '/api/users/{userId}',
headers: {
'Authorization': 'Token <TOKEN>'
}
};
axios(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
```
```python
import requests
import json
url = "https://api.netbird.io/api/users/{userId}"
headers: {
'Authorization': 'Token <TOKEN>'
}
response = requests.request("DELETE", url, headers=headers)
print(response.text)
```
```go
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.netbird.io/api/users/{userId}"
method := "DELETE"
client := &http.Client {
}
req, err := http.NewRequest(method, url, nil)
if err != nil {
fmt.Println(err)
return
{
req.Header.Add("Authorization", "Token <TOKEN>")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
```
```ruby
require "uri"
require "json"
require "net/http"
url = URI("https://api.netbird.io/api/users/{userId}")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Delete.new(url)
request["Authorization"] = "Token <TOKEN>"
response = https.request(request)
puts response.read_body
```
```java
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
Request request = new Request.Builder()
.url("https://api.netbird.io/api/users/{userId}")
.method("DELETE")
.addHeader("Authorization: Token <TOKEN>")
.build();
Response response = client.newCall(request).execute();
```
```php
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.netbird.io/api/users/{userId}',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'DELETE',
CURLOPT_HTTPHEADER => array(
'Authorization: Token <TOKEN>'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
```
</CodeGroup>
</Col>
</Row>
---
## Resend user invitation {{ tag: 'POST' , label: '/api/users/{userId}/invite' }}
<Row>
<Col>
Resend user invitation
#### Path Parameters
<Properties>
<Property name="userId" type="string" required={true}>
The unique identifier of a user
</Property>
</Properties>
</Col>
<Col sticky>
<CodeGroup title="Request" tag="POST" label="/api/users/{userId}/invite">
```bash {{ title: 'cURL' }}
curl -X POST https://api.netbird.io/api/users/{userId}/invite \
-H 'Authorization: Token <TOKEN>'
```
```js
const axios = require('axios');
let config = {
method: 'post',
maxBodyLength: Infinity,
url: '/api/users/{userId}/invite',
headers: {
'Authorization': 'Token <TOKEN>'
}
};
axios(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
```
```python
import requests
import json
url = "https://api.netbird.io/api/users/{userId}/invite"
headers: {
'Authorization': 'Token <TOKEN>'
}
response = requests.request("POST", url, headers=headers)
print(response.text)
```
```go
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.netbird.io/api/users/{userId}/invite"
method := "POST"
client := &http.Client {
}
req, err := http.NewRequest(method, url, nil)
if err != nil {
fmt.Println(err)
return
{
req.Header.Add("Authorization", "Token <TOKEN>")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
```
```ruby
require "uri"
require "json"
require "net/http"
url = URI("https://api.netbird.io/api/users/{userId}/invite")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = "Token <TOKEN>"
response = https.request(request)
puts response.read_body
```
```java
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
Request request = new Request.Builder()
.url("https://api.netbird.io/api/users/{userId}/invite")
.method("POST")
.addHeader("Authorization: Token <TOKEN>")
.build();
Response response = client.newCall(request).execute();
```
```php
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.netbird.io/api/users/{userId}/invite',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => array(
'Authorization: Token <TOKEN>'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
```
</CodeGroup>
</Col>
</Row>
---