Tutorial: Embedded Flow with Inquiry Template
Tutorial: Embedded Flow with Inquiry Template
Tutorial: Embedded Flow with Inquiry Template
An Embedded Flow embeds Persona’s verification UI directly into your website as an iframe.
There are two ways to use Embedded Flow:
This guide walks you through the first method: generating inquiries from an inquiry template.
You will:
Generating inquiries from an inquiry template (the method shown in this guide) is the fastest way to implement Embedded Flow. However, due to limitations of this method, we recommend you pre-create inquiries in production. To learn how, see Tutorial: Pre-create inquiries for Embedded Flow.
You’ll need:
localhost using Python, but you can adapt the setup to another language.Before you start, you should:
A user named Alexander Sample just joined your dog walking app as a dog walker. You want to verify his identity to ensure the safety of users on your service.
Alexander’s user ID in your app is “usr_ABC123”. During account signup in your app, he stated his birthdate is August 31, 1977.
Every inquiry is created from an inquiry template, which defines details like the specific verification logic and UI text and branding of that inquiry. You can think of inquiry templates as a mold that lets you create many inquiries.
Persona offers a suite of solutions that include preconfigured inquiry templates. In this tutorial, use the “KYC” solution to verify your dog walkers.
Follow these instructions to add the “KYC” solution to your Sandbox environment.
Find the ID of the newly-created inquiry template.
In the Persona dashboard, navigate to Inquiries > Templates. Find the “KYC” template in the list of inquiry templates, and note the value in the ID field. The value should begin with itmpl_.
Now, set up the user onboarding page that will display the verification flow to Alexander.
Create a new directory called embedded-flow-demo/.
Inside that directory, create a file called onboarding.html with the following code:
Start a local Python server to host this file:
Load localhost:8000/onboarding.html in a browser to view the page.
You should see the onboarding flow for our newly-registered dog walker:
Right now, the “Start Verifying” button doesn’t work. You’ll wire it up in Step 5.
The web page code does not yet contain the Persona SDK. Let’s add it.
<head> section of onboarding.html, add the following lines right after the closing </style> tag:X.Y.Z. in the CDN URL with the latest version of the SDK. Check the SDK changelog for the latest version.
https://cdn.withpersona.com/dist/persona-v5.4.0.jsYou can also install the SDK as an npm package.
Right now, if you click “Start Verifying”, you see an alert. Make the button trigger a Persona verification flow instead.
itmpl_XXXXXXXXXXXXX with your inquiry template ID from Step 2.env_XXXXXXXXXXXXX with the ID of the Persona environment you’re using. In this tutorial, we’re using your Sandbox environment. Here’s how to find the ID of your environment.This code creates a new Persona web client (new Persona.Client({...})). Note that:
new Persona.Client({...}) is invoked.templateId at minimum. If you don’t provide an environment ID, by default your production environment is used.onComplete and onError, let you coordinate your app’s UI with changes in the Persona UI. Do not rely on them for up-to-date data about the state of the inquiry. Use webhooks (Step 6) for logic that depends on inquiry state.This code demonstrates two best practices for initiating inquiries:
reference-id. A reference ID lets you tag an inquiry as being associated with a particular end user. Persona recommends using the user’s UID from your internal systems.You can receive notifications when any inquiry’s state changes. For example, you can be alerted when any inquiry is started by a user, or when any inquiry is completed. See the full list of inquiry events you can be alerted about.
To receive automatic notifications:
inquiry.started, inquiry.completed, inquiry.approved, inquiry.declined, and inquiry.failedFor this tutorial, you can skip webhooks and view results in the dashboard.
In production, Alexander would click the “Start Verifying” button and complete verification on his own.
For this tutorial, you’ll complete the flow yourself as Alexander:
The inquiry ID will look like inq_XXXXXXXXXXXXX.
If you set up the webhook in Step 6, check your server logs. You should see events from inquiry.started, inquiry.completed, and inquiry.approved.
Note: If you want to receive the inquiry.failed event, you can reload the page and click “Start Verifying” again. Then click through the verification flow, this time with the “Pass verifications” toggle disabled.
Now that you’ve completed the inquiry, take a look at the results. Note that because this inquiry was created in Sandbox, some of the data will be demo data.
Retrieve the inquiry details:
The response includes:
data.attributes.reference-id: The reference ID you provideddata.attributes.status: Should be approveddata.attributes.fields: Prefilled and collected dataNote that:
approved instead of completed because the KYC solution includes Workflows that automatically approve passing inquiries. See the Next Steps section to learn more.Alternative: View in Dashboard You can also view results in the dashboard at Inquiries > All Inquiries. See this Help Center guide for details.
In this tutorial, you:
This is a complete Embedded Flow integration that creates inquiries using an inquiry template.
This implementation is simple, but has drawbacks:
To address these issues, Persona recommends you pre-create inquiries on your server in production. See Tutorial: Pre-create inquiries for Embedded Flow to learn how.
Enhance this integration:
Explore further:
completed to approved.