5.1.3 Create Shipments (Python)
Create Shipment
Sample source code to create shipment
#!/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 createShipment(url, data):
res = requests.post(url + 'shipment/v2/Create', 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": "Mr Mehmet Abadi",
"Address1": "46-02 JALAN TUN ABDUL RAZAK,",
"Address2": "SUSUR 1,",
"Address3": "",
"Postcode": "80000",
"City": "JOHOR BAHRU",
"State": "JOHOR",
"CountryCode": "MY",
"Phone1": "+6072222668"
},
"Consignee": {
"ContactPerson": "Mr Nick Champ",
"Address1": "Test Address 1",
"Address2": "Test Address 2",
"Postcode": "70000",
"City": "SEREMBAN",
"State": "NEGERI SEMBILAN",
"CountryCode": "MY",
"Phone1": "03-8888888"
},
"Items": [
{
"Description": "SHOES",
"Quantity": 1,
"UnitValue": 20.0,
"HSCode": "64035990",
"SKU": "BC008237",
"Url": "http://shoes.com/?id=123"
}
],
"Packages": [
{
"PackageReference": "PKG001",
"Length": 30.0,
"Width": 10.0,
"Height": 10.0,
"ActualWeight": 3.5
}
],
"PackageType": "SPX",
"WeightType": "KG",
"ShipmentDate": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
"TOSMode": "MY-E-LWE",
"ReferenceNo": "ORDERREF00001",
"CurrencyCode": "MYR",
"CODValue": 0,
"CODCurrency": ""
"InsuranceValue": 10.0,
"InsuranceCurrency": "MYR"
}
]
}
resData = createShipment(sandbox_url, json.dumps(request_data))
print(resData)