Skip to main content
Skip table of contents

Update Job Templates

The updateBatchTemplates GraphQL mutation provides a way to update job template settings, programmatically, in a single API call. The mutation allows you to target specific attributes of one or more job templates you have access to, and update them.

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

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 updateBatchTemplates 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 graphql.core.update-batch-templates user permission enabled.

The Batch Templates GraphQL Mutation

Now we have the access token, we can now make the updateBatchTemplates 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 updating the cut off time on 2 job templates. The cut off time is expressed as cron time. To gain a better understanding of how you can use cron time expressions to schedule job generation, visit Crontab Guru.

We will also be asking the API to return the following job template information.

  • Name

  • ID

  • Cut Off Time

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 Mutation

GRAPHQL
mutation ($batchTemplates: [BatchTemplateInput]!) {
    core {
        updateBatchTemplates(batchTemplates: $batchTemplates) {
            id
            name
            cut_off_time_expression
        }
    }
}

Variables

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

Variable Descriptions

Variable

Type

Description

batchTemplates

[BatchTemplateInput]!

An array of BatchTemplateInput objects. Each object allows you to specify the ID of the job template, the fields to be updated and the values you wish to update them to.

Example Variables

JSON
{
    "batchTemplates": [
        {
            "id": 64432,
            "cut_off_time_expression": "0 7,12 * * *"
        },
        {
            "id": 64437,
            "cut_off_time_expression": "0 7,12 * * *"
        }
    ]
}

Response

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

Example response

JSON
{
    "data": {
        "core": {
            "updateBatchTemplates": [
                {
                    "id": 64432,
                    "name": "Paul S Batch Test Consolidation Template",
                    "cut_off_time_expression": "0 7,12 * * *"
                },
                {
                    "id": 64437,
                    "name": "Paul S Batch Test Artwork Processing Template",
                    "cut_off_time_expression": "0 7,12 * * *"
                }
            ]
        }
    }
}

 

JavaScript errors detected

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

If this problem persists, please contact our support.