TypeScript SDK for commercetools Composable Commerce Import API

Usage examples

Browser environment

<script src="https://unpkg.com/@commercetools/sdk-client-v2@latest/dist/commercetools-sdk-client-v2.umd.js"></script>
<script src="https://unpkg.com/@commercetools/importapi-sdk@latest/dist/commercetools-importapi-sdk.umd.js"></script>
<script>
// global: @commercetools/sdk-client-v2
// global: @commercetools/importapi-sdk
;(function () {
// We can now access the sdk-client-v2 and importapi-sdk object as:
// const { ClientBuilder } = this['@commercetools/sdk-client-v2']
// const { createApiBuilderFromCtpClient } = this['@commercetools/importapi-sdk']
// or
// const { ClientBuilder } = window['@commercetools/sdk-client-v2']
// const { createApiBuilderFromCtpClient } = window['@commercetools/importapi-sdk']
})()
</script>

Node environment

npm install --save @commercetools/sdk-client-v2
npm install --save @commercetools/importapi-sdk
const {
ClientBuilder,
createAuthForClientCredentialsFlow,
createHttpClient,
} = require('@commercetools/sdk-client-v2')
const { createApiBuilderFromCtpClient } = require('@commercetools/importapi-sdk')
const fetch = require('node-fetch')

const projectKey = 'mc-project-key'
const authMiddlewareOptions = {
host: 'https://auth.europe-west1.gcp.commercetools.com',
projectKey,
credentials: {
clientId: 'mc-client-id',
clientSecret: 'mc-client-secrets',
},
oauthUri: '/oauth/token', // - optional: custom oauthUri
scopes: [`manage_project:${projectKey}`],
fetch,
}

const httpMiddlewareOptions = {
host: 'https://import.europe-west1.gcp.commercetools.com',
fetch,
}

const client = new ClientBuilder()
.withProjectKey(projectKey)
.withMiddleware(createAuthForClientCredentialsFlow(authMiddlewareOptions))
.withMiddleware(createHttpClient(httpMiddlewareOptions))
.withUserAgentMiddleware()
.build()

// or
const client = new ClientBuilder()
.withProjectKey(projectKey)
.withClientCredentialsFlow(authMiddlewareOptions)
.withHttpMiddleware(httpMiddlewareOptions)
.withUserAgentMiddleware()
.build()


const apiRoot = createApiBuilderFromCtpClient(client)

// calling the importapi functions
// get project details
apiRoot
.withProjectKeyValue({
projectKey,
})
.importContainers()
.get()
.execute()
.then((x) => {
/*...*/
})


// -----------------------------------------------------------------------
// The sdk-client-v2 also has support for the old syntax
import {
createClient,
createHttpClient,
createAuthForClientCredentialsFlow,
} from '@commercetools/sdk-client-v2'
import { createApiBuilderFromCtpClient } from '@commercetools/importapi-sdk')
import fetch from 'node-fetch'

const projectKey = 'some_project_key'

const authMiddleware = createAuthForClientCredentialsFlow({
host: 'https://auth.europe-west1.gcp.commercetools.com',
projectKey,
credentials: {
clientId: 'some_id',
clientSecret: 'some_secret',
},
fetch,
})

const httpMiddleware = createHttpClient({
host: 'https://import.europe-west1.gcp.commercetools.com',
fetch,
})

const ctpClient = createClient({
middlewares: [authMiddleware, httpMiddleware],
})

const apiRoot = createApiBuilderFromCtpClient(ctpClient)

apiRoot
.withProjectKey({
projectKey,
})
.get()
.execute()
.then((x) => {
/*...*/
})

Index

Classes

