Skip to main content
Skip table of contents

Retrieve Job Templates Data

The batch_templates GraphQL query provides a way to pull job template data, programmatically, in a single API call. The query allows you to pull specific data on the job templates you have access to.

In the following sections, we will describe how you can authenticate with the API. We will also provide an example query, 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

Scope can be left blank for this token request as only access to the production centre that the job templates are assigned to, is required.

 

Example Response

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

OAuth User Requirements

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

  • Access to the production centre company or companies that the job templates are assigned to.

The Batch Templates GraphQL Query

Now we have the access token, we can now make the batch_templates 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.

Query

In this example, we will be listing details of the job templates for a specific production centre. We will ask the API to return the following job template information.

  • Name

  • ID

  • Ref

  • SKUs

  • Machine Types

  • Position Count

  • Cut Off Time

  • Artwork Processing Flag

  • Positions

As well as the following information on the positions (filtered to just image positions), if artwork processing is enabled.

  • Name

  • Type

  • X Coordinate

  • Y Coordinate

However, the GraphQL API call can return numerous other pieces of information about the job templates you have access to, details of which, can be found in the schema here - https://developers-v2.custom-gateway.net/graphql/batchtemplate.doc.html

Example Query

GRAPHQL
query ($page: Int!, $count: Int!, $filter: Json!, $positionsFilter: Json!, $positionsPage: Int!, $positionsCount: Int!) {
  core {
    batch_templates(filter: $filter, page: $page, count: $count) {
      pages {
        pageCount
        current
      }
      items{
          name
          id
          ref
          sku
          machine_type_set
          position_count
          cut_off_time_expression
          is_artwork_processing_enabled
          positions(filter: $positionsFilter, page: $positionsPage, count: $positionsCount){
              items{
                  name
                  type
                  x
                  y
              }
          }
      }
    }
  }
}

Variables

The query contains references to 6 variables - $filter, $order, $page and $count. Descriptions of these variables can be found in the table below.

Variable Descriptions

Variable

Type

Description

filter

Json

Allows you to filter the job templates to just the ones you require. For example, by production centre ID.

page

Int

The page number of the list of job templates to be returned. i.e. if the are 100 job templates in total and count is set to 10, setting this value to 2 will return information on job templates 11 through 20 (page 2 of the 100 job templates).

count

Int

How may job templates should be returned in the response.

positionsFilter

Json

Allows you to filter the job template positions to just the ones you require. For example, to just the image positions by filtering the Type field.

positionsPage

Int

The page number of the list of job template positions to be returned. i.e. if the are 20 job template positions in total and positionsCountis set to 10, setting this value to 2 will return information on job templates 11 through 20 (page 2 of the 20 job template positions).

positionsCount

Int

How may job template positions should be returned in the response.

Example Variables

JSON
{
    "filter": {
        "fulfiller_company_ref_id": 300057
    },
    "page": 1,
    "count": 100,
    "positionsFilter": {
        "type": 0
    },
    "positionsPage": 1,
    "positionsCount": 10
}

Response

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

Example response

