# Create a visitor session

```{raw} html
<div class="mo-api-page-show-toc" aria-hidden="true"></div>
```

Creates a new anonymous visitor identity every time, without restoring previous visitor history. Credentials last 604800 seconds; subsequent data calls supply query parameter s.


```http
POST https://api.moi.matrixorigin.cn/v5/public/webapp/session
```

## Before you call this API

Set `BASE_URL` to the product API prefix `https://api.moi.matrixorigin.cn/v5`. For private deployments, use the corresponding product API URL.

[Prepare links and visitor identity in the same environment](identity-lifecycle.md#prepare). Do not supply a product PAT or Workspace request header.

## Request

:::::::{div} mo-api-tabs
::::::{tab-set}
:::::{tab-item} Request example

```bash
curl --request POST \
  "$BASE_URL/public/webapp/session" \
  --header "Content-Type: application/json" \
  --data @- <<JSON
{"webapp": "${AGENT_ID}", "t": "${WEBAPP_TOKEN}"}
JSON
```

:::::
:::::{tab-item} Parameters

| Parameter | Location | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `webapp` | Body | string | Yes | Agent ID from the link or resolve. |
| `t` | Body | string | Yes | Publication token or short code used by resolve. |

:::::
::::::
:::::::

## Successful response

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Response example

```json
{
  "code": 0,
  "data": {
    "session_token": "example-visitor-session",
    "expires_in": 604800
  }
}
```

:::::
:::::{tab-item} Fields

Success returns HTTP 200 with numeric code=0. Read data's [Object descriptions](objects.md) with the example; the conversation-creation example shows a field excerpt only.

:::::
::::::
:::::::

## Error responses

[Public errors and identity handling](identity-lifecycle.md#errors) distinguishes unavailable links, disablement, invalid sessions, parameters, and system failures.
