JSPM

channelape-sdk

1.23.0-develop.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q71442F
  • License Apache-2.0

A client for interacting with ChannelApe's API

Package Exports

  • channelape-sdk

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (channelape-sdk) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ChannelApe SDK

TypeScript and JavaScript SDK for the ChannelApe REST API

Build Status Quality Gate Coverage

Features

Getting Started

The ChannelApe SDK is asynchronous and all functions return promises.

Creating a client

Create a new instance of the ChannelApeClient with your sessionId.

const channelApeClient = new ChannelApeClient({
  sessionId: '4674b668-c4d2-4270-bf9b-ebaab78c378d'
});

Optional client configurations

  • timeout - Number of milliseconds to wait for the API to send response headers. Defaults to 180000 (3 minutes). Cannot be set lower than 2000 (2 seconds).
  • endpoint - Envrionment endpoint you would like to hit. Defaults to https://api.channelape.com
  • logLevel - Level of logs you wish to see from the SDK. Defaults to OFF.
  • maximumRequestRetryTimeout - Number of milliseconds to keep retrying a request for when an undesired response status code is received. Defaults to 180000 (3 minutes). Cannot be set lower than 2000 (2 seconds).
  • minimumRequestRetryRandomDelay - Minimum number of milliseconds to randomly delay by when an undesired response status code is received. Defaults to 1000 (1 second). Cannot be set lower than 1000 (1 second).
  • maximumRequestRetryRandomDelay - Maximum number of milliseconds to randomly delay by when an undesired response status code is received. Defaults to 5000 (5 seconds). Cannot be set lower than 2000 (2 seconds).
  • maximumConcurrentConnections - Maximum number of connections or requests that can be made to the API at a single time. Defaults to 5.

Sessions

Get Session

A User Account session will include your userId which is useful when retrieving Businesses. API Account sessions will return an apiAccountId instead.

channelApeClient.sessions().get(sessionId)
  .then((session: Session) => {
    // do what you need to do with session data here
    // session will also include your userId or apiAccountId
  });

Actions

Get action

channelapeClient.actions().get(actionId)
  .then((action: Action) => {
    // do what you need to do with action data here
  });

Complete action

channelapeClient.actions().complete(actionId)
  .then((action: Action) => {
    // do what you need to do with action data here
  });

Update action with error

channelapeClient.actions().error(actionId)
  .then((action: Action) => {
    // do what you need to do with action data here
  });

Update action health check

channelapeClient.actions().updateHealthCheck(actionId)
  .then((action: Action) => {
    // do what you need to do with action data here
  });

Channels

Get channel

channelapeClient.channels().get(channelId)
  .then((channel: Channel) => {
    // do what you need to do with channel data here
  });

Get all channels for a business

channelapeClient.channels().get({ businessId: 'some-valid-business-id' })
  .then((channels: Channel[]) => {
    // do what you need to do with channel data here
  });

Suppliers

Get supplier

channelapeClient.suppliers().get(supplierId)
  .then((supplier: Supplier) => {
    // do what you need to do with supplier data here
  });

Get all suppliers for a business

channelapeClient.suppliers().get({ businessId: 'some-valid-business-id' })
  .then((suppliers: Supplier[]) => {
    // do what you need to do with supplier data here
  });

Orders

Get order

channelapeClient.orders().get(orderId)
  .then((order: Order) => {
    // do what you need to do with order data here
  });

Update order

channelapeClient.orders().update(order)
  .then((updatedOrder: Order) => {
    // do what you need to do with updatedOrder data here
  });

Patch order

channelapeClient.orders().patch(order)
  .then((patchedOrder: Order) => {
    // do what you need to do with patchedOrder data here
  });

Create order

const orderToCreate: OrderCreateRequest = {
  additionalFields: [
    { name: 'name', value: 'CA1001' },
    { name: 'order_number', value: '1001' }
  ],
  totalPrice: 295.99,
  alphabeticCurrencyCode: 'USD',
  channelId: 'your-channel-id',
  channelOrderId: 'specify-your-channel-order-id',
  customer: {
    firstName: 'John',
    lastName: 'Smith',
    name: 'John Smith',
    additionalFields: [
      { name: 'extraCustomerData', value: 'Put whatever you would like here' }
    ]
  },
  status: OrderStatus.OPEN,
  purchasedAt: new Date(),
  lineItems: [{
    id: 'some-line-item-id',
    quantity: 1,
    sku: 'NCC1701D',
    title: 'A model space ship',
    additionalFields: [
      { name: 'extraLineItemData', value: 'Put whatever you would like here' }
    ]
  }]
};
channelapeClient.orders().create(orderCreateRequest)
  .then((createdOrder: Order) => {
    // do what you need to do with the createdOrder data here
  });

Variants

Get Variant

