Getting started overview

This guide outlines the process for new users to begin using the PrexView document generation API, focusing on the steps required to make a successful first API call. It covers account creation, credential retrieval, and executing a basic document generation request. PrexView is designed to automate the creation of documents such as invoices, contracts, and reports from structured data and predefined templates, as detailed on the PrexView documentation page.

Before initiating API requests, users typically design document templates using the online template designer. These templates define the layout and placeholders for dynamic data. The API then populates these templates with data provided in JSON format, rendering the final document in a specified output format, such as PDF.

The workflow for getting started generally follows these stages:

  1. Account Creation: Register for a PrexView account. A free tier is available for initial evaluation and low-volume use, offering up to 50 documents per month, as stated on the PrexView pricing page.
  2. API Key Retrieval: Locate and securely store your API key from the PrexView dashboard. This key authenticates all API requests.
  3. Template Design (Optional, but Recommended): Create a document template using the PrexView template designer. While not strictly part of the API call itself, a template is necessary for meaningful document generation.
  4. First API Request: Send a request to the PrexView API, including your API key, the ID of your template, and the data to populate the document.

This process is designed to be accessible to developers, with SDKs provided for common programming languages including Python and Node.js.

Step What to Do Where to Find
1. Sign Up Create a PrexView account. PrexView Homepage
2. Get API Key Retrieve your unique API key. PrexView Dashboard
3. Design Template Create or upload a document template. PrexView Template Designer
4. Install SDK (Optional) Install the client library for your preferred language. PrexView Documentation and SDKs
5. Make Request Send a document generation API call. PrexView API Reference

Create an account and get keys

To begin using PrexView, the first step is to create an account. This provides access to the PrexView dashboard, where you can manage templates, view usage statistics, and retrieve your API credentials.

  1. Navigate to the PrexView website: Go to www.prexview.com.
  2. Sign up: Locate the 'Sign Up' or 'Get Started Free' button, typically in the top right corner or prominent on the homepage.
  3. Complete registration: Provide the required information (e.g., email address, password). You may need to verify your email address.
  4. Access the Dashboard: After successful registration and login, you will be redirected to your PrexView dashboard.
  5. Retrieve API Key: Within the dashboard, navigate to a section usually labeled 'API Keys', 'Settings', or 'Developer Tools'. Your unique API key will be displayed here. The PrexView documentation on API access provides specific instructions for locating this key.

Important Security Note: Your API key acts as a bearer token, granting access to your PrexView account and services. Treat it with the same level of security as a password. Do not hardcode it directly into client-side code, expose it in public repositories, or share it unnecessarily. Best practices for securing API keys include using environment variables, dedicated secrets management services, or server-side proxying for client applications. The Google Maps API key best practices offer general guidance on API key security that is applicable to PrexView and other API services.

Your first request

After obtaining your API key, you can make your first document generation request. This example uses a simple JSON payload to populate a hypothetical template. For this example, assume you have a template with ID tpl_your_template_id and it expects a name field.

PrexView supports several client libraries, which streamline the process of interacting with the API. The following examples demonstrate how to make a request using Python and Node.js, as these are primary language examples highlighted in the PrexView developer experience notes.

Prerequisites

  • A PrexView account with an API key.
  • A PrexView template ID (e.g., tpl_your_template_id) that expects data for generation.
  • Python installed (for Python example) or Node.js installed (for Node.js example).

Python example

Install the PrexView Python SDK:

pip install prexview

Then, execute the following Python code:

import os
from prexview import PrexViewClient

API_KEY = os.environ.get("PREXVIEW_API_KEY") # It's recommended to use environment variables for keys
TEMPLATE_ID = "tpl_your_template_id" # Replace with your actual template ID

if not API_KEY:
    raise ValueError("PREXVIEW_API_KEY environment variable not set.")

client = PrexViewClient(API_KEY)

data = {
    "name": "Alice Smith"
}

try:
    # Generate a document (e.g., PDF by default)
    response = client.generate_document(TEMPLATE_ID, data)

    # The response.content contains the raw document bytes
    # For a PDF, you might save it to a file:
    with open("output.pdf", "wb") as f:
        f.write(response.content)
    print("Document generated successfully and saved as output.pdf")

