> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://docs.agentmail.to/llms.txt.

# Connect App

POST https://api.agentmail.to/v0/apps/{app_id}/connect
Content-Type: application/json

Starts signing an inbox in to an app. Returns a single-use `magic_url`,
valid for five minutes, to open in the client that will hold the sign-in;
the client enrolls as the inbox and continues to the app.
A `404` names the missing resource: `App` or `Inbox`.
A `403` `AppSignupLimitError` means the app accepts no more sign-ups from
your organization; sign in with an inbox that already has an account there.

Reference: https://docs.agentmail.to/api-reference/apps/connect

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Servers

- `https://api.agentmail.to` (prod, default)
- `https://x402.api.agentmail.to` (prod-x402)
- `https://mpp.api.agentmail.to` (prod-mpp)
- `https://api.agentmail.eu` (eu-prod)

## Request

### Path parameters

- `app_id` (UUID, required) — ID of app.

### Body (application/json)

This endpoint expects a ConnectAppBody.

- `inbox_id` (string, optional) — Inbox to sign in as. Required unless the API key is scoped to an inbox.
- `accept_disclosure` (boolean, optional) — Accept the app's disclosure on the agent's behalf, skipping the first-use disclosure page. Requires `app_share_owner` when owner scopes are involved.

## Response

### 202

- `api_key_id` (string, required) — ID of api key.
- `magic_url` (string, required) — Single-use URL to open in the client that will hold the key.
- `expires_at` (datetime, required) — Time at which api key expires. Omitted when it does not expire.

## Errors

### 400 Validation Error

- `name` (string, required) — Name of error.
- `errors` (any, required) — Validation errors. Each entry has a path and a message identifying the invalid field.
- `code` (string, optional) — Stable, machine-readable error code in snake_case (for example, not_found or missing_permission). Branch on this rather than the message text.
- `message` (string, optional) — Error message.
- `fix` (string, optional) — The concrete next action that resolves the error.
- `docs` (string, optional) — Link to the error reference entry for this code.

### 404 Not Found Error

- `name` (string, required) — Name of error.
- `message` (string, required) — Error message.
- `code` (string, optional) — Stable, machine-readable error code in snake_case (for example, not_found or missing_permission). Branch on this rather than the message text.
- `fix` (string, optional) — The concrete next action that resolves the error.
- `docs` (string, optional) — Link to the error reference entry for this code.

### 403 App Signup Limit Error

The app's sign-up limit for your organization is reached, or the app has paused new sign-ups. `code` is `limit_exceeded` and `fix` says which. Inboxes that already have an account at the app can still sign in.

- `name` (string, required) — Name of error.
- `message` (string, required) — Error message.
- `code` (string, optional) — Stable, machine-readable error code in snake_case (for example, not_found or missing_permission). Branch on this rather than the message text.
- `fix` (string, optional) — The concrete next action that resolves the error.
- `docs` (string, optional) — Link to the error reference entry for this code.

## Examples

**Response**

```json
{
  "api_key_id": "api_key_id",
  "magic_url": "magic_url",
  "expires_at": "2024-01-15T09:30:00Z"
}
```

**SDK Code**

```python
import requests

url = "https://api.agentmail.to/v0/apps/d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32/connect"

headers = {"Authorization": "Bearer <api_key>"}

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

print(response.json())
```

```javascript
const url = 'https://api.agentmail.to/v0/apps/d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32/connect';
const options = {method: 'POST', headers: {Authorization: 'Bearer <api_key>'}};

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

```go
package main

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

func main() {

	url := "https://api.agentmail.to/v0/apps/d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32/connect"

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

	req.Header.Add("Authorization", "Bearer <api_key>")

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

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

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

}
```

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

url = URI("https://api.agentmail.to/v0/apps/d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32/connect")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <api_key>'

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

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

HttpResponse<String> response = Unirest.post("https://api.agentmail.to/v0/apps/d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32/connect")
  .header("Authorization", "Bearer <api_key>")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.agentmail.to/v0/apps/d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32/connect', [
  'headers' => [
    'Authorization' => 'Bearer <api_key>',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.agentmail.to/v0/apps/d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32/connect");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <api_key>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Authorization": "Bearer <api_key>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.agentmail.to/v0/apps/d5e9c84f-c2b2-4bf4-b4b0-7ffd7a9ffc32/connect")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

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()
```