const variantsRequest: VariantsRequest = {
  productId,
  inventoryItemValue
};
channelApeClient.variants().get(variantsRequest)
  .then((variant: Variant) => {
    // do what you need to do with variant data here
  });

Get Variants for a Product

const variantsRequestByProductId: VariantsRequestByProductId = {
  productId
};
channelApeClient.variants().get(variantsRequestByProductId)
  .then((variants: Variant[]) => {
    // do what you need to do with variant array
  })

Get Variant Search Results for a Vendor

const variantsRequest: VariantsSearchRequestByVendor = {
  vendor,
  businessId
};
channelApeClient.variants().search(variantsRequest)
  .then((variantSearchResults: VariantSearchResults[]) => {
    // do what you need to do with Variant Search Results array
  });

Get Variant Search Results using a Product Filter

const variantsRequest: VariantsSearchRequestByProductFilterId = {
  productFilterId
};
channelApeClient.variants().search(variantsRequest)
  .then((variantSearchResults: VariantSearchResults[]) => {
    // do what you need to do with Variant Search Results array
  });

Get Variant Search Results for a SKU

const variantsRequest: VariantsSearchRequestBySku = {
  sku,
  businessId
};
channelApeClient.variants().search(variantsRequest)
  .then((variantSearchResults: VariantSearchResults[]) => {
    // do what you need to do with Variant Search Results array
  });

Get Variant Search Results for a UPC

const variantsRequest: VariantsSearchRequestByUpc = {
  upc,
  businessId
};
channelApeClient.variants().search(variantsRequest)
  .then((variantSearchResults: VariantSearchResults[]) => {
    // do what you need to do with Variant Search Results array
  });

Get Variant Search Results for a Tag

const variantsRequest: VariantsSearchRequestByTag = {
  tag,
  businessId
};
channelApeClient.variants().search(variantsRequest)
  .then((variantSearchResults: VariantSearchResults[]) => {
    // do what you need to do with Variant Search Results array
  });

Businesses

Get Business

const businessesQueryRequestByBusinessId: BusinessesQueryRequestByBusinessId = {
  businessId
}
channelApeClient.businesses().get(businessesQueryRequestByBusinessId)
  .then((business: Business) => {
    // do what you need to do with business data here
  });

Get Businesses

const businessesQueryRequestByUserId: BusinessesQueryRequestByUserId = {
  userId
}
channelApeClient.businesses().get(businessesQueryRequestByUserId)
  .then((businesses: Business[]) => {
    // do what you need to do with businesses array data here
  });

See Sessions for how to retrieve your userId

Get Business Member

const businessMemberRequest: BusinessMemberRequest = {
  userId,
  businessId
}
channelApeClient.businesses().getBusinessMember(businessMemberQueryRequest)
  .then((businessMember: BusinessMember) => {
    // do what you need to do with the business member here
  });

Verify Business Member

const verificationCode = '1234567';
channelApeClient.businesses().verifyBusinessMember(verificationCode)
  .then((business: Business) => {
    // do what you need to do with the business here
  });

Create Business

const businessToCreate: BusinessCreateRequest = {
  name: 'Valid Business Name',
  timeZone: TimeZoneId.AMERICA_NEW_YORK,
  inventoryItemKey: InventoryItemKey.SKU,
  alphabeticCurrencyCode: AlphabeticCurrencyCode.USD
}
channelApeClient.businesses().create(businessToCreate)
  .then((business: Business) => {
    // do what you need to do with the newly created business here 
  });

Subscriptions

Get Subscription

const businessId = 'valid-business-id';
channelApeClient.subscriptions().get(businessId)
  .then((subscription: Subscription) => {
    // do what you need to do with subscription data here
  });

Order Activities

ChannelApe allows you to log any arbitrary action done to or information about an order through the Order Activities endpoint.

Create order activities

// Create an order activity if you know the channelId and channelOrderId of the order in question
const orderActivityCreateRequest: OrderActivityCreateRequestByChannel = {
  channelId: 'some-channel-id',
  channelOrderId: 'some-channel-order-id-belonging-to-the-specified-channel-id',
  operation: OrderActivityOperation.UPDATE,
  result: OrderActivityResult.SUCCESS,
  messages: [
    {
      description: 'Arbitrary text limited to 1000 characters',
      title: 'Arbitrary text limited to 100 characters.' // Order activities are grouped by title in the ChannelApe dashboard
    }
  ]
};


// Create an order activity if you know the ChannelApe Order ID (i.e. order.id) of the order in question
const orderActivityCreateRequest: OrderActivityCreateRequestByOrderId = {
  orderId: 'some-order-id',
  operation: OrderActivityOperation.CREATE,
  result: OrderActivityResult.ERROR,
  messages: [
    {
      description: 'Arbitrary text limited to 1000 characters',
      title: 'Arbitrary text limited to 100 characters.' // Order activities are grouped by title in the ChannelApe dashboard
    }
  ]
};

