# post\_\_workspace

`POST /workspace`

*Create Workspace*

Create a new workspace for the authenticated user's organization. The creator will automatically be added as an admin of the workspace.

#### TypeScript Client Library

```typescript
public createWorkspace = async (request: WorkspaceTypes.CreateWorkspaceRequest): Promise<WorkspaceTypes.CreateWorkspaceResponse> => {
  return this.makeRequest<WorkspaceTypes.CreateWorkspaceResponse>('workspace', 'POST', request);
};
```

#### Code Samples

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

```shell
# You can also use wget
curl -X POST https://backend.flashback.tech/workspace \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer {access-token}' \
  -d '{
    "name": "Development Workspace"
  }'
```

{% endtab %}

{% tab title="HTTP" %}

```http
POST https://backend.flashback.tech/workspace HTTP/1.1
Host: backend.flashback.tech
Content-Type: application/json
Accept: application/json
Authorization: Bearer {access-token}

{
  "name": "Development Workspace"
}
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const inputBody = '{
  "name": "Development Workspace"
}';
const headers = {
  'Content-Type':'application/json',
  'Accept':'application/json',
  'Authorization':'Bearer {access-token}'
};

fetch('https://backend.flashback.tech/workspace',
{
  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'

headers = {
  'Content-Type' => 'application/json',
  'Accept' => 'application/json',
  'Authorization' => 'Bearer {access-token}'
}

result = RestClient.post 'https://backend.flashback.tech/workspace',
  '{"name": "Development Workspace"}', headers: headers

p JSON.parse(result)
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json',
  'Authorization': 'Bearer {access-token}'
}

data = {
  'name': 'Development Workspace'
}

r = requests.post('https://backend.flashback.tech/workspace', 
                 headers=headers, 
                 json=data)

print(r.json())
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

require 'vendor/autoload.php';

$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(
    'name' => 'Development Workspace'
);

try {
    $response = $client->request('POST','https://backend.flashback.tech/workspace', 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
URL obj = new URL("https://backend.flashback.tech/workspace");
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 = "{\"name\": \"Development Workspace\"}";
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"
)

func main() {
    data := map[string]string{
        "name": "Development Workspace",
    }
    
    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", "https://backend.flashback.tech/workspace", bytes.NewBuffer(jsonData))
    req.Header = headers

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

{% endtab %}
{% endtabs %}

> Body parameter

```json
{
  "name": "Development Workspace"
}
```

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

| Name   | In   | Type   | Required | Description                         |
| ------ | ---- | ------ | -------- | ----------------------------------- |
| body   | body | object | true     | Workspace creation data             |
| » name | body | string | true     | The name of the workspace to create |

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

| Name   | Type   | Required | Restrictions | Description               |
| ------ | ------ | -------- | ------------ | ------------------------- |
| » name | string | true     | none         | The name of the workspace |

> Example responses

> 201 Response

```json
{
  "success": true,
  "workspace": {
    "id": "123e4567-e89b-12d3-a456-426614174000",
    "name": "Development Workspace",
    "orgId": "987fcdeb-51a2-43d1-9f12-345678901234"
  }
}
```

> 400 Response

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

> 403 Response

```json
{
  "success": false,
  "message": "Insufficient permissions to create workspaces"
}
```

> 500 Response

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

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

| Status | Meaning                                                                    | Description                     | Schema |
| ------ | -------------------------------------------------------------------------- | ------------------------------- | ------ |
| 201    | [Created](https://tools.ietf.org/html/rfc7231#section-6.3.2)               | Workspace created 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 |
| 500    | [Internal Server Error](https://tools.ietf.org/html/rfc7231#section-6.6.1) | Server error                    | Inline |

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

Status Code **201**

| Name        | Type    | Required | Restrictions | Description                 |
| ----------- | ------- | -------- | ------------ | --------------------------- |
| » success   | boolean | true     | none         | Operation success status    |
| » workspace | object  | true     | none         | Created workspace details   |
| »» id       | string  | true     | none         | Unique workspace identifier |
| »» name     | string  | true     | none         | Workspace name              |
| »» orgId    | string  | true     | none         | Organization identifier     |

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 **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 OWNER, ADMINISTRATORS, or WORKSPACES role in their organization
* **Account Validation**: User account must be validated to create workspaces
* **Workspace Naming**: Workspace names must be unique within the organization
* **Auto-Admin**: The creator is automatically added as an admin of the workspace
