Getting Started with PayPal Server SDK

June 5, 2026 ยท View on GitHub

Introduction

Important Notes

  • Available Features: This SDK currently contains only 5 of PayPal's API endpoints. Additional endpoints and functionality will be added in the future.

Information

The PayPal Server SDK provides integration access to the PayPal REST APIs. The API endpoints are divided into distinct controllers:

Install the Package

Run the following command from your project directory to install the package from npm:

npm install @paypal/paypal-server-sdk@2.4.0

For additional package details, see the Npm page for the @paypal/paypal-server-sdk@2.4.0 npm.

Initialize the API Client

Note: Documentation for the client can be found here.

The following parameters are configurable for the API Client:

ParameterTypeDescription
environmentEnvironmentThe API environment.
Default: Environment.Sandbox
timeoutnumberTimeout for API calls.
Default: 0
httpClientOptionsPartial<HttpClientOptions>Stable configurable http client options.
unstableHttpClientOptionsanyUnstable configurable http client options.
loggingPartialLoggingOptionsLogging Configuration to enable logging
clientCredentialsAuthCredentialsClientCredentialsAuthCredentialsThe credential object for clientCredentialsAuth

The API client can be initialized as follows:

Code-Based Client Initialization

import { Client, Environment, LogLevel } from '@paypal/paypal-server-sdk';

const client = new Client({
  clientCredentialsAuthCredentials: {
    oAuthClientId: 'OAuthClientId',
    oAuthClientSecret: 'OAuthClientSecret'
  },
  timeout: 0,
  environment: Environment.Sandbox,
  logging: {
    logLevel: LogLevel.Info,
    logRequest: {
      logBody: true
    },
    logResponse: {
      logHeaders: true
    }
  },
});

Configuration-Based Client Initialization

import * as path from 'path';
import * as fs from 'fs';
import { Client } from '@paypal/paypal-server-sdk';

// Provide absolute path for the configuration file
const absolutePath = path.resolve('./config.json');

// Read the configuration file content
const fileContent = fs.readFileSync(absolutePath, 'utf-8');

// Initialize client from JSON configuration content
const client = Client.fromJsonConfig(fileContent);

See the Configuration-Based Client Initialization section for details.

Environment-Based Client Initialization

import * as dotenv from 'dotenv';
import * as path from 'path';
import * as fs from 'fs';
import { Client } from '@paypal/paypal-server-sdk';

// Optional - Provide absolute path for the .env file
const absolutePath = path.resolve('./.env');

if (fs.existsSync(absolutePath)) {
  // Load environment variables from .env file
  dotenv.config({ path: absolutePath, override: true });
}

// Initialize client using environment variables
const client = Client.fromEnvironment(process.env);

See the Environment-Based Client Initialization section for details.

Environments

The SDK can be configured to use a different environment for making API calls. Available environments are:

Fields

NameDescription
ProductionPayPal Live Environment
SandboxDefault PayPal Sandbox Environment

Authorization

This API uses the following authentication schemes.

List of APIs

SDK Infrastructure

Configuration

HTTP

Utilities