sync-actions

Provides an API to construct update actions. Useful for building request body for updates.

Install

Node.js

npm install --save @commercetools/sync-actions

Browser

<script src="https://unpkg.com/@commercetools/sync-actions/dist/commercetools-sync-actions.min.js"></script>
<script>// global: CommercetoolsSyncActions</script>

createSyncCategories(actionGroups)

Creates a sync action that allows to build API update actions for categories.

Arguments

  1. actionGroups (Array): A list of action group in case some actions need to be blacklisted or whitelisted.

Usage example

import { createSyncCategories } from '@commercetools/sync-actions'
import { createClient } from '@commercetools/sdk-client'

const syncCategories = createSyncCategories()
const client = createClient({
  middlewares: [...],
})
const before = {
  name: { en: 'My Category' }
}
const now = {
  name: { en: 'My Category', de: 'Meine Kategorie' }
}
const actions = syncCategories.buildActions(before, now)
const categoriesRequest = {
  url: `/categories/${before.id}`,
  method: 'POST',
  body: JSON.stringify({ version: before.version, actions }),
}

client.execute(categoriesRequest)
.then(result => ...)
.catch(error => ...)

createSyncCustomers(actionGroups)

From package @commercetools/sync-actions.

Creates a sync action that allows to build API update actions for customers.

Arguments

  1. actionGroups (Array): A list of action group in case some actions need to be blacklisted or whitelisted.

Usage example

import { createSyncCustomers } from '@commercetools/sync-actions'
import { createClient } from '@commercetools/sdk-client'

const syncCustomers = createSyncCustomers()
const client = createClient({
  middlewares: [...],
})
const before = {
  firstName: 'John'
}
const now = {
  firstName: 'John',
  lastName: 'Doe'
}
const actions = syncCustomers.buildActions(before, now)
const customersRequest = {
  url: `/customers/${before.id}`,
  method: 'POST',
  body: JSON.stringify({ version: before.version, actions }),
}

client.execute(customersRequest)
.then(result => ...)
.catch(error => ...)

createSyncInventories(actionGroups)

From package @commercetools/sync-actions.

Creates a sync action that allows to build API update actions for inventories.

Arguments

  1. actionGroups (Array): A list of action group in case some actions need to be blacklisted or whitelisted.

Usage example

import { createSyncInventories } from '@commercetools/sync-actions'
import { createClient } from '@commercetools/sdk-client'

const syncInventories = createSyncInventories()
const client = createClient({
  middlewares: [...],
})
const before = {
  quantityOnStock: 10
}
const now = {
  quantityOnStock: 5
}
const actions = syncInventories.buildActions(before, now)
const inventoriesRequest = {
  url: `/inventory/${before.id}`,
  method: 'POST',
  body: JSON.stringify({ version: before.version, actions }),
}

client.execute(inventoriesRequest)
.then(result => ...)
.catch(error => ...)

createSyncOrders(actionGroups)

From package @commercetools/sync-actions.

Creates a sync action that allows to build API update actions for orders.

Arguments

  1. actionGroups (Array): A list of action group in case some actions need to be blacklisted or whitelisted.

Usage example

import { createSyncOrders } from '@commercetools/sync-actions'
import { createClient } from '@commercetools/sdk-client'

const syncOrders = createSyncOrders()
const client = createClient({
  middlewares: [...],
})
const before = {
  orderState: 'Open'
}
const now = {
  orderState: 'Complete'
}
const actions = syncOrders.buildActions(before, now)
const ordersRequest = {
  url: `/orders/${before.id}`,
  method: 'POST',
  body: JSON.stringify({ version: before.version, actions }),
}

client.execute(ordersRequest)
.then(result => ...)
.catch(error => ...)

createSyncProducts(actionGroups)

From package @commercetools/sync-actions.

Creates a sync action that allows to build API update actions for products.

Arguments

  1. actionGroups (Array): A list of action group in case some actions need to be blacklisted or whitelisted.

Usage example

import { createSyncProducts } from '@commercetools/sync-actions'
import { createClient } from '@commercetools/sdk-client'

