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

# Apple Sign-In

POST https://api.customerhub.com/web_api/session/apple_auth
Content-Type: application/json

Authenticate with an Apple identity token and open a session.

**Authentication:** Public — no Bearer token required.

**Request body:**
- `id_token` (required) — Apple identity token from Sign in with Apple
- `mode` (optional) — Sign-in mode; controls whether an unknown account may be registered
- `user_data` (optional) — Profile payload Apple returns on the first authorization only (name fields), used to populate a new account

**Response (signed in):** Standard login payload — `data.token`, `data.location`, `data.user`, plus `data.admin_token` and `data.redirect_url` when applicable.

**Response (2FA enabled):** `data.otp_required` is `true` and `data.otp_token` carries a 5-minute token to submit to `POST /session/verify_otp`.

**Response (unregistered account):** `data.needs_registration` is `true`, alongside `provider`, `email`, `first_name`, and `last_name` so the client can complete registration.

**Side effects:** Triggers a `UserLogin` event recording the IP address and `provider` set to `apple`.

Reference: https://customerhub.com/api/api-reference/sessions/apple-sign-in

## Authentication

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

## Request

### Body (application/json)

This endpoint expects an object.

- `id_token` (string, optional)
- `mode` (string, optional)
- `user_data` (SessionAppleAuthPostRequestBodyContentApplicationJsonSchemaUserData, optional)

## Response

### 200

OK

## Types

### SessionAppleAuthPostRequestBodyContentApplicationJsonSchemaUserData

- `name` (SessionAppleAuthPostRequestBodyContentApplicationJsonSchemaUserDataName, optional)

### SessionAppleAuthPostRequestBodyContentApplicationJsonSchemaUserDataName

- `firstName` (string, optional)
- `lastName` (string, optional)

## Examples

### Success

**Request**

```json
{
  "id_token": "apple-identity-token",
  "mode": "login",
  "user_data": {
    "name": {
      "firstName": "John",
      "lastName": "Doe"
    }
  }
}
```

**Response**

```json
{
  "data": {
    "location": "/dashboard",
    "token": "eyJhbGciOiJIUzI1NiJ9...",
    "user": {
      "avatar_url": null,
      "email": "user@example.com",
      "first_name": "John",
      "id": 1,
      "last_name": "Doe",
      "status": "active"
    }
  }
}
```

**SDK Code**

```python Success
import requests

url = "https://api.customerhub.com/web_api/session/apple_auth"

payload = {
    "id_token": "apple-identity-token",
    "mode": "login",
    "user_data": { "name": {
            "firstName": "John",
            "lastName": "Doe"
        } }
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Success
const url = 'https://api.customerhub.com/web_api/session/apple_auth';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"id_token":"apple-identity-token","mode":"login","user_data":{"name":{"firstName":"John","lastName":"Doe"}}}'
};

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://api.customerhub.com/web_api/session/apple_auth"

	payload := strings.NewReader("{\n  \"id_token\": \"apple-identity-token\",\n  \"mode\": \"login\",\n  \"user_data\": {\n    \"name\": {\n      \"firstName\": \"John\",\n      \"lastName\": \"Doe\"\n    }\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://api.customerhub.com/web_api/session/apple_auth")

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  \"id_token\": \"apple-identity-token\",\n  \"mode\": \"login\",\n  \"user_data\": {\n    \"name\": {\n      \"firstName\": \"John\",\n      \"lastName\": \"Doe\"\n    }\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://api.customerhub.com/web_api/session/apple_auth")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"id_token\": \"apple-identity-token\",\n  \"mode\": \"login\",\n  \"user_data\": {\n    \"name\": {\n      \"firstName\": \"John\",\n      \"lastName\": \"Doe\"\n    }\n  }\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.customerhub.com/web_api/session/apple_auth', [
  'body' => '{
  "id_token": "apple-identity-token",
  "mode": "login",
  "user_data": {
    "name": {
      "firstName": "John",
      "lastName": "Doe"
    }
  }
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Success
using RestSharp;

var client = new RestClient("https://api.customerhub.com/web_api/session/apple_auth");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"id_token\": \"apple-identity-token\",\n  \"mode\": \"login\",\n  \"user_data\": {\n    \"name\": {\n      \"firstName\": \"John\",\n      \"lastName\": \"Doe\"\n    }\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Success
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "id_token": "apple-identity-token",
  "mode": "login",
  "user_data": ["name": [
      "firstName": "John",
      "lastName": "Doe"
    ]]
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.customerhub.com/web_api/session/apple_auth")! 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()
```

### Two-Factor Required

**Request**

```json
{
  "id_token": "apple-identity-token",
  "mode": "login",
  "user_data": {
    "name": {
      "firstName": "John",
      "lastName": "Doe"
    }
  }
}
```

**Response**

```json
{
  "data": {
    "otp_required": true,
    "otp_token": "eyJhbGciOiJIUzI1NiJ9..."
  }
}
```

**SDK Code**

```python Two-Factor Required
import requests

url = "https://api.customerhub.com/web_api/session/apple_auth"

payload = {
    "id_token": "apple-identity-token",
    "mode": "login",
    "user_data": { "name": {
            "firstName": "John",
            "lastName": "Doe"
        } }
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Two-Factor Required
const url = 'https://api.customerhub.com/web_api/session/apple_auth';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"id_token":"apple-identity-token","mode":"login","user_data":{"name":{"firstName":"John","lastName":"Doe"}}}'
};

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

```go Two-Factor Required
package main

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

func main() {

	url := "https://api.customerhub.com/web_api/session/apple_auth"

	payload := strings.NewReader("{\n  \"id_token\": \"apple-identity-token\",\n  \"mode\": \"login\",\n  \"user_data\": {\n    \"name\": {\n      \"firstName\": \"John\",\n      \"lastName\": \"Doe\"\n    }\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 Two-Factor Required
require 'uri'
require 'net/http'

url = URI("https://api.customerhub.com/web_api/session/apple_auth")

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  \"id_token\": \"apple-identity-token\",\n  \"mode\": \"login\",\n  \"user_data\": {\n    \"name\": {\n      \"firstName\": \"John\",\n      \"lastName\": \"Doe\"\n    }\n  }\n}"

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

```java Two-Factor Required
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.customerhub.com/web_api/session/apple_auth")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"id_token\": \"apple-identity-token\",\n  \"mode\": \"login\",\n  \"user_data\": {\n    \"name\": {\n      \"firstName\": \"John\",\n      \"lastName\": \"Doe\"\n    }\n  }\n}")
  .asString();
```

```php Two-Factor Required
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.customerhub.com/web_api/session/apple_auth', [
  'body' => '{
  "id_token": "apple-identity-token",
  "mode": "login",
  "user_data": {
    "name": {
      "firstName": "John",
      "lastName": "Doe"
    }
  }
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Two-Factor Required
using RestSharp;

var client = new RestClient("https://api.customerhub.com/web_api/session/apple_auth");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"id_token\": \"apple-identity-token\",\n  \"mode\": \"login\",\n  \"user_data\": {\n    \"name\": {\n      \"firstName\": \"John\",\n      \"lastName\": \"Doe\"\n    }\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Two-Factor Required
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "id_token": "apple-identity-token",
  "mode": "login",
  "user_data": ["name": [
      "firstName": "John",
      "lastName": "Doe"
    ]]
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.customerhub.com/web_api/session/apple_auth")! 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()
```