Questions

Ask A Question
1
ANSWERED

API Integration

Hello, We are planning on integrating the API into our website that is built in PHP. In our website, we buy items from customers and we generate labels for our customers so they can send us the item. Our goal with the API is to 1. Get Rates from different shipping couriers 2. Create Shipment 3. Tracking The team successfully able to get the rages from different couriers. However, the team is having challenges with the "Create Shipment" part of the API. Below is the error message the team is getting: ["origin_address.contact_email is invalid","destination_address.postal_code is too long (maximum is 20 characters)","destination_address.contact_phone is too long (maximum is 20 characters)","destination_address.contact_email is invalid","sender_address.contact_email is invalid","return_address.contact_email is invalid","insurance.insured_amount is not a number"],"request_id":"4d489bb7-852e-4f8e-b5d2-e3cb8507cea1","timestamp":"2022-01-11T18:35:34.269Z"} The code that the team used is as following: $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.easyship.com/v2/shipments', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS =>'{ "origin_address": { "line_1": "$originaddress1", "line_2": "$originaddress2", "state": "$originstate", "city": "$origincity", "postal_code": "$originpostal_code", "country_alpha2": "US", "contact_name": "$origincontact_name", "company_name": "$origincompany_name", "contact_phone": "$origincontact_phone", "contact_email": "$origincontact_email" }, "sender_address": { "line_1": "$originaddress1", "line_2": "$originaddress2", "state": "$originstate", "city": "$origincity", "postal_code": "$originpostal_code", "country_alpha2": "US", "contact_name": "$origincontact_name", "company_name": "$origincompany_name", "contact_phone": "$origincontact_phone", "contact_email": "$origincontact_email" }, "return_address": { "line_1": "$originaddress1", "line_2": "$originaddress2", "state": "$originstate", "city": "$origincity", "postal_code": "$originpostal_code", "country_alpha2": "US", "contact_name": "$origincontact_name", "company_name": "$origincompany_name", "contact_phone": "$origincontact_phone", "contact_email": "$origincontact_email" }, "destination_address": { "line_1": "$destinationaddress1", "line_2": "$destinationaddress2", "state": "$destinationstate", "city": "$destinationcity", "postal_code": "$destinationpostal_code", "country_alpha2": "US", "contact_name": "$destinationcontact_name", "company_name": "$destinationcompany_name", "contact_phone": "$destinationcontact_phone", "contact_email": "$destinationcontact_email" }, "metadata": {}, "set_as_residential": false, "consignee_tax_id": null, "eei_reference": null, "incoterms": "DDU", "insurance": { "is_insured": false, "insured_amount": "$dealprice", "insured_currency": "USD" }, "order_data": { "platform_name": null, "platform_order_number": null, "order_tag_list": [ "VIP" ], "seller_notes": null, "buyer_notes": null }, "courier_selection": { "selected_courier_id": null, "allow_courier_fallback": false, "apply_shipping_rules": true }, "shipping_settings": { "units": { "weight": "lb", "dimensions": "in" }, "printing_options": { "format": "pdf", "label": "4x6", "commercial_invoice": "A4", "packing_slip": "none" }, "buy_label": false, "buy_label_synchronous": false }, "parcels": [ { "total_actual_weight": 0.8, "box": { "slug": null, "length": 10, "width": 8, "height": 5 }, "items": [ { "description": "Silk dress", "category": "fashion", "sku": "test01", "quantity": 2, "dimensions": { "length": null, "width": null, "height": null }, "actual_weight": 10, "declared_currency": "USD", "declared_customs_value": 20 } ] } ] }', CURLOPT_HTTPHEADER => array( 'Accept: application/json', 'Content-Type: application/json', 'Authorization: Bearer sand_2XLWDdb4/ll9K8Id9UkGj35JZqG5F/ekOMWL4/L7fB0=' ), )); $response = curl_exec($curl); curl_close($curl); echo $response;

Posted by Khodr Saleh 5 days ago