PHP Code to Create Goshippo Shipment Using API

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.

<?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",
            "email" => "[email protected]"
                      );    
       
        $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",
            "email" => "[email protected]"
                      );

       $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.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *