This script shows how to use the ShipEngine API to buy postage and generate a PDF shipping label. Full details, options, sample integration code available at https://www.shipengine.com/docs/labels/create-a-label <?php $service_code = $_GET["service_code"]; $ship_to_name = $_GET["ship_to_name"]; $ship_to_address_line1 = $_GET["ship_to_address_line1"]; $ship_to_city_locality = $_GET["ship_to_city_locality"]; $ship_to_state_province = $_GET["ship_to_state_province"]; $ship_to_postal_code = $_GET["ship_to_postal_code"]; $ship_to_country_code = $_GET["ship_to_country_code"]; $ship_to_address_residential_indicator = $_GET["ship_to_address_residential_indicator"]; $ship_from_name = $_GET["ship_from_name"]; $ship_from_company_name = $_GET["ship_from_company_name"]; $ship_from_phone = $_GET["ship_from_phone"]; $ship_from_address_line1 = $_GET["ship_from_address_line1"]; $ship_from_city_locality = $_GET["ship_from_city_locality"]; $ship_from_state_province = $_GET["ship_from_state_province"]; $ship_from_postal_code = $_GET["ship_from_postal_code"]; $ship_from_country_code = $_GET["ship_from_country_code"]; $ship_from_address_residential_indicator = $_GET["ship_from_address_residential_indicator"]; $weight_value = $_GET["weight_value"]; $weight_unit = $_GET["weight_unit"]; $height = $_GET["height"]; $width = $_GET["width"]; $length = $_GET["length"]; $unit = $_GET["unit"]; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://api.shipengine.com/v1/labels", 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 =>"{\n \"shipment\": {\n \"service_code\": \"$service_code\",\n \"ship_to\": {\n \"name\": \"$ship_to_name\",\n \"address_line1\": \"$ship_to_address_line1\",\n \"city_locality\": \"$ship_to_city_locality\",\n \"state_province\": \"$ship_to_state_province\",\n \"postal_code\": \"$ship_to_postal_code\",\n \"country_code\": \"$ship_to_country_code\",\n \"address_residential_indicator\": \"$ship_to_address_residential_indicator\"\n },\n \"ship_from\": {\n \"name\": \"$ship_from_name\",\n \"company_name\": \"$ship_from_company_name\",\n \"phone\": \"$ship_from_phone\",\n \"address_line1\": \"$ship_from_address_line1\",\n \"city_locality\": \"$ship_from_city_locality\",\n \"state_province\": \"$ship_from_state_province\",\n \"postal_code\": \"$ship_from_postal_code\",\n \"country_code\": \"$ship_from_country_code\",\n \"address_residential_indicator\": \"$ship_from_address_residential_indicator\"\n },\n \"packages\": [\n {\n \"weight\": {\n \"value\": \"$weight_value\",\n \"unit\": \"$weight_unit\"\n },\n \"dimensions\": {\n \"height\": \"$height\",\n \"width\": \"$width\",\n \"length\": \"$length\",\n \"unit\": \"$unit\"\n }\n }\n ]\n }\n}", CURLOPT_HTTPHEADER => array( "Host: api.shipengine.com", "API-Key: TEST_KbNCYts3QVUJxZZ3ImfOf1bkKI4ySDBJhQwuXzn723U", "Content-Type: application/json"), )); $response = curl_exec($curl); curl_close($curl); $result = json_decode($response, TRUE); function search_through_array($search,array $lists){ try{ foreach ($lists as $key => $value) { if(is_array($value)){ array_walk_recursive($value, function($v, $k) use($search ,$key,$value,&$val){ if(strpos($v, $search) !== false ) $val[$key]=$value;}); }else{ if(strpos($value, $search) !== false ) $val[$key]=$value;}} return $val;}catch (Exception $e) {return false;} } $new = search_through_array('pdf',$result); $Package = json_encode($new,TRUE); //header("Location: https://postback.goformz.com/webviewreturn?Package=".$Package); ?> |