# post\_\_workspace\_{wksId}\_users

`POST /workspace/{id}/users`

*Add User to Workspace*

Add a user to a workspace with a specified role. The authenticated user must have ADMIN access to the workspace to perform this operation.

#### TypeScript Client Library

```typescript
public addUserToWorkspace = async (workspaceId: string, request: WorkspaceTypes.AddUserToWorkspaceRequest): Promise<WorkspaceTypes.AddUserToWorkspaceResponse> => {
  return this.makeRequest<WorkspaceTypes.AddUserToWorkspaceResponse>(`workspace/${workspaceId}/users`, 'POST', request);
};
```

#### Code Samples

{% tabs %}
{% tab title="Shell" %}

```shell
# You can also use wget
curl -X POST https://backend.flashback.tech/workspace/123e4567-e89b-12d3-a456-426614174000/users \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer {access-token}' \
  -d '{
    "userId": "user-456",
    "role": "WRITE"
  }'
```

{% endtab %}

{% tab title="HTTP" %}

```http
POST https://backend.flashback.tech/workspace/123e4567-e89b-12d3-a456-426614174000/users HTTP/1.1
Host: backend.flashback.tech
Content-Type: application/json
Accept: application/json
Authorization: Bearer {access-token}

{
  "userId": "user-456",
  "role": "WRITE"
}
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const workspaceId = '123e4567-e89b-12d3-a456-426614174000';
const inputBody = '{
  "userId": "user-456",
  "role": "WRITE"
}';
const headers = {
  'Content-Type':'application/json',
  'Accept':'application/json',
  'Authorization':'Bearer {access-token}'
};

fetch(`https://backend.flashback.tech/workspace/${workspaceId}/users`,
{
  method: 'POST',
  body: inputBody,
  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'rest-client'
require 'json'

workspace_id = '123e4567-e89b-12d3-a456-426614174000'
headers = {
  'Content-Type' => 'application/json',
  'Accept' => 'application/json',
  'Authorization' => 'Bearer {access-token}'
}

data = {
  'userId' => 'user-456',
  'role' => 'WRITE'
}

result = RestClient.post "https://backend.flashback.tech/workspace/#{workspace_id}/users",
  data.to_json, headers: headers

p JSON.parse(result)
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

workspace_id = '123e4567-e89b-12d3-a456-426614174000'
headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'Authorization': 'Bearer {access-token}'
}

data = {
  'userId': 'user-456',
  'role': 'WRITE'
}

r = requests.post(f'https://backend.flashback.tech/workspace/{workspace_id}/users', 
                  headers=headers, 
                  json=data)

print(r.json())
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

require 'vendor/autoload.php';

$workspace_id = '123e4567-e89b-12d3-a456-426614174000';
$headers = array(
    'Content-Type' => 'application/json',
    'Accept' => 'application/json',
    'Authorization' => 'Bearer {access-token}',
);

$client = new \GuzzleHttp\Client();

// Define array of request body.
$request_body = array(
    'userId' => 'user-456',
    'role' => 'WRITE'
);

