1

I am integrating shippo API so far it is working great but there is this problem that when I send the request to create shipment shipment is creating but there is nothing in the rate array but when I send the same request through postman I am getting those rates here is the request that I am sending.

//    Receiver Information for making shipment.
$r_name = $result[0]->r_name;
$r_email = $result[0]->r_email;
$r_street = $result[0]->r_street;
$r_city = $result[0]->r_city;
$r_country = $result[0]->r_country;
$r_zip = $result[0]->r_zip;
$r_state = $result[0]->r_state;

// Sender Information for making Shipment.
$s_name = $result[0]->s_name;
$s_email = $result[0]->s_email;
$s_street = $result[0]->s_street;
$s_city = $result[0]->s_city;
$s_country = $result[0]->s_country;
$s_zip = $result[0]->s_zip;
$s_state = $result[0]->s_state;

// Parcel Information for making Shipment.
$p_qty = $result[0]->p_qty;
$p_name = $result[0]->p_name;
$p_price = $result[0]->p_price;
$p_weight = $result[0]->p_weight;
$p_unit = $result[0]->p_unit;

$shipment_array = array(
    'address_to' => array(
        'name' => $r_name,
        'street1' => $r_street,
        'city' => $r_city,
        'state' => $r_state,
        'zip' => $r_zip,
        'country' => $r_country,
        'phone' => '03212669686',
        'email' => $r_email
    ),
    'address_from' => array(
        'name' => $s_name,
        'street1' => $s_street,
        'city' => $s_city,
        'state' => $s_state,
        'zip' => $s_zip,
        'country' => $s_country,
        'phone' => '03227577798',
        'email' => $s_email
    ),
    'parcels' => array(
        array(
            "length" => "10",
            "width" => "15",
            "height" => "10",
            "distance_unit" => "in",
            "weight" => $p_weight,
            "mass_unit" => $p_unit
        )
    ),
    'async' => false
);

$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => "https://api.goshippo.com/shipments/",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => json_encode($shipment_array),
    CURLOPT_HTTPHEADER => array(
        "Authorization: ShippoToken shippo_test_742eabd1c83ece80052fbce9ee71163181eaee72",
        "Cache-Control: no-cache",
        "Content-Type: application/json",
        "Postman-Token: 906233f7-ac66-3951-f96a-4f0f88c8d419"
    ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response;
}

Can anyone help me finding out what am I doing wrong here.

Mohsin Abbas
  • 630
  • 8
  • 29
  • I am getting same issues with shippo, Have found any solution for it ? – Mayank Vadiya Jul 23 '18 at 07:00
  • Yes, Founded the solution in my case the address was mismatching I was sending the static parameters in postman that is why it is returning rate and in my request when sent dynamically the address_to was not proper. – Mohsin Abbas Jul 28 '18 at 08:51
  • Hope this helps you if not please send me your request that you are sending so that I can check for issues – Mohsin Abbas Jul 28 '18 at 08:51

0 Answers0