except Exception as e:
    print(f"An error occurred: {e}")
    # For more detailed error handling, inspect response.status_code and response.text

Node.js example

Install the PrexView Node.js SDK:

npm install prexview

Then, execute the following Node.js code:

const PrexViewClient = require('prexview').PrexViewClient;

// It's recommended to use environment variables for keys
const API_KEY = process.env.PREXVIEW_API_KEY;
const TEMPLATE_ID = 'tpl_your_template_id'; // Replace with your actual template ID

if (!API_KEY) {
    throw new Error('PREXVIEW_API_KEY environment variable not set.');
}

const client = new PrexViewClient(API_KEY);

const data = {
    name: 'Bob Johnson'
};

async function generateAndSaveDocument() {
    try {
        // Generate a document (e.g., PDF by default)
        const response = await client.generateDocument(TEMPLATE_ID, data);

        // The response.data contains the raw document bytes (Buffer in Node.js)
        // For a PDF, you might save it to a file:
        const fs = require('fs');
        fs.writeFileSync('output.pdf', response.data);
        console.log('Document generated successfully and saved as output.pdf');

    } catch (error) {
        console.error('An error occurred:', error.response ? error.response.data : error.message);
        // For more detailed error handling, inspect error.response.status and error.response.data
    }
}

generateAndSaveDocument();

After running either of these scripts, a file named output.pdf should be created in the same directory, containing your generated document populated with the provided data.

Common next steps

Once you have successfully generated your first document, you can explore more advanced features and integrations:

  • Explore Template Functionality: Utilize the full capabilities of the PrexView Template Designer. This includes conditional rendering, loops for lists, and integration of images or barcodes.
  • Dynamic Data Structures: Experiment with more complex JSON data structures to feed into your templates, handling arrays, nested objects, and various data types.
  • Output Formats: PrexView supports various output formats beyond PDF, such as DOCX or HTML, which can be specified in the API request. Refer to the PrexView API reference documentation for available options.
  • Webhook Integration: Integrate webhooks to receive notifications when documents are successfully generated or if errors occur. This is useful for asynchronous processing and integrating with other systems. Many services, like Stripe's webhook documentation, provide general guidance on implementing and securing webhooks, which can be applied to PrexView.
  • Error Handling: Implement robust error handling in your application to gracefully manage API rate limits, invalid template IDs, or malformed data payloads. The API typically returns HTTP status codes and detailed error messages.
  • Scalability and Production Deployment: Consider moving your API key to a secure secrets management solution and optimizing your application for production loads. Evaluate PrexView's pricing plans to match your expected document generation volume.

Troubleshooting the first call

Encountering issues during your first API call is common. Here are some troubleshooting tips:

  • Check API Key: Ensure your API key is correct and has not expired. Double-check for typos and confirm it's passed correctly in the authentication header or client initialization.
  • Verify Template ID: Confirm that the TEMPLATE_ID in your code exactly matches an existing template ID in your PrexView account. A mismatch will result in a 'Template Not Found' error.
  • Inspect Data Payload: Ensure the JSON data you are sending matches the expected structure and field names within your PrexView template. Mismatched field names or incorrect data types for placeholders can lead to blank sections or errors in the generated document.
  • Review Error Messages: The PrexView API returns descriptive error messages and HTTP status codes. For example, a 401 Unauthorized typically indicates an API key issue, while a 400 Bad Request might point to an invalid template ID or malformed data. Consult the PrexView API reference for a comprehensive list of error codes and their meanings.
  • Check Network Connectivity: Ensure your development environment has outbound internet access to reach the PrexView API endpoints.
  • SDK Version: If using an SDK, ensure you have the latest stable version installed. Outdated SDKs might have bugs or lack support for recent API features.
  • Logging: Add logging to your application to print out the full API request (excluding the API key for security) and the raw API response. This can provide crucial details for diagnosing problems.
  • PrexView Dashboard: Check your PrexView dashboard for usage limits, active plans, or any service announcements that might affect API calls.