Refund an EasyPost shipment
curl -X GET https://api.easypost.com/v2/shipments/shp_.../refund \
-u <YOUR_TEST/PRODUCTION_API_KEY>:
var
rest: HCkRest;
success: Boolean;
bTls: Boolean;
port: Integer;
bAutoReconnect: Boolean;
sbResponseBody: HCkStringBuilder;
jsonResponse: HCkJsonObject;
batch_message: Boolean;
batch_status: Boolean;
created_at: PWideChar;
customs_info: Boolean;
from_addressCity: PWideChar;
from_addressCompany: Boolean;
from_addressCountry: PWideChar;
from_addressCreated_at: PWideChar;
from_addressEmail: Boolean;
from_addressId: PWideChar;
from_addressMode: PWideChar;
from_addressName: PWideChar;
from_addressObject: PWideChar;
from_addressPhone: PWideChar;
from_addressState: PWideChar;
from_addressStreet1: PWideChar;
from_addressStreet2: PWideChar;
from_addressUpdated_at: PWideChar;
from_addressZip: PWideChar;
id: PWideChar;
insurance: Boolean;
is_return: Boolean;
mode: PWideChar;
object: PWideChar;
parcelCreated_at: PWideChar;
parcelHeight: Boolean;
parcelId: PWideChar;
parcelLength: Boolean;
parcelMode: PWideChar;
parcelObject: PWideChar;
parcelPredefined_package: PWideChar;
parcelUpdated_at: PWideChar;
parcelWeight: Integer;
parcelWidth: Boolean;
postage_labelCreated_at: PWideChar;
postage_labelId: PWideChar;
postage_labelIntegrated_form: PWideChar;
postage_labelLabel_date: PWideChar;
postage_labelLabel_epl2_url: Boolean;
postage_labelLabel_file_type: PWideChar;
postage_labelLabel_pdf_url: PWideChar;
postage_labelLabel_resolution: Integer;
postage_labelLabel_size: PWideChar;
postage_labelLabel_type: PWideChar;
postage_labelLabel_url: PWideChar;
postage_labelLabel_zpl_url: PWideChar;
postage_labelObject: PWideChar;
postage_labelUpdated_at: PWideChar;
reference: Boolean;
refund_status: PWideChar;
scan_form: Boolean;
selected_rateCarrier: PWideChar;
selected_rateCreated_at: PWideChar;
selected_rateCurrency: PWideChar;
selected_rateId: PWideChar;
selected_rateObject: PWideChar;
selected_rateRate: PWideChar;
selected_rateService: PWideChar;
selected_rateShipment_id: PWideChar;
selected_rateUpdated_at: PWideChar;
status: PWideChar;
to_addressCity: PWideChar;
to_addressCompany: Boolean;
to_addressCountry: PWideChar;
to_addressCreated_at: PWideChar;
to_addressEmail: PWideChar;
to_addressId: PWideChar;
to_addressMode: PWideChar;
to_addressName: PWideChar;
to_addressObject: PWideChar;
to_addressPhone: Boolean;
to_addressState: PWideChar;
to_addressStreet1: PWideChar;
to_addressStreet2: Boolean;
to_addressUpdated_at: PWideChar;
to_addressZip: PWideChar;
trackerCreated_at: PWideChar;
trackerId: PWideChar;
trackerMode: PWideChar;
trackerObject: PWideChar;
trackerShipment_id: PWideChar;
trackerStatus: PWideChar;
trackerTracking_code: PWideChar;
trackerUpdated_at: PWideChar;
trackerPublic_url: PWideChar;
tracking_code: PWideChar;
updated_at: PWideChar;
i: Integer;
count_i: Integer;
carrier: PWideChar;
currency: PWideChar;
rate: PWideChar;
service: PWideChar;
shipment_id: PWideChar;
begin
rest := CkRest_Create();
// URL: https://api.easypost.com/v2/shipments/shp_.../refund
bTls := True;
port := 443;
bAutoReconnect := True;
success := CkRest_Connect(rest,'api.easypost.com',port,bTls,bAutoReconnect);
if (success <> True) then
begin
Memo1.Lines.Add('ConnectFailReason: ' + IntToStr(CkRest_getConnectFailReason(rest)));
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
CkRest_SetAuthBasic(rest,'<YOUR_TEST/PRODUCTION_API_KEY>','');
sbResponseBody := CkStringBuilder_Create();
success := CkRest_FullRequestNoBodySb(rest,'GET','/v2/shipments/shp_.../refund',sbResponseBody);
if (success <> True) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
jsonResponse := CkJsonObject_Create();
CkJsonObject_LoadSb(jsonResponse,sbResponseBody);
batch_message := CkJsonObject_IsNullOf(jsonResponse,'batch_message');
batch_status := CkJsonObject_IsNullOf(jsonResponse,'batch_status');
created_at := CkJsonObject__stringOf(jsonResponse,'created_at');
customs_info := CkJsonObject_IsNullOf(jsonResponse,'customs_info');
from_addressCity := CkJsonObject__stringOf(jsonResponse,'from_address.city');
from_addressCompany := CkJsonObject_IsNullOf(jsonResponse,'from_address.company');
from_addressCountry := CkJsonObject__stringOf(jsonResponse,'from_address.country');
from_addressCreated_at := CkJsonObject__stringOf(jsonResponse,'from_address.created_at');
from_addressEmail := CkJsonObject_IsNullOf(jsonResponse,'from_address.email');
from_addressId := CkJsonObject__stringOf(jsonResponse,'from_address.id');
from_addressMode := CkJsonObject__stringOf(jsonResponse,'from_address.mode');
from_addressName := CkJsonObject__stringOf(jsonResponse,'from_address.name');
from_addressObject := CkJsonObject__stringOf(jsonResponse,'from_address.object');
from_addressPhone := CkJsonObject__stringOf(jsonResponse,'from_address.phone');
from_addressState := CkJsonObject__stringOf(jsonResponse,'from_address.state');
from_addressStreet1 := CkJsonObject__stringOf(jsonResponse,'from_address.street1');
from_addressStreet2 := CkJsonObject__stringOf(jsonResponse,'from_address.street2');
from_addressUpdated_at := CkJsonObject__stringOf(jsonResponse,'from_address.updated_at');
from_addressZip := CkJsonObject__stringOf(jsonResponse,'from_address.zip');
id := CkJsonObject__stringOf(jsonResponse,'id');
insurance := CkJsonObject_IsNullOf(jsonResponse,'insurance');
is_return := CkJsonObject_BoolOf(jsonResponse,'is_return');
mode := CkJsonObject__stringOf(jsonResponse,'mode');
object := CkJsonObject__stringOf(jsonResponse,'object');
parcelCreated_at := CkJsonObject__stringOf(jsonResponse,'parcel.created_at');
parcelHeight := CkJsonObject_IsNullOf(jsonResponse,'parcel.height');
parcelId := CkJsonObject__stringOf(jsonResponse,'parcel.id');
parcelLength := CkJsonObject_IsNullOf(jsonResponse,'parcel.length');
parcelMode := CkJsonObject__stringOf(jsonResponse,'parcel.mode');
parcelObject := CkJsonObject__stringOf(jsonResponse,'parcel.object');
parcelPredefined_package := CkJsonObject__stringOf(jsonResponse,'parcel.predefined_package');
parcelUpdated_at := CkJsonObject__stringOf(jsonResponse,'parcel.updated_at');
parcelWeight := CkJsonObject_IntOf(jsonResponse,'parcel.weight');
parcelWidth := CkJsonObject_IsNullOf(jsonResponse,'parcel.width');
postage_labelCreated_at := CkJsonObject__stringOf(jsonResponse,'postage_label.created_at');
postage_labelId := CkJsonObject__stringOf(jsonResponse,'postage_label.id');
postage_labelIntegrated_form := CkJsonObject__stringOf(jsonResponse,'postage_label.integrated_form');
postage_labelLabel_date := CkJsonObject__stringOf(jsonResponse,'postage_label.label_date');
postage_labelLabel_epl2_url := CkJsonObject_IsNullOf(jsonResponse,'postage_label.label_epl2_url');
postage_labelLabel_file_type := CkJsonObject__stringOf(jsonResponse,'postage_label.label_file_type');
postage_labelLabel_pdf_url := CkJsonObject__stringOf(jsonResponse,'postage_label.label_pdf_url');
postage_labelLabel_resolution := CkJsonObject_IntOf(jsonResponse,'postage_label.label_resolution');
postage_labelLabel_size := CkJsonObject__stringOf(jsonResponse,'postage_label.label_size');
postage_labelLabel_type := CkJsonObject__stringOf(jsonResponse,'postage_label.label_type');
postage_labelLabel_url := CkJsonObject__stringOf(jsonResponse,'postage_label.label_url');
postage_labelLabel_zpl_url := CkJsonObject__stringOf(jsonResponse,'postage_label.label_zpl_url');
postage_labelObject := CkJsonObject__stringOf(jsonResponse,'postage_label.object');
postage_labelUpdated_at := CkJsonObject__stringOf(jsonResponse,'postage_label.updated_at');
reference := CkJsonObject_IsNullOf(jsonResponse,'reference');
refund_status := CkJsonObject__stringOf(jsonResponse,'refund_status');
scan_form := CkJsonObject_IsNullOf(jsonResponse,'scan_form');
selected_rateCarrier := CkJsonObject__stringOf(jsonResponse,'selected_rate.carrier');
selected_rateCreated_at := CkJsonObject__stringOf(jsonResponse,'selected_rate.created_at');
selected_rateCurrency := CkJsonObject__stringOf(jsonResponse,'selected_rate.currency');
selected_rateId := CkJsonObject__stringOf(jsonResponse,'selected_rate.id');
selected_rateObject := CkJsonObject__stringOf(jsonResponse,'selected_rate.object');
selected_rateRate := CkJsonObject__stringOf(jsonResponse,'selected_rate.rate');
selected_rateService := CkJsonObject__stringOf(jsonResponse,'selected_rate.service');
selected_rateShipment_id := CkJsonObject__stringOf(jsonResponse,'selected_rate.shipment_id');
selected_rateUpdated_at := CkJsonObject__stringOf(jsonResponse,'selected_rate.updated_at');
status := CkJsonObject__stringOf(jsonResponse,'status');
to_addressCity := CkJsonObject__stringOf(jsonResponse,'to_address.city');
to_addressCompany := CkJsonObject_IsNullOf(jsonResponse,'to_address.company');
to_addressCountry := CkJsonObject__stringOf(jsonResponse,'to_address.country');
to_addressCreated_at := CkJsonObject__stringOf(jsonResponse,'to_address.created_at');
to_addressEmail := CkJsonObject__stringOf(jsonResponse,'to_address.email');
to_addressId := CkJsonObject__stringOf(jsonResponse,'to_address.id');
to_addressMode := CkJsonObject__stringOf(jsonResponse,'to_address.mode');
to_addressName := CkJsonObject__stringOf(jsonResponse,'to_address.name');
to_addressObject := CkJsonObject__stringOf(jsonResponse,'to_address.object');
to_addressPhone := CkJsonObject_IsNullOf(jsonResponse,'to_address.phone');
to_addressState := CkJsonObject__stringOf(jsonResponse,'to_address.state');
to_addressStreet1 := CkJsonObject__stringOf(jsonResponse,'to_address.street1');
to_addressStreet2 := CkJsonObject_IsNullOf(jsonResponse,'to_address.street2');
to_addressUpdated_at := CkJsonObject__stringOf(jsonResponse,'to_address.updated_at');
to_addressZip := CkJsonObject__stringOf(jsonResponse,'to_address.zip');
trackerCreated_at := CkJsonObject__stringOf(jsonResponse,'tracker.created_at');
trackerId := CkJsonObject__stringOf(jsonResponse,'tracker.id');
trackerMode := CkJsonObject__stringOf(jsonResponse,'tracker.mode');
trackerObject := CkJsonObject__stringOf(jsonResponse,'tracker.object');
trackerShipment_id := CkJsonObject__stringOf(jsonResponse,'tracker.shipment_id');
trackerStatus := CkJsonObject__stringOf(jsonResponse,'tracker.status');
trackerTracking_code := CkJsonObject__stringOf(jsonResponse,'tracker.tracking_code');
trackerUpdated_at := CkJsonObject__stringOf(jsonResponse,'tracker.updated_at');
trackerPublic_url := CkJsonObject__stringOf(jsonResponse,'tracker.public_url');
tracking_code := CkJsonObject__stringOf(jsonResponse,'tracking_code');
updated_at := CkJsonObject__stringOf(jsonResponse,'updated_at');
i := 0;
count_i := CkJsonObject_SizeOfArray(jsonResponse,'rates');
while i < count_i do
begin
CkJsonObject_putI(jsonResponse,i);
carrier := CkJsonObject__stringOf(jsonResponse,'rates[i].carrier');
created_at := CkJsonObject__stringOf(jsonResponse,'rates[i].created_at');
currency := CkJsonObject__stringOf(jsonResponse,'rates[i].currency');
id := CkJsonObject__stringOf(jsonResponse,'rates[i].id');
object := CkJsonObject__stringOf(jsonResponse,'rates[i].object');
rate := CkJsonObject__stringOf(jsonResponse,'rates[i].rate');
service := CkJsonObject__stringOf(jsonResponse,'rates[i].service');
shipment_id := CkJsonObject__stringOf(jsonResponse,'rates[i].shipment_id');
updated_at := CkJsonObject__stringOf(jsonResponse,'rates[i].updated_at');
i := i + 1;
end;
i := 0;
count_i := CkJsonObject_SizeOfArray(jsonResponse,'tracker.tracking_details');
while i < count_i do
begin
CkJsonObject_putI(jsonResponse,i);
i := i + 1;
end;
CkRest_Dispose(rest);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jsonResponse);
{
"batch_message": null,
"batch_status": null,
"created_at": "2013-11-08T15:50:00Z",
"customs_info": null,
"from_address": {
"city": "San Francisco",
"company": null,
"country": "US",
"created_at": "2013-11-08T15:49:59Z",
"email": null,
"id": "adr_faGeob9S",
"mode": "test",
"name": "EasyPost",
"object": "Address",
"phone": "415-379-7678",
"state": "CA",
"street1": "417 Montgomery Street",
"street2": "5th Floor",
"updated_at": "2013-11-08T15:49:59Z",
"zip": "94104"
},
"id": "shp_vN9h7XLn",
"insurance": null,
"is_return": false,
"mode": "test",
"object": "Shipment",
"parcel": {
"created_at": "2013-11-08T15:49:59Z",
"height": null,
"id": "prcl_TXCreKJp",
"length": null,
"mode": "test",
"object": "Parcel",
"predefined_package": "UPSLetter",
"updated_at": "2013-11-08T15:49:59Z",
"weight": 3.0,
"width": null
},
"postage_label": {
"created_at": "2013-11-08T20:57:32Z",
"id": "pl_2Np7asmw",
"integrated_form": "none",
"label_date": "2013-11-08T20:57:32Z",
"label_epl2_url": null,
"label_file_type": "image/png",
"label_pdf_url": "https://amazonaws.com/.../a1b2c3.pdf",
"label_resolution": 200,
"label_size": "4x7",
"label_type": "default",
"label_url": "https://amazonaws.com/.../a1b2c3.png",
"label_zpl_url": "https://amazonaws.com/.../a1b2c3.zpl",
"object": "PostageLabel",
"updated_at": "2013-11-08T21:11:14Z"
},
"rates": [
{
"carrier": "UPS",
"created_at": "2013-11-08T15:50:02Z",
"currency": "USD",
"id": "rate_vWwNuK8z",
"object": "Rate",
"rate": "30.44",
"service": "NextDayAir",
"shipment_id": "shp_w1xi76n4",
"updated_at": "2013-11-08T15:50:02Z"
},
{
"carrier": "UPS",
"created_at": "2013-11-08T15:50:02Z",
"currency": "USD",
"id": "rate_kqsS35Cx",
"object": "Rate",
"rate": "60.28",
"service": "NextDayAirEarlyAM",
"shipment_id": "shp_w1xi76n4",
"updated_at": "2013-11-08T15:50:02Z"
}
],
"reference": null,
"refund_status": "submitted",
"scan_form": null,
"selected_rate": {
"carrier": "UPS",
"created_at": "2013-11-08T15:50:02Z",
"currency": "USD",
"id": "rate_vWwNuK8z",
"object": "Rate",
"rate": "30.44",
"service": "NextDayAir",
"shipment_id": "shp_w1xi76n4",
"updated_at": "2013-11-08T15:50:02Z"
},
"status": "unknown",
"to_address": {
"city": "Redondo Beach",
"company": null,
"country": "US",
"created_at": "2013-11-08T15:49:58Z",
"email": "dr_steve_brule@gmail.com",
"id": "adr_EyDCpoii",
"mode": "test",
"name": "Dr. Steve Brule",
"object": "Address",
"phone": null,
"state": "CA",
"street1": "179 N Harbor Dr",
"street2": null,
"updated_at": "2013-11-08T15:49:58Z",
"zip": "90277"
},
"tracker": {
"created_at": "2013-11-08T20:57:32Z",
"id": "trk_k7oNSa1Q",
"mode": "test",
"object": "Tracker",
"shipment_id": "shp_w1xi76n4",
"status": "unknown",
"tracking_code": "1ZE6A4850190733810",
"tracking_details": [
],
"updated_at": "2013-11-08T20:58:26Z",
"public_url": "https://track.easypost.com/djE7..."
},
"tracking_code": "1ZE6A4850190733810",
"updated_at": "2013-11-08T20:58:26Z"
}