5.2.3 Modify Shipments (Python)
Modify Shipment
Sample source code for modify shipment. Please note that a new HAWB will be generated and the old HAWB will be deleted.
#!/usr/bin/python
import time
import json
import requests
production_url = "https://apiv2.unixus.com.my/"
sandbox_url = "https://sandbox-apiv2.unixus.com.my/"
myRefreshToken = "88888888" # Replace your Refresh Token here
def getAccessToken(url):
res = requests.post(url + 'Token/Refresh', data='{ "RefreshToken" : "' + myRefreshToken + '"}', headers={
'Content-Type': 'application/json',
'Accept-Language': 'en'
})
responseContent = res.content
j = json.loads(responseContent)
return j['AccessToken']
def modifyShipment(url, data):
res = requests.post(url + 'shipment/v2/Modify', data=data, headers={
'Content-Type': 'application/json',
'Accept-Language': 'en',
'Authorization': 'Bearer ' + getAccessToken(url)
})
responseContent = res.content
j = json.loads(responseContent)
return j
request_data = {
"Shipments": [
{
"Shipper": {
"Name": "DEMO ACCOUNT",
"ContactPerson": "Ms Angie",
"Address1": "No.4",
"Address2": "Jalan SS13/6C",
"Address3": "",
"Postcode": "47500",
"City": "Subang Jaya",
"State": "Selangor",
"CountryCode": "MY",
"Phone1": "+60388008830"
},
"Consignee": {
"ContactPerson": "James Brown",
"Address1": "Test Address 1",
"Address2": "Test Address 2",
"Postcode": "70000",
"City": "JOHOR BAHRU",
"State": "SELANGOR",
"CountryCode": "MY",
"Phone1": "012-3668899"
},
"Items": [
{
"Description": "Shoes, TShirt",
"Quantity": 2,
"UnitValue": 50,
"HSCode": "64035990",
"SKU": "ABC123",
"Url": "http://www.mywebsite.com"
}
],
"Packages": [
{
"PackageReference": "Shoes001",
"Length": 30,
"Width": 10,
"Height": 10,
"ActualWeight": 1.5
},
{
"PackageReference": "TShirt002",
"Length": 30,
"Width": 30,
"Height": 10,
"ActualWeight": 1.1
}
],
"HawbNo": "458040010619601",
"PackageType": "SPX",
"WeightType": "KG",
"ShipmentDate": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
"TOSMode": "MY-E-LWE",
"ReferenceNo": "ORDERREF00001",
"CurrencyCode": "MYR"
}
]
}
resData = modifyShipment(sandbox_url, json.dumps(request_data))
print(resData)