Generating documents with Magic Links and sharing them

If you don't have the ability to display generated documents in your own application, you can let your customers securely view documents generated in Inkit using a Magic Link. With a Magic Link, anyone can view a document for either a specific period of time or a specific number of views.

To create a Magic Link, do the following:

  1. Set up the Magic Link app if you have not done so.

  2. Generate the document through the web app or the API.

📘

Note: You can also share a generated document with a Magic Link.

Generating a document with a Magic Link through the web app

To generate a document with a Magic Link using the Inkit web app, do the following:

  1. In the Inkit web app, select Documents in the left sidebar. Then click + Create and select Document from the dropdown list.

  2. In the Create Document page, select a template that you want to use to generate the document and click Continue.

  3. In the New Document panel, enter a Name of the document and an optional Description and click Continue.

  4. In the Fill Out Destinations panel, under Merge Fields enter Your Data for each Variable in your template.

    Click + Add.

    In the Add Destination dialog box, select Magic Link and click Continue.

    In the Magic Link tab, select the Authentication Type from the following options:

    • Email (users complete authentication through an email address)
    • Social (users complete authentication through a social login provider such as Google)

    Enter the email address of the Magic Link's recepient in Recipient’s Email Address and Authorization Email Address.

    To have documents expire after certain amount of time, select Expire after and specify the Amount of Time and the Unit of time. You can choose from the following units:

    • Minutes
    • Hours
    • Days

    Then select when to start the expiration timer from the following options:

    • Start expiration timer when link is sent
    • Start expiration timer when link is opened

    To have documents expire after specific number of views, select Expire after an Amount of Views and enter the maximum number of Views before the document expires.

    Note: If you select Expire after an Amount of Views, the link will expire in 10 days even if there are views remaining.

    Finally, click Generate Document, which will not only generate the document but also send a link to it to the recipient's email address.

Generating a document with a Magic Link through the API

To generate a document with a Magic Link and send a link to it through the API, use the following code, specifying your API key and template ID as well as your Magic Link settings:

   # Import the Inkit Python package
   import inkit
   from inkit.exceptions import InkitResponseException
   # Import json package
   import json

   # Replace the string below with your API key
   inkit.api_token = "ENTER YOUR API KEY"

   try:
      # Create a PDF document from a template
      resp = inkit.Render.create(
         # Specify the ID of the template
         template_id = "ENTER YOUR TEMPLATE ID",
         # Specify the data for the merge
         merge_parameters = {"Last": "Doe", "First": "John", "Middle": "X", "Address": "1234 Main St.", "Apt": "#1", "City": "New York", "State": "NY", "Zip": "10001", "Birth": "01/01/1980", "SSN": "123-45-6789", "Email": "[email protected]", "Phone": "(555) 555-5555", "Citizen": "X",},
         # Specify the name of the PDF file and Magic Link information
         destinations = {"inkit_storage": {"name": "John Doe I-9"}, "magic_link": {"retain_from_created": {"hours": 1}, "auth_email": "[email protected]", "recipient_email": "[email protected]", "expire_after_n_views": 1}}
      )
      # Print the JSON repsonse of the API call
      print(json.dumps(resp.data, indent = 3))
   except InkitResponseException as err:
      # Print any error
      print(err.response.data)
// Import the Inkit Node.js package
const Inkit = require("inkit");

// Replace the string below with your API key
Inkit.apiToken = "ENTER YOUR API KEY";

// Call the  PDF renderer
createRender();

// Create a PDF document from a template
async function createRender() {
    try {
        const result = await Inkit.Render.create({
            // Specify the ID of the template
            templateId: 'ENTER YOUR TEMPLATE ID',
            // Specify the data for the Name field
            mergeParameters:
                {"Last": "Doe", "First": "John", "Middle": "X", "Address": "1234 Main St.", "Apt": "#1", "City": "New York", "State": "NY", "Zip": "10001", "Birth": "01/01/1980", "SSN": "123-45-6789", "Email": "[email protected]", "Phone": "(555) 555-5555", "Citizen": "X",},
            // Specify the name of the PDF file and Magic Link information
            destinations: {"inkit_storage": {"name": "John Doe I-9"}, "magic_link": {"retain_from_created": {"hours": 1}, "auth_email": "[email protected]", "recipient_email": "[email protected]", "expire_after_n_views": 1}}
        });
        // Print the JSON response of the API call
        console.log(JSON.stringify(result.data, null, 3));
    } catch (error) {
        // Print any error
        console.error(error.response.status, error.response.statusText);
    }
}
curl --request POST \
     --url https://api.inkit.com/v1/generate \
     --header 'Content-Type: application/json' \
     --header 'X-Inkit-API-Token: ENTER YOUR API KEY' \
     --header 'accept: application/json' \
     --data '
{
  "merge_parameters": {
    "Last": "Doe",
    "First": "John",
    "Middle": "X",
    "Address": "1234 Main St.",
    "Apt": "#1",
    "City": "New York",
    "State": "NY",
    "Zip": "10001",
    "Birth": "01/01/1980",
    "SSN": "123-45-6789",
    "Email": "[email protected]",
    "Phone": "(555) 555-5555",
    "Citizen": "X"
  },
  "destinations": {
    "inkit_storage": {
      "name": "John Doe I-9"
    }
    "magic_link": {
      "retain_from_created": {
        "hours": 1
      },
      "auth_email": "[email protected]", 
      "recipient_email": "[email protected]", 
      "expire_after_n_views": 1
    }
  },
  "template_id": "ENTER YOUR TEMPLATE ID"
}
'

You can also create a Magic Link in the API reference.