const syncProducts = createSyncProducts()
const client = createClient({
  middlewares: [...],
})
const before = {
  name: { en: 'My Product' }
}
const now = {
  name: { en: 'My Product', de: 'Mein Produkt' }
}
const actions = syncProducts.buildActions(before, now)
const productsRequest = {
  url: `/products/${before.id}`,
  method: 'POST',
  body: JSON.stringify({ version: before.version, actions }),
}

client.execute(productsRequest)
.then(result => ...)
.catch(error => ...)

createSyncProductDiscounts(actionGroups)

From package @commercetools/sync-actions.

Creates a sync action that allows to build API update actions for product-discounts.

Arguments

  1. actionGroups (Array): A list of action group in case some actions need to be blacklisted or whitelisted.

Usage example

import { createSyncProductDiscounts } from '@commercetools/sync-actions'
import { createClient } from '@commercetools/sdk-client'

const syncProductDiscounts = createSyncProductDiscounts()
const client = createClient({
  middlewares: [...],
})
const before = {
  name: { en: 'My Product Discount' }
}
const now = {
  name: { en: 'My Product Discount', de: 'Mein Produkt Rabatt' }
}
const actions = syncProductDiscounts.buildActions(before, now)
const productDiscountsRequests = {
  url: `/product-discounts/${before.id}`,
  method: 'POST',
  body: JSON.stringify({ version: before.version, actions }),
}

client.execute(productDiscountsRequests)
.then(result => ...)
.catch(error => ...)

createSyncDiscountCodes(actionGroups)

From package @commercetools/sync-actions.

Creates a sync action that allows to build API update actions for discount-codes.

Arguments

  1. actionGroups (Array): A list of action group in case some actions need to be blacklisted or whitelisted.

Usage example

import { createSyncDiscountCodes } from '@commercetools/sync-actions'
import { createClient } from '@commercetools/sdk-client'

const syncDiscountCodes = createSyncDiscountCodes()
const client = createClient({
  middlewares: [...],
})
const before = {
  name: { en: 'My Discount Code' }
}
const now = {
  name: { en: 'My Discount Code', de: 'Mein Rabatt Code' }
}
const actions = syncDiscountCodes.buildActions(before, now)
const discountCodesRequest = {
  url: `/discount-codes/${before.id}`,
  method: 'POST',
  body: JSON.stringify({ version: before.version, actions }),
}

client.execute(discountCodesRequest)
.then(result => ...)
.catch(error => ...)

createSyncCustomerGroup(actionGroups)

From package @commercetools/sync-actions.

Creates a sync action that allows to build API update actions for customer-groups.

Arguments

  1. actionGroups (Array): A list of action group in case some actions need to be blacklisted or whitelisted.

Usage example

import { createSyncCustomerGroup } from '@commercetools/sync-actions'
import { createClient } from '@commercetools/sdk-client'

const syncCustomerGroups = createSyncCustomerGroup()
const client = createClient({
  middlewares: [...],
})
const before = {
  name: 'My customer group',
  key: 'some-old-key'
}
const now = {
  name: 'My new customer group',
  key: 'some-new-key'
}
const actions = syncCustomerGroups.buildActions(before, now)
const customerGroupRequest = {
  url: `/customer-groups/${before.id}`,
  method: 'POST',
  body: JSON.stringify({ version: before.version, actions }),
}

client.execute(customerGroupRequest)
.then(result => ...)
.catch(error => ...)

createSyncCartDiscounts(actionGroups)

From package @commercetools/sync-actions.

Creates a sync action that allows to build API update actions for cart-discounts.

Arguments

  1. actionGroups (Array): A list of action group in case some actions need to be blacklisted or whitelisted.

Usage example

import { createSyncCartDiscounts } from '@commercetools/sync-actions'
import { createClient } from '@commercetools/sdk-client'

const syncCartDiscounts = createSyncCartDiscounts()
const client = createClient({
  middlewares: [...],
})
const before = {
  name: { en: 'My Cart Discount' }
}
const now = {
  name: { en: 'My Cart Discount', de: 'Mein Warenkorbrabatt' }
}
const actions = syncCartDiscounts.buildActions(before, now)
const cartDiscountsRequests = {
  url: `/cart-discounts/${before.id}`,
  method: 'POST',
  body: JSON.stringify({ version: before.version, actions }),
}

client.execute(cartDiscountsRequests)
.then(result => ...)
.catch(error => ...)

results matching ""

    No results matching ""