JSON
{
    "data": {
        "core": {
            "batch_templates": {
                "pages": {
                    "pageCount": 1,
                    "current": 1
                },
                "items": [
                    {
                        "name": "Paul S Batch Test Consolidation Template",
                        "id": 64432,
                        "ref": "mgrd7b09br",
                        "sku": "64861775,Bella&Canvas3001-Black-L,-GD01IGNXL,-GD01BLKS,JH001*,JH001 HEA XL,JH001 GOL M,3001-BC-TEAM-PURPLE-MD,BL00XBKFRT529805QOS,BL00XBKFRT529805QOXL,MensTee-GRY-L,5000L-PSTEST,5000L-WHITE-S,mta-black-s,MMS00039WO1S284-PSTEST,HEINZ-3-SAUCE-PACK,MMS00043WO1S26-PSTEST01,MensTee*,the-sauces-bundle-PSTEST,GIANTCARD-PSTEST,97200-PSTEST\n\n,11006210010005",
                        "machine_type_set": "",
                        "position_count": 1,
                        "cut_off_time_expression": "",
                        "is_artwork_processing_enabled": false,
                        "positions": {
                            "items": []
                        }
                    },
                    {
                        "name": "Paul S Batch Test Artwork Processing Template",
                        "id": 64437,
                        "ref": "wrtvjn3mz3",
                        "sku": "SGS7E-CS-G,SGS7-TCB-CS-G,SGS7E-CS-G-TEST,SGS20-TCB-CS-G-PSTEST",
                        "machine_type_set": "",
                        "position_count": 2,
                        "cut_off_time_expression": "0 7,12 * * *",
                        "is_artwork_processing_enabled": true,
                        "positions": {
                            "items": [
                                {
                                    "name": "Position 1",
                                    "type": 0,
                                    "x": 942,
                                    "y": 1240
                                },
                                {
                                    "name": "Position 2",
                                    "type": 0,
                                    "x": 2566,
                                    "y": 1240
                                }
                            ]
                        }
                    },
                    {
                        "name": "Paul S Batch Test Artwork Processing Template 2",
                        "id": 72495,
                        "ref": "q8t90b4ptm",
                        "sku": "SGS7E-CS-G,SGS7-TCB-CS-G,SGS20-TCB-CS-G-PSTEST",
                        "machine_type_set": "",
                        "position_count": 2,
                        "cut_off_time_expression": "0 7,12 * * *",
                        "is_artwork_processing_enabled": true,
                        "positions": {
                            "items": [
                                {
                                    "name": "Position 1",
                                    "type": 0,
                                    "x": 942,
                                    "y": 1240
                                },
                                {
                                    "name": "Position 2",
                                    "type": 0,
                                    "x": 2566,
                                    "y": 1240
                                }
                            ]
                        }
                    },
                    {
                        "name": "Jigsaw 30PC",
                        "id": 127865,
                        "ref": "sby42nb5fg",
                        "sku": "JIGSAW30PCSMEDTIN",
                        "machine_type_set": "kornit-dtg",
                        "position_count": 1,
                        "cut_off_time_expression": "",
                        "is_artwork_processing_enabled": true,
                        "positions": {
                            "items": [
                                {
                                    "name": "Position 1",
                                    "type": 0,
                                    "x": 1648,
                                    "y": 1348
                                }
                            ]
                        }
                    },
                    {
                        "name": "Paul S Creation Test2",
                        "id": 155305,
                        "ref": "w4btpqq0r5",
                        "sku": "",
                        "machine_type_set": "",
                        "position_count": 0,
                        "cut_off_time_expression": "0 7,12 * * *",
                        "is_artwork_processing_enabled": true,
                        "positions": {
                            "items": []
                        }
                    },
                    {
                        "name": "Sacks ",
                        "id": 159584,
                        "ref": "k2v6yr7xzx",
                        "sku": "SGS7-TCB-CS-G-SS",
                        "machine_type_set": "",
                        "position_count": 8,
                        "cut_off_time_expression": "0 7,12 * * *",
                        "is_artwork_processing_enabled": true,
                        "positions": {
                            "items": [
                                {
                                    "name": "1",
                                    "type": 0,
                                    "x": 1570,
                                    "y": 2728
                                },
                                {
                                    "name": "2",
                                    "type": 0,
                                    "x": 4712,
                                    "y": 2730
                                },
                                {
                                    "name": "3",
                                    "type": 0,
                                    "x": 7853,
                                    "y": 2730
                                },
                                {
                                    "name": "4",
                                    "type": 0,
                                    "x": 10994,
                                    "y": 2730
                                },
                                {
                                    "name": "5",
                                    "type": 0,
                                    "x": 1570,
                                    "y": 8187
                                },
                                {
                                    "name": "6",
                                    "type": 0,
                                    "x": 4712,
                                    "y": 8187
                                },
                                {
                                    "name": "7",
                                    "type": 0,
                                    "x": 7853,
                                    "y": 8187
                                },
                                {
                                    "name": "8",
                                    "type": 0,
                                    "x": 10994,
                                    "y": 8187
                                }
                            ]
                        }
                    },
                    {
                        "name": "V3 Testing White Mugs",
                        "id": 172394,
                        "ref": "q0m3443fnm",
                        "sku": "SUB-11ozWhiteMug",
                        "machine_type_set": "epson-sublimatio",
                        "position_count": 10,
                        "cut_off_time_expression": "",
                        "is_artwork_processing_enabled": true,
                        "positions": {
                            "items": [
                                {
                                    "name": "Mug 1",
                                    "type": 0,
                                    "x": 729,
                                    "y": 1696
                                },
                                {
                                    "name": "Mug 2",
                                    "type": 0,
                                    "x": 1984,
                                    "y": 1696
                                },
                                {
                                    "name": "Mug 3",
                                    "type": 0,
                                    "x": 3248,
                                    "y": 1696
                                },
                                {
                                    "name": "Mug 4",
                                    "type": 0,
                                    "x": 4513,
                                    "y": 1696
                                },
                                {
                                    "name": "Mug 5",
                                    "type": 0,
                                    "x": 5785,
                                    "y": 1696
                                },
                                {
                                    "name": "Mug 6",
                                    "type": 0,
                                    "x": 7193,
                                    "y": 1696
                                },
                                {
                                    "name": "Mug 7",
                                    "type": 0,
                                    "x": 8456,
                                    "y": 1696
                                },
                                {
                                    "name": "Mug 8",
                                    "type": 0,
                                    "x": 9728,
                                    "y": 1696
                                },
                                {
                                    "name": "Mug 9",
                                    "type": 0,
                                    "x": 10985,
                                    "y": 1696
                                },
                                {
                                    "name": "Mug 10",
                                    "type": 0,
                                    "x": 12240,
                                    "y": 1696
                                }
                            ]
                        }
                    },
                    {
                        "name": "Paul S Batch Test Vector Artwork Processing Template",
                        "id": 177804,
                        "ref": "bf1k4xrc0m",
                        "sku": "IP12-TCB-CS-G-TEST",
                        "machine_type_set": "",
                        "position_count": 2,
                        "cut_off_time_expression": "0 7,12 * * *",
                        "is_artwork_processing_enabled": true,
                        "positions": {
                            "items": [
                                {
                                    "name": "Position 1",
                                    "type": 0,
                                    "x": 942,
                                    "y": 1240
                                },
                                {
                                    "name": "Position 2",
                                    "type": 0,
                                    "x": 2566,
                                    "y": 1240
                                }
                            ]
                        }
                    }
                ]
            }
        }
    }
}

 

JavaScript errors detected

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

If this problem persists, please contact our support.