Skip to content

pliancy/microsoft-partnercenter-node

Repository files navigation

Microsoft PartnerCenter and Graph API SDK for NodeJS

Getting Started

You can install the package with the following command:

npm install microsoft-partnercenter

or

yarn add microsoft-partnercenter

or

pnpm install microsoft-partnercenter

Partner Center API

Initialize with Client ID and Client Secret Auth & Partner Domain:

import { MicrosoftPartnerCenter } from "microsoft-partnercenter"

const msPartnerCenter = new MicrosoftPartnerCenter({
  partnerDomain: "partner.onmicrosoft.com",
  authentication: {
    clientId: "1",
    clientSecret: "1",
  },
})

Graph API

Initialize with Client ID, Client Secret, and Tenant ID:

import { MicrosoftGraphApi } from "microsoft-partnercenter"

const msGraphApi = new MicrosoftGraphApi({
  tenantId: "your-tenant-id",
  authentication: {
    clientId: "1",
    clientSecret: "1",
  },
})

Example Usage

Partner Center API

Get all Customers

await msPartnerCenter.getAllCustomers()

Create Order

const customerId = "123"
const billingCycle = "monthly"

const lineItems = [
  {
    offerId: "1",
    quantity: 16,
    termDuration: "P1M",
  },
]

await msPartnerCenter.createOrder(customerId, billingCycle, lineItems)

Graph API

Create a GDAP Relationship

const relationship = await msGraphApi.createGDAPRelationship({
  displayName: "My GDAP Relationship",
  partner: {
    tenantId: "partner-tenant-id",
  },
  customer: {
    tenantId: "customer-tenant-id",
  },
  accessDetails: {
    unifiedRoles: ["Directory Readers"],
  },
  duration: "P90D",
})

Get All GDAP Relationships

const relationships = await msGraphApi.getAllGDAPRelationships()

Create a Domain

const domain = await msGraphApi.createDomain("example.com")

Get All Domains

const domains = await msGraphApi.getAllDomains()

Authentication

Both the Partner Center API and Graph API support authentication using client credentials (client ID and client secret). The SDK handles token management and renewal automatically.

Error Handling

The SDK includes built-in error handling and will automatically retry on certain errors (e.g., 401 Unauthorized). You can configure retry behavior in the config object:

const msPartnerCenter = new MicrosoftPartnerCenter({
  // ... other config
  conflict: {
    retryOnConflict: true,
    retryOnConflictDelayMs: 1000,
    maximumRetries: 3,
  },
})

Documentation

For more detailed information about available methods and their parameters, please refer to the TypeScript definitions included with this package.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request