<span id="刷新同一访客session"></span>

# Refresh the same visitor session

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

Returns a new credential and a full 604800 seconds, retaining end_user_id. Old credentials remain valid until natural expiration. Explicit session invalidation returns 404/code17. A dependency 500 does not mean the visitor is invalid and must not clear identity.


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

<span id="调用前准备"></span>

## Before you call this API

Set `BASE_URL` to the product API prefix `https://api.moi.matrixorigin.cn/v5`; use the corresponding product API URL for a dedicated deployment.

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

<span id="请求"></span>

## Request

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

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

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

| Parameter | Location | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `webapp` | Body | string | Yes | Agent ID. |
| `t` | Body | string | Yes | Current publication credential. |
| `session` | Body | string | Yes | Still-valid visitor session; the field is not named s here. |

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

<span id="成功响应"></span>

## 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 and numeric code=0. Read data's [object descriptions](objects.md) alongside the example. The conversation creation example is only a field excerpt.

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

<span id="错误响应"></span>

## Error responses

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