Skip to content

Latest commit

 

History

History
116 lines (79 loc) · 3 KB

File metadata and controls

116 lines (79 loc) · 3 KB

API Client Examples

Complete working examples demonstrating how to use the @visa/api-client package for direct REST API integration with VIC platform.

📖 What This Is

This package contains example code and workflows that demonstrate:

  • Direct REST API calls to VIC platform using VicApiClient
  • Automatic X-Pay token generation and MLE encryption
  • End-to-end workflow orchestration
  • Error handling and response processing patterns

Prerequisites

  • Node.js >= 18.0.0
  • Visa API credentials (VIC, VDP, MLE certificates)
  • Consumer ID and Enrollment Reference ID for testing
  • Packages must be built first (see Building section below)

Building

Before running the examples, you must build the required packages:

Option 1: Build Everything

# From api-examples directory
npm run build

This will automatically build all required packages and install dependencies.

Option 2: Build from Root

cd ../..
npm run build:packages

Configuration

  1. Copy the environment template:

    cp .env.example .env
  2. Edit .env with your actual Visa credentials:

    • VIC API credentials (API Key, Shared Secret)
    • MLE certificates and private key
    • Consumer ID and Enrollment Reference ID
    • Visa API base URL

Running Examples

After building the packages and configuring your environment, run the workflow examples:

Using npm Scripts (Recommended)

npm run api:create-cancel

Using tsx Directly

npx tsx workflows/create-and-cancel-instruction.ts

Project Structure

vic-api-examples/
├── workflows/              # End-to-end workflow examples
├── package.json           # Dependencies and scripts
├── tsconfig.json          # TypeScript configuration
├── .env.example           # Environment variable template
└── README.md             # This file

Troubleshooting

"Cannot find module '@visa/api-client'"

Make sure you've built the packages first:

npm run build

"Missing required environment variables"

Check that:

  • .env file exists
  • All required variables are set
  • No extra whitespace in values

API Errors with Correlation IDs

If you get API errors:

  • Check the correlation ID in the error message
  • Verify your credentials are correct
  • Ensure certificates are in correct PEM format
  • Check that Consumer ID and Enrollment Reference ID are valid

For More Information