Goshippo is the popular shipping company which will take care of you all shipments, So you can focus on your Business. They have official API mentioned with full API documentation. You can do any third party integration with Goshippo Shipping API.
In this article we are going to explain How to Create Goshippo Shipment using PHP. First you need to get API token from Shippo API settings page. Goshippo API require HTTP Authentication method with token. You can put Authorization: ShippoToken in your header request.
Creating Goshippo Shipment API Call Using PHP
To create a new shipment inside Goshippo, need to create shipment object as send in api request.
API Resource URL: https://api.goshippo.com/shipments/
Goshippo Create Shipment PHP Code:
Check below PHP sample code to send shipment api request. Create a request object for address_from, address_to and parcel.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
<?php $headers = array( "Content-Type: application/json", "Authorization: ShippoToken bbfa1db******************651c0" // place your shippo private token here ); $url = 'https://api.goshippo.com/shipments/'; $address_from = array( "object_purpose"=> "PURCHASE", "name"=> "sender name", "street1"=> "1092 Indian Summer Ct", "city"=> "San Jose", "state"=> "CA", "zip" => "95122", "country" => "US", "phone" => "5654546565", ); $address_to = array( "object_purpose"=> "PURCHASE", "name"=> "recipeint name", "street1"=> "965 Mission St #572", "city"=> "San Francisco", "state"=> "CA", "zip" => "94103", "country" => "US", "phone" => "45366373243", ); $parcel = array( "length"=> "10", "width"=> "15", "height"=> "10", "distance_unit"=> "in", "weight"=> "1", "mass_unit" => "lb" ); $shipment = array( "object_purpose" => "PURCHASE", "address_from" => $address_from, // you can use Shippo Address Object Id here instead of new object. "address_to" => $address_to, "parcel" => $parcel, "async" => false ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($shipment)); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); curl_close($ch); ?> |
You can easily integrate this Goshippo Shipment API php code with any third party software. This will automate the shipment process. In our next post we will explain you How to Print Goshippo Shipping Label using PHP.