// Create an order activity if you know the channelOrderId and the businessId of the order in question
const orderActivityCreateRequest: OrderActivityCreateRequestByBusiness = {
  channelOrderId: 'some-channel-order-id',
  businessId: 'some-business-id-that-the-channel-order-id-belongs-to',
  operation: OrderActivityOperation.CREATE,
  result: OrderActivityResult.WARN,
  messages: [
    {
      description: 'Arbitrary text limited to 1000 characters',
      title: 'Arbitrary text limited to 100 characters.' // Order activities are grouped by title in the ChannelApe dashboard
    }
  ]
};

channelApeClient.orders().activities().create(orderActivityCreateRequest).then((orderActivity) => {
  // do what you need to do with orderActivity here
});

Analytics

Generate Analytics Embed

This can only be done with an end user account that has access to ChannelApe analytics.

const embedCode = 'valid-embed-code';
const timezone = 'America/New_York';
channelApeClient.analytics().generateEmbed(embedCode, timezone)
  .then((embed: Embed) => {
    // Render the embed in an iframe or in a browser.
  });

Available Analytics Embeds

channelApeClient.analytics().get()
  .then((reports[]: Embed) => {
    // Do what you need to with list of reports
  });

Get Analytics Token

channelApeClient.analytics().getToken()
  .then((token: Token) => {
    // Do what you need to with the token
  });

Product Filters

Create Product Filter

const productFilterRequest: ProductFilterRequest = {
  businessId: 'valid-business-id'
};
channelApeClient.productFilter().create({}, productFilterRequest)
  .then((productFilter: ProductFilter) => {
    // Do what you need with the filter
  });

Users

Get User

const userId: string = 'some-user-id';
channelApeClient.users().get(userId)
  .then((user: User) => {
    // Do what you need with the user
  });

Inventories

Get inventory item

const inventoryItemId: string = 'some-inventory-id';
channelApeClient.inventories().get(inventoryItemId)
  .then((inventoryItem: InventoryItem) => {
    // Do what you need with the inventory item
  });

Get businesses inventory item by SKU

const inventorySku: string = 'ABC-123';
const businessId: string = '1';
channelApeClient.inventories().get(businessId, inventorySku)
  .then((inventoryItem: InventoryItem) => {
    // Do what you need with the inventory item
  });

Create new Inventory Item

const inventoryItemCreateRequest: InventoryItemCreateRequest = {
  businessId: '1',
  sku: 'ABC-123',
  title: 'Cool inventory title'
};
channelApeClient.inventories().create(inventoryItemCreateRequest)
  .then((inventoryItem: InventoryItem) => {
    // Do what you need with the created inventory item
  });

Update Inventory Item

const inventoryItemUpdateRequest: InventoryItemUpdateRequest = {
  id: '123',
  sku: 'ABC-123',
  title: 'Cool inventory title'
};
channelApeClient.inventories().update(inventoryItemUpdateRequest)
  .then((inventoryItem: InventoryItem) => {
    // Do what you need with the updated inventory item
  });

Inventory Quantities

Adjust Inventory Item Quantity

const adjustmentRequest: AdjustmentRequest = {
  locationId: '123',
  inventoryStatus: 'ABC-123',
  quantity: 31
};
channelApeClient.inventories().quantities().adjust(adjustmentRequest)
  .then((adjustment: Adjustment) => {
    // Do what you need with the adjustment
  });

Set Inventory Item Quantity

const adjustmentRequest: AdjustmentRequest = {
  locationId: '123',
  inventoryStatus: 'ABC-123',
  quantity: 31
};
channelApeClient.inventories().quantities().set(adjustmentRequest)
  .then((adjustment: Adjustment) => {
    // Do what you need with the adjustment
  });

Retrieve an inventory item's current quantities

const inventoryItemId = '35';
channelApeClient.inventories().quantities().retrieve(inventoryItemId);
  .then((quantities: InventoryItemQuantity[]) => {
    // Do what you need with the inventory item quantities
  });

Locations

Get location

const locationId: string = 'some-location-id';
channelApeClient.locations().get(locationId)
  .then((location: Location) => {
    // Do what you need with the location
  });

Get locations for a business

const businessId: string = '1';
channelApeClient.locations().getByBusinessId(businessId)
  .then((location: Location) => {
    // Do what you need with the locations
  });

Create new Location

const locationCreationRequest: LocationCreateRequest = {
  businessId: '1',
  name: 'Some location Name'
};
channelApeClient.locations().create(locationCreationRequest)
  .then((location: Location) => {
    // Do what you need with the created location
  });

Update Location

const locationUpdateRequest: LocationUpdateRequest = {
  id: '123',
  name: 'Some updated location Name'
};
channelApeClient.locations().update(locationUpdateRequest)
  .then((location: Location) => {
    // Do what you need with the updated location
  });