ApiRoot ByProjectKeyCategoriesImportContainersByImportContainerKeyRequestBuilder ByProjectKeyCategoriesImportContainersRequestBuilder ByProjectKeyCategoriesRequestBuilder ByProjectKeyCustomersImportContainersByImportContainerKeyRequestBuilder ByProjectKeyCustomersImportContainersRequestBuilder ByProjectKeyCustomersRequestBuilder ByProjectKeyDiscountCodesImportContainersByImportContainerKeyRequestBuilder ByProjectKeyDiscountCodesImportContainersRequestBuilder ByProjectKeyDiscountCodesRequestBuilder ByProjectKeyImportContainersByImportContainerKeyImportOperationsRequestBuilder ByProjectKeyImportContainersByImportContainerKeyImportSummariesRequestBuilder ByProjectKeyImportContainersByImportContainerKeyRequestBuilder ByProjectKeyImportContainersRequestBuilder ByProjectKeyImportOperationsByIdRequestBuilder ByProjectKeyImportOperationsRequestBuilder ByProjectKeyInventoriesImportContainersByImportContainerKeyRequestBuilder ByProjectKeyInventoriesImportContainersRequestBuilder ByProjectKeyInventoriesRequestBuilder ByProjectKeyOrderPatchesImportContainersByImportContainerKeyRequestBuilder ByProjectKeyOrderPatchesImportContainersRequestBuilder ByProjectKeyOrderPatchesRequestBuilder ByProjectKeyOrdersImportContainersByImportContainerKeyRequestBuilder ByProjectKeyOrdersImportContainersRequestBuilder ByProjectKeyOrdersRequestBuilder ByProjectKeyPricesImportContainersByImportContainerKeyRequestBuilder ByProjectKeyPricesImportContainersRequestBuilder ByProjectKeyPricesRequestBuilder ByProjectKeyProductDraftsImportContainersByImportContainerKeyRequestBuilder ByProjectKeyProductDraftsImportContainersRequestBuilder ByProjectKeyProductDraftsRequestBuilder ByProjectKeyProductTypesImportContainersByImportContainerKeyRequestBuilder ByProjectKeyProductTypesImportContainersRequestBuilder ByProjectKeyProductTypesRequestBuilder ByProjectKeyProductVariantPatchesImportContainersByImportContainerKeyRequestBuilder ByProjectKeyProductVariantPatchesImportContainersRequestBuilder ByProjectKeyProductVariantPatchesRequestBuilder ByProjectKeyProductVariantsImportContainersByImportContainerKeyRequestBuilder ByProjectKeyProductVariantsImportContainersRequestBuilder ByProjectKeyProductVariantsRequestBuilder ByProjectKeyProductsImportContainersByImportContainerKeyRequestBuilder ByProjectKeyProductsImportContainersRequestBuilder ByProjectKeyProductsRequestBuilder ByProjectKeyRequestBuilder ByProjectKeyStandalonePricesImportContainersByImportContainerKeyRequestBuilder ByProjectKeyStandalonePricesImportContainersRequestBuilder ByProjectKeyStandalonePricesRequestBuilder ByProjectKeyTypesImportContainersByImportContainerKeyRequestBuilder ByProjectKeyTypesImportContainersRequestBuilder ByProjectKeyTypesRequestBuilder

Interfaces

