# Sign up and get a code

Starts sign-up without a browser: we email a code with 8 digits to the address. It works once and for 15 minutes. accept_terms must be true. The answer is the same whether the address already has an account or not; an existing account gets an additional key in the next step. No API key needed.

`POST https://api.switchfile.io/v1/signup`

No API key needed.

## Example

cURL:

```bash
curl "https://api.switchfile.io/v1/signup" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "agent@example.com",
    "accept_terms": true
  }'
```

Node.js:

```js
const res = await fetch("https://api.switchfile.io/v1/signup", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    email: "agent@example.com",
    accept_terms: true
  }),
});
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
console.log(await res.json());
```

PHP:

```php
<?php
$ch = curl_init('https://api.switchfile.io/v1/signup');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => json_encode([
        'email' => 'agent@example.com',
        'accept_terms' => true,
    ]),
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
    ],
    CURLOPT_RETURNTRANSFER => true,
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

if ($status >= 400) {
    throw new RuntimeException("HTTP $status: $response");
}
print_r(json_decode($response, true));
```

Python:

```python
import requests

res = requests.post(
    "https://api.switchfile.io/v1/signup",
    json={
        "email": "agent@example.com",
        "accept_terms": True,
    },
)
res.raise_for_status()
print(res.json())
```

## Request body

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `accept_terms` | boolean | no | Must be true: you accept the terms (https://switchfile.io/terms). See the privacy policy at https://switchfile.io/privacy |
| `email` | string | yes | Your email address. The code goes there (3 to 254 characters) |

## Responses

### 202: The code is on its way. New and existing accounts get the same answer

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `email` | string | yes | The address the code was sent to |
| `expires_in` | string (integer) \| integer | yes | Seconds until the code expires |
| `message` | string | yes |  |
| `status` | string | yes | (one of "code_sent") |
| `verify_url` | string | yes | Send the code here, together with the email address |

Example (application/json):

```json
{
  "status": "code_sent",
  "email": "agent@example.com",
  "expires_in": 900,
  "verify_url": "https://api.switchfile.io/v1/signup/verify",
  "message": "We sent a code with 8 digits to agent@example.com. Send it with the email address to POST https://api.switchfile.io/v1/signup/verify within 15 minutes."
}
```

### 400: accept_terms is missing or not true (TERMS_NOT_ACCEPTED), the email is not one plain address without a name or angle brackets (INVALID_EMAIL), or the address belongs to a disposable email service (DISPOSABLE_EMAIL) (`TERMS_NOT_ACCEPTED`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-terms-not-accepted",
  "title": "Terms not accepted",
  "status": 400,
  "code": "TERMS_NOT_ACCEPTED",
  "detail": "To sign up, accept the terms by sending \"accept_terms\": true. Terms: https://switchfile.io/terms. Privacy policy: https://switchfile.io/privacy.",
  "terms_url": "https://switchfile.io/terms",
  "privacy_url": "https://switchfile.io/privacy"
}
```

### 422: A field is missing or has the wrong type (`INVALID_DATA`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-invalid-data",
  "title": "Invalid data",
  "status": 422,
  "code": "INVALID_DATA",
  "detail": "The request contains invalid data.",
  "errors": {
    "email": [
      "Enter a valid email address."
    ]
  }
}
```

### 429: Too many codes for this address (5 per hour) or from this IP address (10 per hour). See Retry-After (`RATE_LIMIT_EXCEEDED`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-rate-limit-exceeded",
  "title": "Rate limit exceeded",
  "status": 429,
  "code": "RATE_LIMIT_EXCEEDED",
  "detail": "Too many codes requested. Try again in 42 minutes."
}
```

### 503: Email or sign-up is not available right now (MAIL_NOT_CONFIGURED, MAIL_SEND_FAILED, SIGNUP_UNAVAILABLE). See Retry-After (`MAIL_SEND_FAILED`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-mail-send-failed",
  "title": "Mail send failed",
  "status": 503,
  "code": "MAIL_SEND_FAILED",
  "detail": "We couldn't send the email right now. Try again in a few minutes."
}
```

Error bodies and codes are explained in [Errors](https://switchfile.io/docs/errors).
