Skip to main content
Skip table of contents

Creating Attribute Sets

Product attribute sets provide a way to specify a collection of attributes that will be used repeatedly across multiple products. You can then assign this set of attributes to a product, which saves you from assigning the same attribute names and values to each product, again and again.

It’s possible to create new attribute sets using the updateProductAttributeSets GraphQL mutation. In this article, we’ll explain how to do just that. 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.

Authentication

The GraphQL API uses OAuth 2.0 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

graphql.core.update-product-attribute-sets

 

Example Response

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

OAuth User Requirements

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

  • The graphql.core.update-product-attribute-sets user permission enabled.

The Orders GraphQL Mutation

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

We will be making a POST request to the https://graphql.kornitx.net 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 providing the ID, name and company ref ID for the new attribute set. We will ask the API to return the following information from the new attribute set.

  • Attribute Set ID

  • Name

  • Company Ref ID

However, the GraphQL API call can return other data related to the attribute set, details of which, can be found in the schema here - https://developers-v2.custom-gateway.net/graphql/productattributeset.doc.html

Example Mutation

GRAPHQL
mutation($productAttributeSets: [ProductAttributeSetInput]!) {
    core {
        updateProductAttributeSets(productAttributeSets: $productAttributeSets) {
            id
            name
            company_ref_id
        }
    }
}

Variables

The mutation contains references to a single variable - $productAttributeSets. A description of this variable can be found in the table below.

Variable Description

Variable

Type

Description

productAttributeSets

[ProductAttributeSetInput]!

An array of ProductAttributeSet objects that contain the required information for the new attribute set.

Each ProductAttributeSetInput object contains a number of fields which we can use to initialise the product attribute set, each of which are explained below.

Field Name

Type

Description

id

Int

The value of this field must always be 0 when creating a new product attribute set.

name

String

The name of the new product attribute set.

company_ref_id

Int

The company ref ID of the organisation/admin company that the new product attribute set will belong to.

Example Variable

JSON
{
  "productAttributeSets": [
    {
      "id": 0,
      "name": "Standard Pallet Light HQ",
      "company_ref_id": 582319
    }
  ]
}

Response

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

Example response

JSON
{
    "data": {
        "core": {
            "updateProductAttributeSets": [
                {
                    "id": 3270,
                    "name": "Standard Pallet Light HQ",
                    "company_ref_id": 582319
                }
            ]
        }
    }
}

 

JavaScript errors detected

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

If this problem persists, please contact our support.