The following article will cover how to edit a consignment via the API when you are delegating your own carrier consignment numbers and item references/barcodes.
The main use cases for an edit workflow include:
- Adjusting item weights/dimensions
- Adding new items and references
- Removing items and references
Note:
- This article will not cover the basics of creating consignments.
- An article covering consignment creation in depth can be found here: A guide to creating Consignments via the API
- This article is specific to workflows where the user is delegating their own carrier consignment ID and item references/barcodes. A simpler guide on editing consignments via the API where you are NOT allocating carrier consignment IDs and item references/barcodes can be found here: How to Edit Consignments Via The API
Edit Consignment Workflow
Step 1: Create Your Consignment
When you are looking to generate your own consignment numbers and item references/barcodes and pass them into Machship you must use the following endpoint to create consignments:
/apiv2/consignments/createConsignmentwithComplexItems
When using this endpoint, we have two undocumented fields you will need to add to your payload:
- carrierConsignmentId - sitting at the parent level, this value is the carrier consignment ID, which must follow the carrier specifications including any relevant prefixes that you have generated for this consignment.
- items.consignmentItemReferences.carrierItemReference - This field sits inside an array on the items object, inside the consignmentItemReferences array object and is the barcode that will be used on the label. This barcode must follow the carrier specifications.
An example of how these would be set is:
{
"carrierConsignmentId": "2657628002",
"carrierId": "446",
//all other consignment data
"items": [
{
"name": "Pallet",
"quantity": 2,
"itemType": "Pallet",
"standardItem": {
"weight": 270,
"length": "117",
"height": "110",
"width": "117"
},
"consignmentItemReferences": [
{
"carrierItemReference": "(00)393168610029113320"
},
{
"carrierItemReference": "(00)393168610029113321"
}
]
}
]
}
The response you get on a successful consignment create will include an "id" value - which is the Machship consignment ID.
You will need to store this returned "id" value so you are able to retrieve and modify the consignment in the following steps.
NOTE: If you are unable to store the returned id value, then prior to calling the GET endpoint mentioned in the next step, you will first need to call /apiv2/consignments/returnConsignmentsByCarrierConsignmentId using the consignment ID you delegated earlier, then get the ID from that, before you proceed with step 2 as it is required for the next endpoints.
Step 2: Get Your Consignment
To edit a consignment, you would first call:
GET /apiv2/consignments/getUnmanifestedConsignmentForEdit
The only key value pair required is:
id = the consignment ID stored from previous step.
This endpoint returns the full schema of data about the consignment in the format required for editing.
Step 3: Edit Your Consignment
Now that you have your response, take everything from inside the object section, and start making your edits.
You can add new items, remove them, or edit them.
To add an item with a barcode you would add a new item in the following format:
- {
- "itemType": "Carton",
- "name": "Test Item",
- "quantity": 1,
- "standardItem": {
- "height": 20.00000,
- "weight": 1.00000,
- "length": 20.00000,
- "width": 20.00000
- },
- "consignmentItemReferences": [
- {
- "carrierItemReference": "642000123456780000299006",
- }
- ]
- }
If you are adding barcodes or removing non-sequential barcodes you need to edit this value, setting it to TRUE:
- {
"id": 26848234,
"setItemReferences": true,
//ALL RETURNED CONSIGNMENT DATA HERE
"items": [
{
"itemType": "Carton",
"name": "Test Item",
"quantity": 1,
"standardItem": {
"height": 20.00000,
"weight": 1.00000,
"length": 20.00000,
"width": 20.00000
},
"consignmentItemReferences": [
{
"carrierItemReference": "642000123456780000299006",
"printed": false,
"printedDateUtc": null
}
]
}
],
//ANY & ALL REMAINING CONSIGNMENT DATA HERE
}
This instructs us to read the barcodes from the lines, rather than generating our own.
If you note that we are ignoring the barcodes you have set, and are setting our own, it is likely either that you forgot this value, or the carrier doesn't support allocating barcodes from outside of Machship.
Step 4: POST Your Edit
Send this edited payload to POST /apiv2/consignments/editUnmanifestedConsignment
The response from this will be your edited payload - check it and ensure the item references and consignment Id is what you expect.
That's it - you're done!