Created
May 3, 2018 15:51
-
-
Save tiagomatos/dc0825767b308d376a1ba73c2db88a17 to your computer and use it in GitHub Desktop.
Create DHL eCommerce Label
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'byebug' | |
require 'awesome_print' | |
require 'httparty' | |
username = 'elite.track' | |
password = 'axwdavgo' | |
client_id = 35318 | |
pickup = 1000000047 | |
response = HTTParty.get("https://api.dhlglobalmail.com/v2/auth/access_token?username=#{username}&password=#{password}") | |
access_token = response.parsed_response['data']['access_token'] | |
[43,41,42,34,35,46,69,56,57,29,27,28,59,58,51,47,48,60,54,76,77,72,73,81,631,82,36,83,532,531,491,761,764,384,383,44,45].each do |product_id| | |
label_json = { | |
"shipments": [{ | |
"pickup": "#{pickup}", | |
"distributionCenter": "USORD1", | |
"packages": [{ | |
"consigneeAddress": { | |
"address1": "Address line 1", | |
"address2": "apt 123", | |
"city": "Test City", | |
"country": "CZ", | |
"email": "[email protected]", | |
"name": "Test Name", | |
"phone": "555-555-5555", | |
"postalCode": "99999", | |
"state": "GA" | |
}, | |
"packageDetails": { | |
"billingRef1": "test ref 1", | |
"billingRef2": "test ref 2", | |
"codAmount": 0, | |
"currency": "USD", | |
"declaredValue": 250.00, | |
# "dgCategory": "01", | |
"dimensionUom": "IN", | |
"dutyCharges": 10.00, | |
"dutiesPaid": "N", | |
"freightCharges": 10.00, | |
"insuredValue": 1, | |
"mailtype": "7", | |
"orderedProduct": product_id, | |
"packageDesc": "Desc", | |
"packageId": "99999999999999999999999", | |
"packageRefName": "55555555555555555", | |
"taxCharges": 10.00, | |
"weight": 1, | |
"weightUom": "LB" | |
}, | |
"returnAddress": { | |
"address1": "Address line 1", | |
"city": "Test City", | |
"companyName": "Test Company", | |
"country": "US", | |
"name": "John Returns Doe", | |
"postalCode": "99999", | |
"state": "GA" | |
}, | |
"customsDetails": [{ | |
"itemDescription": "Desc", | |
"countryOfOrigin": "US", | |
"hsCode": "888888888888", | |
"packagedQuantity": 10, | |
"itemValue": 10.00, | |
"skuNumber": "3333333333333" | |
}] | |
}] | |
}] | |
} | |
response2 = HTTParty.post("https://api.dhlglobalmail.com/v2/label/multi/image.json?access_token=#{access_token}&client_id=#{client_id}", body: label_json.to_json, headers: { | |
'Content-Type' => 'application/json', | |
'Accept' => 'application/json' | |
}) | |
ap "Product ID - #{product_id}" | |
ap response2.parsed_response['data']['shipments'].first['packages'].first['errors'].first | |
ap "-----------" | |
end | |
p "Finished" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment