Skip to content

Latest commit

 

History

History
174 lines (110 loc) · 8.52 KB

README.md

File metadata and controls

174 lines (110 loc) · 8.52 KB

Rates

Overview

A rate is the cost to ship a parcel from a carrier. The rate object details the service level including the cost and transit time.

Available Operations

get

Returns an existing rate using a rate object ID.

Example Usage

<?php

declare(strict_types=1);

require 'vendor/autoload.php';

use \Shippo\API;
use \Shippo\API\Models\Components;
use \Shippo\API\Models\Operations;

$security = new Components\Security();
$security->apiKeyHeader = '<YOUR_API_KEY_HERE>';

$sdk = API\ShippoSDK::builder()
    ->setShippoApiVersion('2018-02-08')
    ->setSecurity($security)->build();

try {
    

    $response = $sdk->rates->get('<value>', '2018-02-08');

    if ($response->rate !== null) {
        // handle response
    }
} catch (Throwable $e) {
    // handle exception
}

Parameters

Parameter Type Required Description Example
rateId string ✔️ Object ID of the rate
shippoApiVersion string String used to pick a non-default API version to use 2018-02-08

Response

?\Shippo\API\Models\Operations\GetRateResponse

listShipmentRates

Returns a paginated list of rates associated with a shipment

Example Usage

<?php

declare(strict_types=1);

require 'vendor/autoload.php';

use \Shippo\API;
use \Shippo\API\Models\Components;
use \Shippo\API\Models\Operations;

$security = new Components\Security();
$security->apiKeyHeader = '<YOUR_API_KEY_HERE>';

$sdk = API\ShippoSDK::builder()
    ->setShippoApiVersion('2018-02-08')
    ->setSecurity($security)->build();

try {
    

    $response = $sdk->rates->listShipmentRates('<value>', 253644, 758978, '2018-02-08');

    if ($response->ratePaginatedList !== null) {
        // handle response
    }
} catch (Throwable $e) {
    // handle exception
}

Parameters

Parameter Type Required Description Example
shipmentId string ✔️ Object ID of the shipment to update
page int The page number you want to select
results int The number of results to return per page (max 100)
shippoApiVersion string String used to pick a non-default API version to use 2018-02-08

Response

?\Shippo\API\Models\Operations\ListShipmentRatesResponse

listShipmentRatesByCurrencyCode

Returns all available shipping rates for a shipment object.

When you create a new valid shipment object, Shippo automatically calculates all available rates. Depending on your shipment data, there may be none, one or multiple rates.

By default, the calculated rates will return the price in two currencies under the amount and amount_local keys, respectively. The amount key will contain the price of a rate expressed in the currency that is used in the country from where the parcel originates, and the amount_local key will contain the price expressed in the currency that is used in the country the parcel is shipped to. You can request rates with prices expressed in a different currency by adding the currency code to the end of the resource URL. The full list of supported currencies along with their codes can be viewed on open exchange rates.

Note: re-requesting the rates with a different currency code will re-queue the shipment (i.e. set the Shipment's status to QUEUED) and the converted currency rates will only be available when the Shipment's status is set to SUCCESS.

Example Usage

<?php

declare(strict_types=1);

require 'vendor/autoload.php';

use \Shippo\API;
use \Shippo\API\Models\Components;
use \Shippo\API\Models\Operations;

$security = new Components\Security();
$security->apiKeyHeader = '<YOUR_API_KEY_HERE>';

$sdk = API\ShippoSDK::builder()
    ->setShippoApiVersion('2018-02-08')
    ->setSecurity($security)->build();

try {
        $request = new Operations\ListShipmentRatesByCurrencyCodeRequest();
    $request->shipmentId = '<value>';
    $request->currencyCode = '<value>';
    $request->page = 129833;
    $request->results = 866327;;

    $response = $sdk->rates->listShipmentRatesByCurrencyCode($request);

    if ($response->ratePaginatedList !== null) {
        // handle response
    }
} catch (Throwable $e) {
    // handle exception
}

Parameters

Parameter Type Required Description
$request \Shippo\API\Models\Operations\ListShipmentRatesByCurrencyCodeRequest ✔️ The request object to use for the request.

Response

?\Shippo\API\Models\Operations\ListShipmentRatesByCurrencyCodeResponse