---
id: create-widget-token
title: Create widget token
hide_title: true
description: "How to create a Walley widget token"
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import Ingress from '../../../src/components/ingress/ingress.react';

<Ingress title="Create a widget token">
  Before using any of the widgets, a widget token must be acquired. This is done by sending a POST request to the widget endpoint on the backend channel. 
  The response contains the token to use when rendering the widget and an expiry date when the token is no longer valid.
</Ingress>

:::info Important
The widget token should be reused for all widgets until it expires.
Failing to do so will put our system under an unnecessary performance load, and might lead to a temporary shutdown of the feature for you.
:::

<Tabs defaultValue="req" values={[
{ label: 'Initialize Widget request', value: 'req', },
{ label: 'Initialize Widget response', value: 'res', }]}>
<TabItem value="req">

```http
POST /widgets HTTP/1.1
Host: api.uat.walleydev.com
Authorization: Bearer bXlVc2VybmFtZTpmN2E1ODA4MGQzZTk0M2VmNWYyMTZlMDE...
Content-Type: application/json

{
  "storeId": 123
}
```

</TabItem>

<TabItem value="res">

```http
HTTP/1.1 200 OK
Content-Type: application/json

{
  "id": "91714012-6ae9-4780-a927-fe459bc95bf6",
  "data": {
    "widgetToken": "widget-NO-0TTJOMERnUGlVN1JtazFwZUo2UmFZVW92dFA5cXpEOXVzZit5dFJlcVZ4QUdpMlF5MmdUNVVqN3I4T3BzVEpCekJCelNY",
    "expiresAt": "2019-12-07T07:16:49.8098107+00:00"
  },
  "error": null
}
```

</TabItem>
</Tabs>

## Request headers

| Header            | Required | Explanation                                                                                                       |
| ----------------- | -------- | ----------------------------------------------------------------------------------------------------------------- |
| **Authorization** | Yes      | See [how to generate the authorization header value](/docs/checkout/authorization).                               |

## Request body properties

| Property    | Required | Explanation                                                                                      |
| ----------- | -------- | ------------------------------------------------------------------------------------------------ |
| **storeId** | Yes      | Store id related to markets SE, NO and FI are supported. Received from Walley Merchant Services. |

## Response

| Property        | Explanation                                                     |
| --------------- | --------------------------------------------------------------- |
| **widgetToken** | The token used to render the widget.                            |
| **expiresAt**   | The timestamp when the token expires and can no longer be used. |
