Skip to main content
Skip table of contents

Update Product eCommerce Data

The updateProductEcommerce GraphQL mutation provides a way to update product eCommerce data, programmatically, in a single API call. The mutation allows you to update specific data in the eCommerce section of the products that your OAuth user has access to.

In the following sections, we will describe how you can authenticate with the API. We will also provide an example mutation, the associated variables and a typical response from the API.

In this example we will be using the API to update the Sales Description (Short), Weight and Lead Time (Days) eCommerce fields on a product.

Authentication

The GraphQL API uses OAuth authentication.  A request for an OAuth token is made to the OAuth endpoint, which returns an access token.  This token can then be used in requests made to the GraphQL API endpoint.

To make a request for a token, you will require an OAuth user to be set up in the KornitX platform. The user will require specific access and permissions depending on the API request. The permissions required for this request can be found in the “OAuth User Requirements” section below.

If you don’t have an OAuth user set up, please contact the support team, who will be happy to help. The support team will set up the OAuth user in the KornitX platform for you and supply you with the OAuth user client ID and client secret.  These credentials can then be used to obtain a token from the OAuth token endpoint. 

OAuth Token Endpoint - https://oauth.kornitx.net/token

The OAuth token can be obtained by making a POST to the above endpoint.  The request type for the OAuth token is x-www-form-urlencoded and must include the following form keys and values.

Key

Value

client_id

The client ID of the OAuth user provided by the support team.

client_secret

The client secret of the OAuth user provided by the support team.

grant_type

client_credentials

scope

product.customisable.edit

Example Response

JSON
{"token_type":"Bearer","expires_in":3600,"access_token":"..."}

OAuth User Requirements

To make the updateProductEcommerce request to the GraphQL API, the OAuth user must have:

  • Access to the category that the product is in.

  • The product.customisable.edit user permission enabled.

The Update Products Ecommerce GraphQL Mutation

Now we have the access token, we can now make the updateProductEcommerce request.

We will be making a POST request to the https://platform.kornitx.net/v2/product-manager/graphql endpoint.

The request will have 2 headers listed below.

Content-Type: “application/json” 

Authorization: “Bearer [OAUTH_ACCESS_TOKEN]“

[OAUTH_ACCESS_TOKEN] should be replaced by the access token that was returned when we made the token request to the https://oauth.kornitx.net/token endpoint.

Mutation

In this example, we will be updating Sales Description (Short), Weight and Lead Time (Days) eCommerce fields on a product. We will ask the API to return the following product information.

  • Product ID

  • Sales Description (Short)

  • Weight

  • Lead Time (Days)

However, the GraphQL API call can return numerous other pieces of information from the products' eCommerce data, details of which, can be found in the schema here - ProductEcommerce

Example Mutation

GRAPHQL
mutation ($productId: ID!, $ecommerce: ProductEcommerceInput!) {
  updateProductEcommerce(productId: $productId, ecommerce: $ecommerce) {
      product_id
      sales_description
      weight
      lead_time_days
  }
}

Variables

The mutation contains references to 2 variables - $productId and $ecommerce. A description of these variables can be found in the table below.

Variable Description

Variable

Type

Description

productId

ID!

A product ID from the Catalog module of the KornitX platform.

ecommerce

ProductEcommerceInput!

An object containing the eCommerce fields that you wish to update on the product.

Example Variable

JSON
{
  "productId": 11925669,
  "ecommerce": {
    "product_id": 11925669,
    "sales_description": "A classic unisex t-shirt that feels soft and light with just the right amount of stretch.  It's comfortable and flattering for all.  It's a t-shirt we're sure you'll love!",
    "weight": 400,
    "lead_time_days": 2
  }
}

Response

A successful request will return a HTTP 200 response and the details we requested from the products' eCommerce data. For the example we have been working with, the response data can be viewed below.

Example response

JSON
{
    "data": {
        "updateProductEcommerce": {
            "product_id": 11925669,
            "sales_description": "A classic unisex t-shirt that feels soft and light with just the right amount of stretch.  It's comfortable and flattering for all.  It's a t-shirt we're sure you'll love!",
            "weight": 400,
            "lead_time_days": 2
        }
    }
}

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.