Create a parcel, including the weight, and either a predefined_package or length, width and height if applicable.
curl -X POST https://api.easypost.com/v2/parcels \
-u <YOUR_TEST/PRODUCTION_API_KEY>: \
-d 'parcel[length]=20.2' \
-d 'parcel[width]=10.9' \
-d 'parcel[height]=5' \
-d 'parcel[weight]=65.9'
var
rest: HCkRest;
success: Boolean;
bTls: Boolean;
port: Integer;
bAutoReconnect: Boolean;
strResponseBody: PWideChar;
jsonResponse: HCkJsonObject;
id: PWideChar;
object: PWideChar;
length: Integer;
width: Integer;
height: Integer;
predefined_package: Boolean;
weight: Integer;
created_at: PWideChar;
updated_at: PWideChar;
begin
rest := CkRest_Create();
// URL: https://api.easypost.com/v2/parcels
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>','');
CkRest_AddQueryParam(rest,'parcel[length]','20.2');
CkRest_AddQueryParam(rest,'parcel[width]','10.9');
CkRest_AddQueryParam(rest,'parcel[height]','5');
CkRest_AddQueryParam(rest,'parcel[weight]','65.9');
strResponseBody := CkRest__fullRequestFormUrlEncoded(rest,'POST','/v2/parcels');
if (CkRest_getLastMethodSuccess(rest) <> True) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
jsonResponse := CkJsonObject_Create();
CkJsonObject_Load(jsonResponse,strResponseBody);
id := CkJsonObject__stringOf(jsonResponse,'id');
object := CkJsonObject__stringOf(jsonResponse,'object');
length := CkJsonObject_IntOf(jsonResponse,'length');
width := CkJsonObject_IntOf(jsonResponse,'width');
height := CkJsonObject_IntOf(jsonResponse,'height');
predefined_package := CkJsonObject_IsNullOf(jsonResponse,'predefined_package');
weight := CkJsonObject_IntOf(jsonResponse,'weight');
created_at := CkJsonObject__stringOf(jsonResponse,'created_at');
updated_at := CkJsonObject__stringOf(jsonResponse,'updated_at');
CkRest_Dispose(rest);
CkJsonObject_Dispose(jsonResponse);
{
"id": "prcl_WDv2VzHp",
"object": "Parcel",
"length": 20.2,
"width": 10.9,
"height": 5.0,
"predefined_package": null,
"weight": 65.9,
"created_at": "2013-04-22T05:40:57Z",
"updated_at": "2013-04-22T05:40:57Z"
}