AccessDeniedError Address Asset AssetDimensions AssetSource AttributeBooleanType AttributeDateTimeType AttributeDateType AttributeDefinition AttributeEnumType AttributeLocalizableTextType AttributeLocalizedEnumType AttributeLocalizedEnumValue AttributeMoneyType AttributeNestedType AttributeNumberType AttributePlainEnumValue AttributeReferenceType AttributeSetType AttributeTextType AttributeTimeType Attributes BooleanAttribute BooleanField BooleanSetAttribute BooleanSetField CartClassificationTier CartDiscountKeyReference CartKeyReference CategoryImport CategoryImportRequest CategoryKeyReference ChannelKeyReference ClassificationShippingRateInput ClientRequest ConcurrentModificationError ContentionError Custom CustomFieldBooleanType CustomFieldDateTimeType CustomFieldDateType CustomFieldEnumType CustomFieldEnumValue CustomFieldLocalizedEnumType CustomFieldLocalizedEnumValue CustomFieldLocalizedStringType CustomFieldMoneyType CustomFieldNumberType CustomFieldReferenceType CustomFieldSetType CustomFieldStringType CustomFieldTimeType CustomLineItemDraft CustomLineItemTaxedPrice CustomObjectKeyReference CustomTokenizer CustomerAddress CustomerGroupKeyReference CustomerImport CustomerImportRequest CustomerKeyReference DateAttribute DateField DateSetAttribute DateSetField DateTimeAttribute DateTimeField DateTimeSetAttribute DateTimeSetField Delivery DeliveryAddressDraft DeliveryDraft DeliveryItem DeliveryParcel DeliveryParcelDraft DiscountCodeImport DiscountCodeImportRequest DiscountCodeInfo DiscountCodeKeyReference DiscountedLineItemPortion DiscountedLineItemPriceDraft DiscountedPrice DuplicateAttributeValueError DuplicateAttributeValuesError DuplicateFieldError DuplicateVariantValuesError EnumAttribute EnumField EnumSetAttribute EnumSetField EnumValue ErrorResponse ExternalTaxRateDraft FieldContainer FieldDefinition GenericError HighPrecisionMoney Image ImportContainer ImportContainerDraft ImportContainerPagedResponse ImportContainerUpdateDraft ImportOperation ImportOperationPagedResponse ImportOperationStatus ImportResource ImportResponse ImportSummary InsufficientScopeError InvalidCredentialsError InvalidFieldError InvalidInput InvalidJsonInput InvalidOperation InvalidScopeError InvalidStateTransitionError InvalidTokenError InventoryImport InventoryImportRequest ItemShippingDetailsDraft ItemShippingTarget ItemState LineItemImportDraft LineItemPrice LineItemProductVariantImportDraft LocalizableEnumAttribute LocalizableEnumSetAttribute LocalizableTextAttribute LocalizableTextSetAttribute LocalizedEnumField LocalizedEnumSetField LocalizedEnumValue LocalizedString LocalizedStringField LocalizedStringSetField Money MoneyAttribute MoneyField MoneySetAttribute MoneySetField NumberAttribute NumberField NumberSetAttribute NumberSetField OperationStates OrderField OrderImport OrderImportRequest OrderKeyReference OrderPatchImport OrderPatchImportRequest Parcel ParcelItems ParcelMeasurementDraft ParcelMeasurements ParcelTrackingData PaymentKeyReference PriceDraftImport PriceImport PriceImportRequest PriceKeyReference PriceTier ProductDiscountKeyReference ProductDraftImport ProductDraftImportRequest ProductImport ProductImportRequest ProductKeyReference ProductTypeImport ProductTypeImportRequest ProductTypeKeyReference ProductVariantDraftImport ProductVariantImport ProductVariantImportRequest ProductVariantKeyReference ProductVariantPatch ProductVariantPatchRequest ReferenceAttribute ReferenceField ReferenceSetAttribute ReferenceSetField RemoveDeliveryDraft RemoveParcelFromDeliveryDraft RequiredFieldError ResourceCreationError ResourceDeletionError ResourceNotFoundError ResourceUpdateError ReturnInfo ReturnItemDraft ScoreShippingRateInput SearchKeyword SearchKeywords ShippingInfoImportDraft ShippingMethodKeyReference ShippingRateDraft StandalonePriceImport StandalonePriceImportRequest StateKeyReference StoreKeyReference StringField StringSetField SubRate SyncInfo TaxCategoryKeyReference TaxPortion TaxRate TaxedPrice TextAttribute TextSetAttribute TimeAttribute TimeField TimeSetAttribute TimeSetField TrackingData TypeImport TypeImportRequest TypeKeyReference UnresolvedReferences VariantValues WhitespaceTokenizer

Type Aliases

Functions