> For the complete documentation index, see [llms.txt](https://legacy-docs.usesmileid.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://legacy-docs.usesmileid.com/integration-options/server-to-server/python/generate-token-for-web-integration.md).

# Generate Token for Web Integration

Required Class: **Web API Class**

## Generating a Token for Web Integration

To use our [web integration](/integration-options/web-mobile-web/web-integration.md), you must generate a web token for every instance of the widget you run. You can generate a token with this library by editing the sample code below with your own parameters:

```python
from smile_id_core import WebApi, ServerError

# Initialize
partner_id = "<Put your partner ID here>"; #login to the Smile ID portal to view your partner id
default_callback = "<Put your default callback url here>";
api_key = "<Put your API key here>"; # copy your API key from the Smile ID portal
sid_server = <0 | 1>; # Use 0 for the sandbox server, use 1 for production server

connection = WebApi(partner_id,default_callback,api_key,sid_server)

# Create required request parameters
user_id = "<put your unique ID for the user here>"; # Set your unique user_id
job_id = "<put your unique job ID here>"; # Set the unique job_id
product = "<put product name here>"; # Choose one of 'authentication', 'basic_kyc', 'smartselfie', 'biometric_kyc', 'enhanced_kyc', 'doc_verification'

# Generate the web token
try:
    response = connection.get_web_token(user_id,job_id,product)
except ValueError:
    # some of your params entered for a job are not valid or missing
    print("handle ValueError")
except ServerError:
    # Server returned an error
    print("handle ServerError")
except FileNotFoundError:
    # Sent a file which could not be found
    print("handle FileNotFoundError")
```

### Response

The response will return a json that contains the following:

```json
{
  "success": true,
  "token": "<token string>"
}
```

{% hint style="info" %}
For a comprehensive guide on using the web integration, check the [Usage](/integration-options/web-mobile-web/web-integration/usage.md) section of the Web Integration documentation.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://legacy-docs.usesmileid.com/integration-options/server-to-server/python/generate-token-for-web-integration.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