try {
    $response = $client->request('POST',"https://backend.flashback.tech/workspace/{$workspace_id}/users", array(
        'headers' => $headers,
        'json' => $request_body,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }
```

{% endtab %}

{% tab title="Java" %}

```java
String workspaceId = "123e4567-e89b-12d3-a456-426614174000";
URL obj = new URL("https://backend.flashback.tech/workspace/" + workspaceId + "/users");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept", "application/json");
con.setRequestProperty("Authorization", "Bearer {access-token}");

String jsonInputString = "{\"userId\": \"user-456\", \"role\": \"WRITE\"}";
con.setDoOutput(true);
try(OutputStream os = con.getOutputStream()) {
    byte[] input = jsonInputString.getBytes("utf-8");
    os.write(input, 0, input.length);           
}

int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
       "bytes"
       "net/http"
       "encoding/json"
       "fmt"
)

func main() {
    workspaceId := "123e4567-e89b-12d3-a456-426614174000"
    data := map[string]string{
        "userId": "user-456",
        "role": "WRITE",
    }
    
    jsonData, _ := json.Marshal(data)
    
    headers := map[string][]string{
        "Content-Type": []string{"application/json"},
        "Accept": []string{"application/json"},
        "Authorization": []string{"Bearer {access-token}"},
    }

    req, err := http.NewRequest("POST", fmt.Sprintf("https://backend.flashback.tech/workspace/%s/users", workspaceId), bytes.NewBuffer(jsonData))
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}
```

{% endtab %}
{% endtabs %}

> Body parameter

```json
{
  "userId": "user-456",
  "role": "WRITE"
}
```

#### Parameters <a href="#post__workspace_wksid_users-parameters" id="post__workspace_wksid_users-parameters"></a>

| Name | In   | Type   | Required | Description                            |
| ---- | ---- | ------ | -------- | -------------------------------------- |
| id   | path | string | true     | The unique identifier of the workspace |
| body | body | object | true     | User addition data                     |

#### Path Parameters <a href="#post__workspace_wksid_users-path-parameters" id="post__workspace_wksid_users-path-parameters"></a>

| Name | Type   | Required | Restrictions | Description                            |
| ---- | ------ | -------- | ------------ | -------------------------------------- |
| id   | string | true     | none         | The unique identifier of the workspace |

#### Request Body Schema <a href="#post__workspace_wksid_users-request-body-schema" id="post__workspace_wksid_users-request-body-schema"></a>

| Name     | Type   | Required | Restrictions | Description                                         |
| -------- | ------ | -------- | ------------ | --------------------------------------------------- |
| » userId | string | true     | none         | The unique identifier of the user to add            |
| » role   | string | true     | none         | The role to assign to the user (READ, WRITE, ADMIN) |

**Enumerated Values**

| Parameter | Value |
| --------- | ----- |
| » role    | READ  |
| » role    | WRITE |
| » role    | ADMIN |

> Example responses

> 200 Response

```json
{
  "success": true
}
```

> 400 Response

```json
{
  "success": false,
  "message": "User not found or account is not validated"
}
```

> 403 Response

```json
{
  "success": false,
  "message": "Insufficient permissions to manage workspace users"
}
```

> 404 Response

```json
{
  "success": false,
  "message": "Target user not found"
}
```

> 500 Response

```json
{
  "success": false,
  "message": "Failed to add user to workspace"
}
```

#### Responses <a href="#post__workspace_wksid_users-responses" id="post__workspace_wksid_users-responses"></a>

| Status | Meaning                                                                    | Description                          | Schema |
| ------ | -------------------------------------------------------------------------- | ------------------------------------ | ------ |
| 200    | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)                    | User added to workspace successfully | Inline |
| 400    | [Bad Request](https://tools.ietf.org/html/rfc7231#section-6.5.1)           | User not found or not validated      | Inline |
| 403    | [Forbidden](https://tools.ietf.org/html/rfc7231#section-6.5.3)             | Insufficient permissions             | Inline |
| 404    | [Not Found](https://tools.ietf.org/html/rfc7231#section-6.5.4)             | Target user not found                | Inline |
| 500    | [Internal Server Error](https://tools.ietf.org/html/rfc7231#section-6.6.1) | Server error                         | Inline |

#### Response Schema <a href="#post__workspace_wksid_users-responseschema" id="post__workspace_wksid_users-responseschema"></a>

Status Code **200**

| Name      | Type    | Required | Restrictions | Description              |
| --------- | ------- | -------- | ------------ | ------------------------ |
| » success | boolean | true     | none         | Operation success status |

Status Code **400**

| Name      | Type    | Required | Restrictions | Description              |
| --------- | ------- | -------- | ------------ | ------------------------ |
| » success | boolean | true     | none         | Operation success status |
| » message | string  | true     | none         | Error message            |

Status Code **403**

| Name      | Type    | Required | Restrictions | Description              |
| --------- | ------- | -------- | ------------ | ------------------------ |
| » success | boolean | true     | none         | Operation success status |
| » message | string  | true     | none         | Error message            |

Status Code **404**

| Name      | Type    | Required | Restrictions | Description              |
| --------- | ------- | -------- | ------------ | ------------------------ |
| » success | boolean | true     | none         | Operation success status |
| » message | string  | true     | none         | Error message            |

Status Code **500**

| Name      | Type    | Required | Restrictions | Description              |
| --------- | ------- | -------- | ------------ | ------------------------ |
| » success | boolean | true     | none         | Operation success status |
| » message | string  | true     | none         | Error message            |

## Notes

* **Authentication Required**: User must be authenticated with a valid Bearer token
* **Permissions**: User must have ADMIN access to the workspace to add users
* **Account Validation**: User account must be validated to perform this operation
* **User Organization**: Target user must belong to the same organization as the workspace
* **Role Assignment**: Users can be assigned READ, WRITE, or ADMIN roles
* **Duplicate Prevention**: If the user already exists in the workspace, the role will be updated
* **Organization Scoped**: Users can only be added to workspaces within their organization


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.flashback.tech/support-reference/platform-api-reference/workspace/post__workspace_-wksid-_users.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
