API Example - Creating Transactions

Explanation link

This example walks through how to create a 2ic Transaction using the 2ic Pallets API.

To create a Transaction with the 2ic Pallets API, the CreateTransaction endpoint must be passed a valid CreateTransactionInput JSON object, a simple example of this object can be seen below:

{
  "transactionInput":{

    "id":"72a2f5a4-b5db-9f9f-2b76-a8ef2d02fc7a",

    "productId": "{{productId}}",
    "senderLocationId": "{{senderLocationId}}",
    "receiverLocationId": "{{receiverLocationId}}",

    "sendingDate":"2022-01-01",
    "quantity": 22,
    "isDocketNumberGenerated": true
  }
}

These fields are the information fields on the Transaction that you will create, for example the product ID may be for CHEP Pallets, and the quantity would be the quantity of that product involved in this Transaction.

The sendingDate and quantity fields are specific to each Transaction, and must be edited as such.

The isDocketNumberGenerated endpoint specifies if you would like a docket number generated for this Transaction, alternatively the docketNumber field can be directly written to, with custom docket numbers, see Transaction Input Glossary for more info.

The id field must be generated externally, and is the unique identifier for the Transaction that is being generated.

The productId field must be obtained from your own database, this is the unique identifier for the product that is being transacted. See Gathering Transactional Data.

The senderLocationId and receiverLocationId fields must be obtained from your own database, as these are unique identifiers for locations in your pallets database. See Gathering Transactional Data.
These locations must be a valid combination of "kind", for example, a tradingPartner to another tradingPartner Transaction is not allowed.

Please see Transaction Input Glossary for the full list of inputs and further explanation.

Gathering Transactional Data link

From 2ic Pallets Web App link

  1. Go to https://app.2icsoftware.com/ and log in.

  2. Select the grid you would like to see from the list on the left and find the record from the list that you would like to create a Transaction for.

find grids

  1. Unhide the ID field by clicking the book symbol on the upper left of the grid and checking "ID".

find ids

  1. Copy the ID for the record you want and enter it into the altair environment that was created earlier .

From recent Transactions link

  1. Run the GetTransactions query, there is an example in both of the Example Collections, this will display the last 5 transactions, you can use these to gather information if you are using the same information to create your Transaction.

Transaction Example

From querying Products and Locations link

  1. Run the location and product queries, there is an example in both of the Example Collections, this will display the records based on your filters.

Product Query Example

Example Collections link

2ic provides two example collections for creating Transactions:

  1. get_app 2ic Altair Collection 2ic-altair-collection.zip
  2. get_app 2ic Postman Collection 2ic-postman-collection.postman_collection

Creating a 2ic Transaction from Altair link

Downloading and viewing the Transaction example link

  1. Go to the 2ic pallets API at https://pallets-api.2icsoftware.com and click Altair GraphQL Client.

  2. Download the example collection from Example Collections and import it into altair.

  3. Open the Example collection and see the example queries.

Creating a Transaction from Altair link

  1. Find the CreateNewTransaction mutation, this mutation will create a Transaction in your database when ran.
mutation CreateNewTransaction ($transactionInput: CreateTransactionInput!) {
    createTransaction (input: $transactionInput) {
    content
    messages { kind key targets arguments { name value isValueAKey }}
  }
}
  1. In the variables section at the bottom of the page, find the transactionInput variable, edit this with the fields gathered from Gathering Transactional Data.

  2. Hit Run mutation CreateNewTransaction, if the response has no errors and its content is true, you have created a Transaction in your target database!

Creating a 2ic Transaction from Postman link

  1. Download the example collection from Example Collections and import it into Postman.

  2. Navigate to the Create Transaction post request under the transactions directory in the example collection, and click on the body tab and ensure that Graphql is selected.

  3. In the variables section on the right hand side of the page, add the data gathered from the Gathering Transactional Data, note that Postman supports generating their own Guids with {{$guid}}.

  4. Hit Send in the top right hand side of the page, if the response has no errors and its content is true, you have created a Transaction in your target database!

Additional information link

To see any Transaction that you have created, you can run the getTransactions query in either of the collection examples, and use the filtering to specify your input fields.
2ic does not support creating transactions with no id input, this is due to our create mutations not returning the id of the created Transaction, thus making the created record difficult to access.
For information on all of the possible fields on CreateTransactionInput and any error messages that may be encountered, please visit Transaction Input and Error Glossaries.

Last updated on 21/06/2024