How to use @commercetools/api-request-builder - 8 common examples

To help you get started, we’ve selected a few @commercetools/api-request-builder examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github commercetools / nodejs / integration-tests / cli / helpers / utils.js View on Github external
export function clearData(apiConfig, entityName, predicate = null) {
  const client = createClient({
    middlewares: [
      createAuthMiddlewareForClientCredentialsFlow({ ...apiConfig, fetch }),
      createHttpMiddleware({ host: apiConfig.apiUrl, fetch }),
    ],
  })

  let service = createRequestBuilder({
    projectKey: apiConfig.projectKey,
  })[entityName]

  if (predicate) service = service.where(predicate)

  const request = {
    uri: service.build(),
    method: 'GET',
  }

  return client.process(request, payload => {
    // Built-in states cannot be deleted
    const results =
      entityName === 'states'
        ? payload.body.results.filter(state => state.builtIn === false)
        : payload.body.results
github commercetools / nodejs / integration-tests / cli / helpers / utils.js View on Github external
export function getId(apiConfig, entityName) {
  const client = createClient({
    middlewares: [
      createAuthMiddlewareForClientCredentialsFlow({ ...apiConfig, fetch }),
      createHttpMiddleware({ host: apiConfig.apiUrl, fetch }),
    ],
  })

  const service = createRequestBuilder({
    projectKey: apiConfig.projectKey,
  })[entityName]

  const request = {
    uri: service.build(),
    method: 'GET',
  }

  return client
    .execute(request)
    .then(result => Promise.resolve(result.body.results[0].id))
}
github commercetools / nodejs / integration-tests / cli / helpers / utils.js View on Github external
export function createData(apiConfig, entityName, data, id) {
  const client = createClient({
    middlewares: [
      createAuthMiddlewareForClientCredentialsFlow({ ...apiConfig, fetch }),
      createHttpMiddleware({ host: apiConfig.apiUrl, fetch }),
    ],
  })
  const requestOption = { projectKey: apiConfig.projectKey }
  const service = createRequestBuilder(requestOption)[entityName]
  return Promise.all(
    data.map(_data => {
      if (id) service.byId(id)
      const request = {
        uri: service.build(),
        method: 'POST',
        body: _data,
      }
      return client.execute(request)
    })
  )
}
github commercetools / nodejs / packages / csv-parser-state / src / main.js View on Github external
static _createStateService(projectKey: string): ServiceBuilderInstance {
    return createRequestBuilder({ projectKey }).states
  }
github commercetools / nodejs / packages / resource-deleter / src / main.js View on Github external
createService() {
    return createRequestBuilder({
      projectKey: this.apiConfig.projectKey,
    })[this.resource]
  }
github commercetools / nodejs / packages / csv-parser-price / src / main.js View on Github external
function _getCustomTypeDefinition(customTypeKey) {
    const getTypeByKeyUri = createRequestBuilder({
      projectKey: this.apiConfig.projectKey,
    })
      .types.where(`key="${customTypeKey}"`)
      .build()
    const execObj = {
      uri: getTypeByKeyUri,
      method: 'GET',
    }
    if (this.accessToken)
      execObj.headers = {
        Authorization: `Bearer ${this.accessToken}`,
      }

    return this.client.execute(execObj).then(response => {
      if (response.body.count === 0)
        return Promise.reject(
github commercetools / nodejs / packages / discount-code-importer / src / main.js View on Github external
_createService(): ServiceBuilderInstance {
    return createRequestBuilder({
      projectKey: this.apiConfig.projectKey,
    }).discountCodes
  }
github commercetools / nodejs / packages / state-importer / src / main.js View on Github external
_createService(): ServiceBuilderInstance {
    return createRequestBuilder({
      projectKey: this.apiConfig.projectKey,
    }).states
  }

@commercetools/api-request-builder

Helper functions to construct API requests URI for the commercetools platform in a declarative way.

MIT
Latest version published 2 years ago

Package Health Score

66 / 100
Full package analysis

Popular @commercetools/api-request-builder functions