// STEP 1: Get OAuth Token
client_id = "YOUR_CLIENT_ID_HERE";
client_secret = "YOUR_CLIENT_SECRET_HERE";
token_url = "https://onlinetools.ups.com/security/v1/oauth/token";
auth_str = client_id + ":" + client_secret;
encodedAuth = zoho.encryption.base64Encode(auth_str);
headers_token = Map();
headers_token.put("Content-Type", "application/x-www-form-urlencoded");
headers_token.put("x-merchant-id", "YOUR_MERCHANT_ID");
headers_token.put("Authorization", "Basic " + encodedAuth);
bodyParams = Map();
bodyParams.put("grant_type", "client_credentials");
bodyParams.put("scope", "ship");
token_response = invokeurl
[
url : token_url
type : POST
parameters : bodyParams
headers : headers_token
];
info "Token Response: " + token_response;
access_token = token_response.get("access_token");
info "Access Token: " + access_token;
// STEP 2: Call Shipment API
shipment_url = "https://onlinetools.ups.com/api/shipments/v1/ship?additionaladdressvalidation=city";
headers_ship = Map();
headers_ship.put("Content-Type", "application/json");
headers_ship.put("Authorization", "Bearer " + access_token);
headers_ship.put("x-merchant-id", "YOUR_MERCHANT_ID");
headers_ship.put("transId", "e2b7d510-29cb-4c4d-8ab0-3d8a92876c91");
headers_ship.put("transactionSrc", "ZOHOCRM");
// Sample shipment JSON (simplify to test)
shipment_body = {"ShipmentRequest":{"Shipment":{"Description":"Inbound Karger","Shipper":{"Name":"Smart Service","AttentionName":"Smart Servicios","TaxIdentificationNumber":"456789","Phone":{"Number":"+34 971 571 044"},"ShipperNumber":"0Y15W6","Address":{"AddressLine":"Font i Monteros 6 2a planta","City":"Palma de Mallorca","StateProvinceCode":"ES","PostalCode":"07003","CountryCode":"ES"}},"ReturnService":{"Code":"9"},"ShipTo":{"Name":"Smart Service","AttentionName":"Smart Servicios","Phone":{"Number":"+34 971 571 044"},"FaxNumber":"1234567999","TaxIdentificationNumber":"456999","Address":{"AddressLine":"Font i Monteros 6 2a planta","City":"Palma de Mallorca","StateProvinceCode":"ES","PostalCode":"07003","CountryCode":"ES"}},"ShipFrom":{"Name":"Familie Pascal Karger","AttentionName":"Test Company","Phone":{"Number":"+41764752096"},"FaxNumber":"1234567999","TaxIdentificationNumber":"456999","Address":{"AddressLine":["Am Hinkeln 6"],"City":"Schwerte","StateProvinceCode":null,"PostalCode":"58239","CountryCode":"DE"}},"PaymentInformation":{"ShipmentCharge":{"Type":"01","BillShipper":{"AccountNumber":"0Y15W6"}}},"Service":{"Code":"07","Description":"UPS Express"},"Package":[{"Description":"Inbound Karger","Packaging":{"Code":"01"},"PackageWeight":{"UnitOfMeasurement":{"Code":"KGS"},"Weight":".3"}}],"ItemizedChargesRequestedIndicator":"","RatingMethodRequestedIndicator":"","TaxInformationIndicator":"","ShipmentRatingOptions":{"NegotiatedRatesIndicator":""},"ShipmentServiceOptions":{"Notification":{"NotificationCode":"2","EMail":{"EMailAddress":"ups@smart-servicios.com","Memo":null}}}},"LabelSpecification":{"LabelImageFormat":{"Code":"GIF"}}}};
shipment_response = invokeurl
[
url : shipment_url
type : POST
parameters : shipment_body.toString()
headers : headers_ship
];
info "ShipmentResponse: " + shipment_response;
Posts