|
| 1 | +Create Label From Rate |
| 2 | +====================================== |
| 3 | +When retrieving rates for shipments using the `getRatesWithShipmentDetails` method, the returned information contains a `rateId` property that can be used to purchase a label without having to refill in the shipment information repeatedly. Please see [our docs](https://www.shipengine.com/docs/labels/create-from-rate/) to learn more about creating shipping labels from rates. |
| 4 | + |
| 5 | +Input Parameters |
| 6 | +------------------------------------- |
| 7 | + |
| 8 | +The `createLabelFromRate` method requires a `rateId` and label params as seen in the documentation above. |
| 9 | + |
| 10 | +Output |
| 11 | +-------------------------------- |
| 12 | +The `createLabelFromRate` method returns the label that was created. |
| 13 | + |
| 14 | +Example |
| 15 | +```php |
| 16 | +use ShipEngine\ShipEngine; |
| 17 | +use ShipEngine\Message\ShipEngineException; |
| 18 | + |
| 19 | +function createLabelFromRateDemoFunction() { |
| 20 | + $client = new ShipEngine('API-Key'); |
| 21 | + |
| 22 | + $params = [ |
| 23 | + "validate_address" => "no_validation", |
| 24 | + "label_layout" => "4x6", |
| 25 | + "label_format" => "pdf", |
| 26 | + "label_download_type" => "url", |
| 27 | + "display_scheme" => "label" |
| 28 | + ]; |
| 29 | + |
| 30 | + try { |
| 31 | + print_r($client-> createLabelFromRate('se-797094871', $params)); |
| 32 | + } catch (ShipEngineException $e) { |
| 33 | + print_r($e -> getMessage()); |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +createLabelFromRateDemoFunction(); |
| 38 | + |
| 39 | +``` |
| 40 | + |
| 41 | +Example Output |
| 42 | +----------------------------------------------------- |
| 43 | + |
| 44 | +### Successful Create Label From Rate Result |
| 45 | +```php |
| 46 | +Array |
| 47 | +( |
| 48 | + [label_id] => se-75484277 |
| 49 | + [status] => completed |
| 50 | + [shipment_id] => se-144316600 |
| 51 | + [ship_date] => 2021-08-04T00:00:00Z |
| 52 | + [created_at] => 2021-08-04T17:29:10.3686928Z |
| 53 | + [shipment_cost] => Array |
| 54 | + ( |
| 55 | + [currency] => usd |
| 56 | + [amount] => 11.63 |
| 57 | + ) |
| 58 | + |
| 59 | + [insurance_cost] => Array |
| 60 | + ( |
| 61 | + [currency] => usd |
| 62 | + [amount] => 0 |
| 63 | + ) |
| 64 | + |
| 65 | + [tracking_number] => 9405511899560334465315 |
| 66 | + [is_return_label] => |
| 67 | + [rma_number] => |
| 68 | + [is_international] => |
| 69 | + [batch_id] => |
| 70 | + [carrier_id] => se-423887 |
| 71 | + [service_code] => usps_priority_mail |
| 72 | + [package_code] => regional_rate_box_a |
| 73 | + [voided] => |
| 74 | + [voided_at] => |
| 75 | + [label_format] => pdf |
| 76 | + [display_scheme] => label |
| 77 | + [label_layout] => 4x6 |
| 78 | + [trackable] => 1 |
| 79 | + [label_image_id] => |
| 80 | + [carrier_code] => stamps_com |
| 81 | + [tracking_status] => in_transit |
| 82 | + [label_download] => Array |
| 83 | + ( |
| 84 | + [pdf] => https://api.shipengine.com/v1/downloads/10/I_F8RgnVBEGvt7ycgHHIGg/label-75484277.pdf |
| 85 | + [png] => https://api.shipengine.com/v1/downloads/10/I_F8RgnVBEGvt7ycgHHIGg/label-75484277.png |
| 86 | + [zpl] => https://api.shipengine.com/v1/downloads/10/I_F8RgnVBEGvt7ycgHHIGg/label-75484277.zpl |
| 87 | + [href] => https://api.shipengine.com/v1/downloads/10/I_F8RgnVBEGvt7ycgHHIGg/label-75484277.pdf |
| 88 | + ) |
| 89 | + |
| 90 | + [form_download] => |
| 91 | + [insurance_claim] => |
| 92 | + [packages] => Array |
| 93 | + ( |
| 94 | + [0] => Array |
| 95 | + ( |
| 96 | + [package_id] => 80105682 |
| 97 | + [package_code] => regional_rate_box_a |
| 98 | + [weight] => Array |
| 99 | + ( |
| 100 | + [value] => 1 |
| 101 | + [unit] => ounce |
| 102 | + ) |
| 103 | + |
| 104 | + [dimensions] => Array |
| 105 | + ( |
| 106 | + [unit] => inch |
| 107 | + [length] => 0 |
| 108 | + [width] => 0 |
| 109 | + [height] => 0 |
| 110 | + ) |
| 111 | + |
| 112 | + [insured_value] => Array |
| 113 | + ( |
| 114 | + [currency] => usd |
| 115 | + [amount] => 0 |
| 116 | + ) |
| 117 | + |
| 118 | + [tracking_number] => 9405511899560334465315 |
| 119 | + [label_messages] => Array |
| 120 | + ( |
| 121 | + [reference1] => |
| 122 | + [reference2] => |
| 123 | + [reference3] => |
| 124 | + ) |
| 125 | + |
| 126 | + [external_package_id] => |
| 127 | + [sequence] => 1 |
| 128 | + ) |
| 129 | + |
| 130 | + ) |
| 131 | + |
| 132 | + [charge_event] => carrier_default |
| 133 | +) |
| 134 | +``` |
0 commit comments