> This page is for Developers.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.emnify.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.emnify.com/_mcp/server.

# Switch to an assigned Workspace

POST https://cdn.emnify.net/api/v1/authenticate/workspace
Content-Type: application/json

Required permissions Beta [Learn more](/developers/api-guidelines/permissions#how-permissions-work)`Authenticate.Workspace` + `Get`Roles: Administrator User ObserverSwitch to an assigned Workspace and receive an authentication token for the target Workspace.This endpoint requires authentication with [user credentials](/developers/auth/user-credentials) (not an application token), as application tokens are scoped to a single Workspace.The returned `auth_token` is valid for the target Workspace.
Your original token remains valid for the source Workspace.

Reference: https://docs.emnify.com/developers/api/workspaces/authenticate-workspace

## Authentication

- `Authorization` header (bearer token, required) — An `auth_token` should be provided to authenticate a session. To obtain an `auth_token`, see the [`/api/v1/authenticate` **POST** request](/developers/api/authentication/authenticate).

## Request

### Body (application/json)

This endpoint expects an object.

- `target_organisation` (ApiV1AuthenticateWorkspacePostRequestBodyContentApplicationJsonSchemaTargetOrganisation, required)

## Response

### 200

Successfully switched to the assigned Workspace

- `auth_token` (string, optional) — JWT authentication token valid for the target Workspace

## Errors

### 401 Unauthorized Error

Unauthorized

- `any`

### 403 Forbidden Error

Your role doesn't include the permission this endpoint requires. Most endpoints return `error_code`, `error_token`, and `message`. Some return only `status_code` and `message`.

- `error_code` (integer, optional)
- `error_token` (string, optional)
- `status_code` (integer, optional)
- `message` (string, optional)

## Types

### ApiV1AuthenticateWorkspacePostRequestBodyContentApplicationJsonSchemaTargetOrganisation

- `id` (integer, optional)

## Examples

**Request**

```json
{
  "target_organisation": {
    "id": 23211
  }
}
```

**Response**

```json
{
  "auth_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
```

**SDK Code**

```python Success
import requests

url = "https://cdn.emnify.net/api/v1/authenticate/workspace"

payload = { "target_organisation": { "id": 23211 } }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Success
const url = 'https://cdn.emnify.net/api/v1/authenticate/workspace';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"target_organisation":{"id":23211}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Success
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://cdn.emnify.net/api/v1/authenticate/workspace"

	payload := strings.NewReader("{\n  \"target_organisation\": {\n    \"id\": 23211\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Success
require 'uri'
require 'net/http'

url = URI("https://cdn.emnify.net/api/v1/authenticate/workspace")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"target_organisation\": {\n    \"id\": 23211\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java Success
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://cdn.emnify.net/api/v1/authenticate/workspace")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"target_organisation\": {\n    \"id\": 23211\n  }\n}")
  .asString();
```

```php Success
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://cdn.emnify.net/api/v1/authenticate/workspace', [
  'body' => '{
  "target_organisation": {
    "id": 23211
  }
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Success
using RestSharp;

var client = new RestClient("https://cdn.emnify.net/api/v1/authenticate/workspace");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"target_organisation\": {\n    \"id\": 23211\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Success
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["target_organisation": ["id": 23211]] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://cdn.emnify.net/api/v1/authenticate/workspace")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```