This article target developers looking to create shipments based on the Token returned by the method GetShipAdvise.
Note: This is only to show a basic example.
You need to apply your own business logic and error handling.
Content in this article:
The Token key
A special key that can contain Product, GoodsType, Services and values from the Expressions used in the CSR document.
The idea with the Token is that you no longer need to extend the data object with the above information.
You just need to add the Token key in the options object.
Note: You can use the Developer Tools to test the requests
Example
Sending a request to the GetShipAdvise method with the options and data object below:
Options:
{
"ServiceLevel": "Service_Level_Configured_For_SA"
}
Data:
{
"Addresses": [
{
"Kind": 1,
"Name1": "Name1 - Receiver",
"Street1": "Test address 1",
"PostCode": "7400",
"City": "Herning",
"CountryCode": "DK",
"Email": "noreply@nshift.com"
}
],
"Lines": [
{
"PkgWeight": 1000,
"Number": 1
}
]
}
Will result in a response like this:
{
"Products": [
{
"ProdConceptID": 113,
"ProdCSID": 349,
"ProdName": "GLS DK - Normal erhvervspakke",
"CustomFields": {
"type": "Home Delivery"
},
"Services": [
{
"serviceid": 11008,
"name": "Privat Levering"
},
{
"serviceid": 11014,
"name": "Flex Delivery"
}
],
"Token": "11008|11014_0_0_547_517_349_113_0_0__0_PEV4cHJlc3Npb25zPg0KCTxFeHByZXNzaW9uIHRhcmdldGZpZWxkPSJmbGRfQWRyU2VuZGVyTmFtZTEiPg0KCQk8SXRlbSBleHByZXNzaW9uPSJDb25zaWdub3IgQS9TIi8+DQoJPC9FeHByZXNzaW9uPg0KCTxFeHByZXNzaW9uIHRhcmdldGZpZWxkPSJmbGRfQWRyU2VuZGVyQXR0ZW50aW9uIj4NCgkJPEl0ZW0gZXhwcmVzc2lvbj0iQXR0ZW50aW9uIi8+DQoJPC9FeHByZXNzaW9uPg0KCTxFeHByZXNzaW9uIHRhcmdldGZpZWxkPSJmbGRfQWRyU2VuZGVyQWRkcmVzczEiPg0KCQk8SXRlbSBleHByZXNzaW9uPSJCcmVkc2tpZnRlIEFsbMOpIDExIi8+DQoJPC9FeHByZXNzaW9uPg0KCTxFeHByZXNzaW9uIHRhcmdldGZpZWxkPSJmbGRfQWRyU2VuZGVyQ291bnRyeSI+DQoJCTxJdGVtIGV4cHJlc3Npb249IkRLIi8+DQoJPC9FeHByZXNzaW9uPg0KCTxFeHByZXNzaW9uIHRhcmdldGZpZWxkPSJmbGRfQWRyU2VuZGVyUG9zdE5vIj4NCgkJPEl0ZW0gZXhwcmVzc2lvbj0iODIxMCIvPg0KCTwvRXhwcmVzc2lvbj4NCgk8RXhwcmVzc2lvbiB0YXJnZXRmaWVsZD0iZmxkX0FkclNlbmRlckNpdHkiPg0KCQk8SXRlbSBleHByZXNzaW9uPSJBYXJodXMgViIvPg0KCTwvRXhwcmVzc2lvbj4NCgk8RXhwcmVzc2lvbiB0YXJnZXRmaWVsZD0iZmxkX0FkclNlbmRlck1vYmlsZSI+DQoJCTxJdGVtIGV4cHJlc3Npb249IjEyMzQ1Njc4Ii8+DQoJPC9FeHByZXNzaW9uPg0KCTxFeHByZXNzaW9uIHRhcmdldGZpZWxkPSJmbGRfQWRyU2VuZGVyUGhvbmUiPg0KCQk8SXRlbSBleHByZXNzaW9uPSIxMjM0NTY3OCIvPg0KCTwvRXhwcmVzc2lvbj4NCgk8RXhwcmVzc2lvbiB0YXJnZXRmaWVsZD0iZmxkX0FkclNlbmRlckVtYWlsIj4NCgkJPEl0ZW0gZXhwcmVzc2lvbj0ibm8tcmVwbHlAY29uc2lnbm9yLmNvbSIvPg0KCTwvRXhwcmVzc2lvbj4NCjwvRXhwcmVzc2lvbnM+_30\/12\/1899_30\/12\/1899___",
"SupportsDropPoint": 0
}
]
}
See the CSR configuration to see why these products where returned.
Now if you apply the Token in the options object for the request to the SubmitShipment method.
Options:
{
"Labels": "PNG",
"Token": "11008|11014_0_0_547_517_349_113_0_0__0_PEV4cHJlc3Npb25zPg0KCTxFeHByZXNzaW9uIHRhcmdldGZpZWxkPSJmbGRfQWRyU2VuZGVyTmFtZTEiPg0KCQk8SXRlbSBleHByZXNzaW9uPSJDb25zaWdub3IgQS9TIi8+DQoJPC9FeHByZXNzaW9uPg0KCTxFe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2lvbj4NCjwvRXhwcmVzc2lvbnM+_30\/12\/1899_30\/12\/1899___"
}
But still only using the same Data object as in the request to GetShipAdvise:
{
"Addresses": [
{
"Kind": 1,
"Name1": "Name1 - Receiver",
"Street1": "Test address 1",
"PostCode": "7400",
"City": "Herning",
"CountryCode": "DK",
"Email": "noreply@nshift.com"
}
],
"Lines": [
{
"PkgWeight": 1000,
"Number": 1
}
]
}
When you inspect the response, it should contain a shipment based on the Token from the product returned from GetShipAdvise.
The ProdConceptID, Sender Address (Expressions), GoodsType & Services should now have been applied.
{
"ShpCSID": 3375,
"ShpESID": 3233700847,
"ShpTag": "EF59D0A0-0EF3-4155-AEB9-3516B076ECC0",
"InstallationID": "30000364023",
"Kind": 1,
"PickupDt": "2019-09-19T00:00:00",
"LabelPrintDt": "2019-09-19T13:25:26",
"SubmitDt": "2019-09-19T13:25:26",
"DimensionalWeight": 1000,
"Weight": 1000,
"ActorCSID": 83,
"Temperature": 1,
"CarriagePayer": 1,
"CarrierConceptID": 11,
"CarrierCSID": 14,
"SubcarrierConceptID": 23,
"SubcarrierCSID": 53,
"ProdConceptID": 113,
"ProdCSID": 349,
"StackCSID": 51,
"PayerAccountAtCarrier": "99999",
"SenderAccountAtCarrier": "99999",
"Addresses": [
{
"Kind": 1,
"Name1": "Name1 - Receiver",
"Street1": "Test address 1",
"PostCode": "7400",
"City": "Herning",
"Email": "noreply@nshift.com",
"CountryCode": "DK"
},
{
"Kind": 13
},
{
"Kind": 2,
"Name1": "nShift A\/S",
"Street1": "Bredskifte All\u00e9 11",
"PostCode": "8210",
"City": "Aarhus V",
"Phone": "12345678",
"Mobile": "12345678",
"Email": "no-reply@nshift.com",
"Attention": "Attention",
"CountryCode": "DK"
}
],
"Amounts": [
],
"References": [
],
"CSEvents": [
{
"Kind": 4,
"Date": "2019-09-19T13:25:26",
"User": "SS\/83\/SubmitShipment",
"EventTag": "55DC1C6B-5096-465D-8728-82B796828BA7"
}
],
"Lines": [
{
"LineCSID": 3650,
"LineTag": "B94A6759-3037-4780-AB06-288255A3291C",
"LineWeight": 1000,
"PkgWeight": 1000,
"GoodsTypeName": "Business-Parcel",
"GoodsTypeKey1": "A",
"Pkgs": [
{
"PkgCSID": 3440,
"ItemNo": 1,
"PkgTag": "54224D60-CA36-41FB-96B0-067EEF664062",
"PkgNo": "099999113068",
"References": [
],
"CSEvents": [
{
"Kind": 8,
"Date": "2019-09-19T13:25:26",
"User": "SS\/83\/SubmitShipment",
"EventTag": "1378AD8A-F145-4AE8-B206-03038B7495E9"
}
]
}
],
"References": [
{
"Kind": 219,
"Value": "True"
}
]
}
],
"Services": [
11008,
11014
],
"Labels": [
{
"Content": "iVBORw0KGgo...",
"Type": 10,
"Copies": 1,
"PkgCSID": 3440,
"PkgNo": "099999113068"
}
]
}
Shipping Rules
The configuration file containing the products and validations used for the GetShipAdvise method in this article.
<?xml version="1.0" encoding="utf-8"?>
<CSR carriervalidation="0" defaultservicelevel="Service_Level_Configured_For_SA">
<Expressions>
<Expression targetfield="fld_AdrSenderName1">
<Item expression="nShift A/S"/>
</Expression>
<Expression targetfield="fld_AdrSenderAttention">
<Item expression="Attention"/>
</Expression>
<Expression targetfield="fld_AdrSenderAddress1">
<Item expression="Bredskifte Allé 11"/>
</Expression>
<Expression targetfield="fld_AdrSenderCountry">
<Item expression="DK"/>
</Expression>
<Expression targetfield="fld_AdrSenderPostNo">
<Item expression="8210"/>
</Expression>
<Expression targetfield="fld_AdrSenderCity">
<Item expression="Aarhus V"/>
</Expression>
<Expression targetfield="fld_AdrSenderMobile">
<Item expression="12345678"/>
</Expression>
<Expression targetfield="fld_AdrSenderPhone">
<Item expression="12345678"/>
</Expression>
<Expression targetfield="fld_AdrSenderEmail">
<Item expression="no-reply@nshift.com"/>
</Expression>
</Expressions>
<ServiceLevels>
<ServiceLevel name="Service_Level_Configured_For_SA">
<Products>
<Product name="GLS DK - Normal erhvervspakke" conceptid="113">
<ProductGoodsType goodstypeid="0"/>
<CustomFields type="Home Delivery"/>
<ValidationRules>
<ValidationRule name="country" allowcountries="DK" field="fld_AdrCountry"/>
</ValidationRules>
<Services>
<Service serviceid="11008" name="Private Delivery Service"/>
<Service serviceid="11014"/>
</Services>
</Product>
<Product name="GLS DK - Export" conceptid="189">
<ProductGoodsType goodstypeid="0"/>
<CustomFields type="Home Delivery"/>
<ValidationRules>
<ValidationRule name="country" allowcountries="SE" field="fld_AdrCountry"/>
</ValidationRules>
</Product>
</Products>
</ServiceLevel>
</ServiceLevels>
</CSR>