Widget Redirection & Completion
Widget Redirection & Completion
Configure client-side redirection and post-session behaviors once a widget flow finishes
The Spain Public Administration Flow API allows you to control the user’s browser redirection behavior once they complete or exit the data extraction widget. This is done by configuring completion settings during session initialization.
Redirection Settings
When calling Create Session, you can customize redirection behaviors under the settings object using the following parameters:
completion_mode: The redirection behavior (e.g. standard redirect, opening a new tab, closing the tab, or doing nothing).completion_url: The destination URL to navigate to (required if redirecting). Supports dynamic template variables in both the URL path and query string.completion_extra_data: A dictionary of key-value pairs. All keys and values are automatically serialized into query parameters and appended to the final redirect URL. Values in this dictionary support dynamic template variables.
Authorized Redirect Domains
For security reasons (to prevent open-redirect vulnerabilities), the domain of the completion_url must be pre-authorized and listed in your application’s allowed redirect domains. You can configure and manage your authorized domains list in the Infonite Dashboard. Redirection to unlisted domains will fail.
Completion Modes
You can specify how the widget behaves upon exit by setting completion_mode to one of the following values:
Prefer redirect over redirect_blank
Modern web browsers restrict scripts from automatically opening new tabs (window.open(..., '_blank')) unless triggered by a direct user action (like a click). Since widget redirection is automatic upon flow completion, browsers might block redirect_blank as a popup.
Script Restrictions with close_tab
Browsers only permit scripts to close tabs that were originally opened by a script (using window.open). If the user navigated directly to the widget, close_tab will fail silently due to browser security restrictions.
Dynamic Query Parameters & Templating
The widget engine supports dynamic runtime template variables to construct customized redirect flows. These settings are configured inside the settings object of the Create Session initialization request payload.
These template variables can be used in two ways:
- Directly in the URL: Interpolated within the
completion_urlstring (either in the URL path or in query parameters). - In Extra Data values: Interpolated inside the values of the
completion_extra_datadictionary.
Additionally, the completion_extra_data dictionary is automatically converted to query parameters and appended to the final URL.
Available Template Variables
{app_id}: The unique identifier of your application.{customer_id}: The customer ID associated with the session.{session_id}: The active widget session ID.{status_code}: The final status code of the session (e.g.COMPLETED).
Example Parameter Mapping
If you initialize a session with a URL template path and an extra data dictionary (demonstrating how template variables can be partially interpolated inside composite strings, such as prefixing the session ID):
The template variables are resolved and the dictionary is serialized into query parameters, redirecting the user to:
Data Security Warning
All redirect parameters, whether interpolated directly in the completion_url path or passed via the completion_extra_data dictionary, are exposed in the final browser URL query string. This makes them visible in browser history, network logs, and referrer headers. Never pass sensitive personal data (such as names, emails, phones, or DNI numbers) as template variables. Use generic identifiers like {session_id} and fetch the results securely on your backend.
Real-World Examples
The following examples demonstrate how to construct the request payload when calling the Create Session endpoint.
Note that all redirection settings must be nested inside the settings object of the initialization payload, alongside other session configurations (such as required features).
Redirect the user back to your customer portal, passing the session status and customer ID to automatically refresh their application state:
Resulting URL:
Assuming a session with ID 644599da47847b79c03cc94f, customer ID cust_esp_202406, and status code COMPLETED, the final resolved URL is:
The modern way to trigger a WhatsApp chat is using https://wa.me/<<phone>>. You can pass a pre-filled template message inside the text query parameter:
Resulting URL:
The template variables will be resolved, and the dictionary keys and values will be automatically URL-encoded and appended. For a session with ID 644599da47847b79c03cc94f, the final resolved URL is:
If you need to use the legacy WhatsApp API endpoint (https://api.whatsapp.com/send), you pass both the phone number and language settings in completion_extra_data:
Resulting URL:
For a session with ID 644599da47847b79c03cc94f, the query parameters will be serialized, URL-encoded, and appended:
Iframe postMessage Events
If you embed the widget inside an HTML <iframe> on your website, the widget will dispatch a JavaScript message event to the parent window upon completion or exit, regardless of the configured completion_mode. This is useful for programmatically closing the iframe, refreshing parent page components, or showing custom UI elements on the host platform.
Event Message Structure
When the session reaches its end screen, the widget calls window.parent.postMessage() with a payload structured as follows:
event: The event identifier string (alwayses-public-administration:ended).status_code: The final execution status of the session (e.g.COMPLETED,FAILED,WAITING).cursor: The identifier of the active cursor/screen the user was on when the widget session finished. Possible values include:es-public-administration:bye:completed: The user successfully completed the data retrieval and signature flow.es-public-administration:bye:failure: An execution failure occurred and the session ended.es-public-administration:connect:wait: The session is temporarily waiting for an asynchronous background task or report generation (e.g., generating the CIRBE report).
The widget closing is not the session ending. When status_code is WAITING and the cursor is es-public-administration:connect:wait, the user is free to go but a source — typically the CIRBE report — is still working in the background.
This browser message tells you the widget is gone; it does not carry results, and it is not a completion signal. The data reaches your backend through webhooks: es-public-administration:partial with what was gathered so far, and es-public-administration:ended with the final data once the pending source answers.
A session is finished when — and only when — is_closed is true. See Knowing when a session is finished.
Integration Example
To handle the completion event in your host application, register a listener for the window message event: