Upload PDFs via API
Prerequisites for Using SmartUI
- Familiarity with HTTP APIs is essential.
- Visit the
LambdaTest SmartUIpage and log in with your credentials. - Obtain your
LT_USERNAMEandLT_ACCESS_KEYby clicking on theAccess Keybutton, located at the top right corner of your dashboard.
Step 1: Establishing a SmartUI Project
To initiate a SmartUI PDF Comparison Project, adhere to the following instructions:
- Navigate to the SmartUI Projects Page.
- Tap on the
new projectbutton. - Specify your platform type as
PDF. - Provide your
projectname, designateapprovers, and addtags(optional). - Confirm your entry by clicking on Submit.
Once your project is active, retrieve your Project Token from the application. Here's an example of a project token:
projectToken = "123456#1234abcd-****-****-****-************"
Uploading PDFs via API
After setting up your SmartUI Project, you can upload your local PDF files to your project. This will automatically generate a build by capturing snapshots of every page.
Here's how you can upload your PDFs:
-
Retrieve your API
URL Endpointpost activation of your enterprise plan. To schedule a demonstration, click here. -
Append the following parameters to your request payload via
form-body:
| Variable | Type | Description | Required? |
|---|---|---|---|
| projectToken | string | This token is required to upload PDF files and validate your project. Example: projectToken:123456#1234abcd-****-****-****-************ | Yes |
| pathToFiles | array | Add the path to the PDFs that will be uploaded. Example: pathToFiles : [ "path/to/pdf-1", "path/to/pdf-2"] | Yes |
| buildName | string | Assign a name of your choice to the build comprising the uploaded PDFs. Example: buildName : #<Build_Name> | No |
Only files in .pdf format are compatible with this feature.
API Request Example
Here's a sample API request using cURL:
curl -X POST "YOUR_API_ENDPOINT" \
-H "Content-Type: multipart/form-data" \
-F "projectToken=123456#1234abcd-****-****-****-************" \
-F "pathToFiles[]=path/to/document1.pdf" \
-F "pathToFiles[]=path/to/document2.pdf" \
-F "buildName=Release-v2.1"
Response Format
The API will return a JSON response containing:
- Build ID: Unique identifier for the uploaded build
- Status: Upload status (success/failure)
- Pages Captured: Number of pages processed
- Test Results: Visual comparison results (if available)
Use Cases
- Automated CI/CD Integration: Seamlessly integrate PDF testing into your deployment pipeline
- Batch Processing: Upload multiple PDFs simultaneously for efficient testing
- Custom Workflows: Build custom applications that interact with SmartUI programmatically
- Enterprise Integration: Connect with existing enterprise systems and workflows
Best Practices
- PDF File Management
- Project Token Management
- Build Naming
- Error Handling
- Batch Processing
PDF File Management
- Use consistent naming conventions for PDF files
- Organize PDFs in logical directory structures
- Verify PDF files are valid and not corrupted before upload
- Keep PDF files in version control when appropriate
Project Token Management
- Store project token as environment variable
- Never commit tokens to version control
- Use different tokens for different environments
- Rotate tokens regularly
Build Naming
- Use meaningful build names that include version info
- Include date or version in build names
- Use consistent naming conventions
Example:
buildName="PDF-Comparison-v1.0-$(date +%Y%m%d)"
Error Handling
- Always check API response status
- Handle network failures gracefully
- Implement retry logic for transient failures
- Log errors for debugging
Batch Processing
- Process PDFs in batches for efficiency
- Monitor upload progress
- Handle partial failures in batch operations
- Use appropriate batch sizes
Troubleshooting
- PDF Upload Fails
- Project Not Found Error
- Upload Returns Error Response
- PDFs Not Appearing in Dashboard
Issue: PDF Upload Fails
Symptoms: PDF upload returns error or fails silently
Possible Causes:
- Invalid PDF file
- File path incorrect
- File size too large
- Network connectivity issues
- Project token incorrect
- API endpoint incorrect
Solutions:
- Verify PDF file is valid and not corrupted
- Check file path is correct and accessible
- Verify file size is within limits
- Check network connectivity to LambdaTest servers
- Verify PROJECT_TOKEN is set correctly
- Confirm API endpoint URL is correct
Issue: "Project Not Found" Error
Symptoms: Error message indicating project cannot be found
Possible Causes:
- Incorrect project token
- Project deleted or renamed
- Token from wrong project
Solutions:
- Verify project exists in SmartUI dashboard
- Copy project token directly from Project Settings
- Ensure token includes the project ID prefix (e.g.,
123456#...) - Check for extra spaces or quotes in token
Issue: Upload Returns Error Response
Symptoms: API returns error status or failure message
Possible Causes:
- Invalid request format
- Missing required parameters
- Authentication issues
- Server-side processing error
Solutions:
- Verify request format matches API specification
- Check all required parameters are included
- Verify authentication credentials
- Review error response for specific details
- Retry upload if transient error
Issue: PDFs Not Appearing in Dashboard
Symptoms: Uploads complete but PDFs don't appear in SmartUI dashboard
Possible Causes:
- Incorrect project token
- Project name mismatch
- Upload not completed
- Dashboard refresh needed
Solutions:
- Verify PROJECT_TOKEN is correct
- Check project name matches exactly (case-sensitive)
- Wait a few moments and refresh dashboard
- Check upload response for errors
- Review API response for upload status
Getting Help
If you encounter issues not covered here:
- Review the Comprehensive Troubleshooting Guide for detailed solutions
- Check PDF Comparison Overview for PDF-specific information
- See PDF CLI Upload for alternative upload methods
- Visit LambdaTest Support for additional resources
- Contact support at support@lambdatest.com or use 24/7 Chat Support
