Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Objective-C) Shippo Create Shipment ObjectCreate a Shipment object to retrieve rates. It represents a request to ship a given package from the sender to the recipient address. For more information, see https://goshippo.com/docs/shipping-labels/
#import <CkoHttp.h> #import <CkoJsonObject.h> #import <CkoHttpResponse.h> #import <CkoStringBuilder.h> #import <NSString.h> // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkoHttp *http = [[CkoHttp alloc] init]; BOOL success; // Implements the following CURL command: // curl https://api.goshippo.com/shipments/ \ // -H "Authorization: ShippoToken <API_TOKEN>" \ // -H "Content-Type: application/json" \ // -d '{ // "address_from":{ // "name":"Mr. Hippo", // "street1":"215 Clayton St.", // "city":"San Francisco", // "state":"CA", // "zip":"94117", // "country":"US" // }, // "address_to":{ // "name":"Mrs. Hippo", // "street1":"965 Mission St.", // "city":"San Francisco", // "state":"CA", // "zip":"94105", // "country":"US" // }, // "parcels":[{ // "length":"5", // "width":"5", // "height":"5", // "distance_unit":"in", // "weight":"2", // "mass_unit":"lb" // }], // "async": false // }' // Use this online tool to generate code from sample JSON: // Generate Code to Create JSON // The following JSON is sent in the request body. // { // "address_from": { // "name": "Mr. Hippo", // "street1": "215 Clayton St.", // "city": "San Francisco", // "state": "CA", // "zip": "94117", // "country": "US" // }, // "address_to": { // "name": "Mrs. Hippo", // "street1": "965 Mission St.", // "city": "San Francisco", // "state": "CA", // "zip": "94105", // "country": "US" // }, // "parcels": [ // { // "length": "5", // "width": "5", // "height": "5", // "distance_unit": "in", // "weight": "2", // "mass_unit": "lb" // } // ], // "async": false // } CkoJsonObject *json = [[CkoJsonObject alloc] init]; [json UpdateString: @"address_from.name" value: @"Mr. Hippo"]; [json UpdateString: @"address_from.street1" value: @"215 Clayton St."]; [json UpdateString: @"address_from.city" value: @"San Francisco"]; [json UpdateString: @"address_from.state" value: @"CA"]; [json UpdateString: @"address_from.zip" value: @"94117"]; [json UpdateString: @"address_from.country" value: @"US"]; [json UpdateString: @"address_to.name" value: @"Mrs. Hippo"]; [json UpdateString: @"address_to.street1" value: @"965 Mission St."]; [json UpdateString: @"address_to.city" value: @"San Francisco"]; [json UpdateString: @"address_to.state" value: @"CA"]; [json UpdateString: @"address_to.zip" value: @"94105"]; [json UpdateString: @"address_to.country" value: @"US"]; [json UpdateString: @"parcels[0].length" value: @"5"]; [json UpdateString: @"parcels[0].width" value: @"5"]; [json UpdateString: @"parcels[0].height" value: @"5"]; [json UpdateString: @"parcels[0].distance_unit" value: @"in"]; [json UpdateString: @"parcels[0].weight" value: @"2"]; [json UpdateString: @"parcels[0].mass_unit" value: @"lb"]; [json UpdateBool: @"async" value: NO]; [http SetRequestHeader: @"Authorization" value: @"ShippoToken <API_TOKEN>"]; [http SetRequestHeader: @"Content-Type" value: @"application/json"]; CkoHttpResponse *resp = [http PostJson3: @"https://api.goshippo.com/shipments/" contentType: @"application/json" json: json]; if (http.LastMethodSuccess == NO) { NSLog(@"%@",http.LastErrorText); return; } CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init]; [resp GetBodySb: sbResponseBody]; CkoJsonObject *jResp = [[CkoJsonObject alloc] init]; [jResp LoadSb: sbResponseBody]; jResp.EmitCompact = NO; NSLog(@"%@",@"Response Body:"); NSLog(@"%@",[jResp Emit]); int respStatusCode = [resp.StatusCode intValue]; NSLog(@"%@%d",@"Response Status Code = ",respStatusCode); if (respStatusCode >= 400) { NSLog(@"%@",@"Response Header:"); NSLog(@"%@",resp.Header); NSLog(@"%@",@"Failed."); return; } // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "carrier_accounts": [ // ], // "object_created": "2019-06-28T17:45:20.441Z", // "object_updated": "2019-06-28T17:45:20.511Z", // "object_id": "17b01795a4884d8a9002ccc17c9d09d1", // "object_owner": "admin@chilkatsoft.com", // "status": "SUCCESS", // "address_from": { // "object_id": "427489906b604f498f7bd2429ab7d9a1", // "is_complete": true, // "name": "Mr. Hippo", // "company": "", // "street_no": "", // "street1": "215 Clayton St.", // "validation_results": {}, // "street2": "", // "street3": "", // "city": "San Francisco", // "state": "CA", // "zip": "94117", // "country": "US", // "phone": "", // "email": "", // "is_residential": null, // "test": true // }, // "address_to": { // "object_id": "3d7166269a2844b7842ef9ace942ec7c", // "is_complete": true, // "name": "Mrs. Hippo", // "company": "", // "street_no": "", // "street1": "965 Mission St.", // "validation_results": {}, // "street2": "", // "street3": "", // "city": "San Francisco", // "state": "CA", // "zip": "94105", // "country": "US", // "phone": "", // "email": "", // "is_residential": null, // "test": true // }, // "parcels": [ // { // "object_state": "VALID", // "object_created": "2019-06-28T17:45:20.411Z", // "object_updated": "2019-06-28T17:45:20.455Z", // "object_id": "5af766ff15684a4186b0e3c833348fac", // "object_owner": "admin@chilkatsoft.com", // "template": null, // "extra": {}, // "length": "5.0000", // "width": "5.0000", // "height": "5.0000", // "distance_unit": "in", // "weight": "2.0000", // "mass_unit": "lb", // "value_amount": null, // "value_currency": null, // "metadata": "", // "line_items": [ // ], // "test": true // } // ], // "shipment_date": "2019-06-28T17:45:20.511Z", // "address_return": { // "object_id": "427489906b604f498f7bd2429ab7d9a1", // "is_complete": true, // "name": "Mr. Hippo", // "company": "", // "street_no": "", // "street1": "215 Clayton St.", // "validation_results": {}, // "street2": "", // "street3": "", // "city": "San Francisco", // "state": "CA", // "zip": "94117", // "country": "US", // "phone": "", // "email": "", // "is_residential": null, // "test": true // }, // "alternate_address_to": null, // "customs_declaration": null, // "extra": {}, // "rates": [ // { // "object_created": "2019-06-28T17:45:20.789Z", // "object_id": "dd7556c284e8444294d2ab7099e662d2", // "object_owner": "admin@chilkatsoft.com", // "shipment": "17b01795a4884d8a9002ccc17c9d09d1", // "attributes": [ // "FASTEST" // ], // "amount": "22.78", // "currency": "USD", // "amount_local": "22.78", // "currency_local": "USD", // "provider": "USPS", // "provider_image_75": "https://shippo-static.s3.amazonaws.com/providers/75/USPS.png", // "provider_image_200": "https://shippo-static.s3.amazonaws.com/providers/200/USPS.png", // "servicelevel": { // "name": "Priority Mail Express", // "token": "usps_priority_express", // "terms": "" // }, // "estimated_days": 2, // "arrives_by": null, // "duration_terms": "Overnight delivery to most U.S. locations.", // "messages": [ // ], // "carrier_account": "1f3dc340ad6c4991ad61f14fa3e4b82e", // "test": true, // "zone": "1" // }, // { // "object_created": "2019-06-28T17:45:20.786Z", // "object_id": "ec11cc297e2f4583986097f6d409e5c6", // "object_owner": "admin@chilkatsoft.com", // "shipment": "17b01795a4884d8a9002ccc17c9d09d1", // "attributes": [ // "BESTVALUE", // "CHEAPEST", // "FASTEST" // ], // "amount": "6.95", // "currency": "USD", // "amount_local": "6.95", // "currency_local": "USD", // "provider": "USPS", // "provider_image_75": "https://shippo-static.s3.amazonaws.com/providers/75/USPS.png", // "provider_image_200": "https://shippo-static.s3.amazonaws.com/providers/200/USPS.png", // "servicelevel": { // "name": "Priority Mail", // "token": "usps_priority", // "terms": "" // }, // "estimated_days": 2, // "arrives_by": null, // "duration_terms": "Delivery within 1, 2, or 3 days based on where your package started and where it’s being sent.", // "messages": [ // ], // "carrier_account": "1f3dc340ad6c4991ad61f14fa3e4b82e", // "test": true, // "zone": "1" // }, // { // "object_created": "2019-06-28T17:45:20.785Z", // "object_id": "d256586f539f4c93a2f02cc11f4942ac", // "object_owner": "admin@chilkatsoft.com", // "shipment": "17b01795a4884d8a9002ccc17c9d09d1", // "attributes": [ // ], // "amount": "7.32", // "currency": "USD", // "amount_local": "7.32", // "currency_local": "USD", // "provider": "USPS", // "provider_image_75": "https://shippo-static.s3.amazonaws.com/providers/75/USPS.png", // "provider_image_200": "https://shippo-static.s3.amazonaws.com/providers/200/USPS.png", // "servicelevel": { // "name": "Parcel Select", // "token": "usps_parcel_select", // "terms": "" // }, // "estimated_days": 7, // "arrives_by": null, // "duration_terms": "Delivery in 2 to 8 days.", // "messages": [ // ], // "carrier_account": "1f3dc340ad6c4991ad61f14fa3e4b82e", // "test": true, // "zone": "1" // } // ], // "messages": [ // { // "source": "DHLExpress", // "code": "", // "text": "Shippo's DHL Express master account doesn't support shipments to inside of the US" // } // ], // "metadata": "", // "test": true, // "order": null // } // Sample code for parsing the JSON response... // Use the following online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON NSString *object_state = 0; NSString *template = 0; NSString *length = 0; NSString *width = 0; NSString *height = 0; NSString *distance_unit = 0; NSString *weight = 0; NSString *mass_unit = 0; NSString *value_amount = 0; NSString *value_currency = 0; int j; int count_j; NSString *shipment = 0; NSString *amount = 0; NSString *currency = 0; NSString *amount_local = 0; NSString *currency_local = 0; NSString *provider = 0; NSString *provider_image_75 = 0; NSString *provider_image_200 = 0; NSString *servicelevelName = 0; NSString *servicelevelToken = 0; NSString *servicelevelTerms = 0; int estimated_days; NSString *arrives_by = 0; NSString *duration_terms = 0; NSString *carrier_account = 0; NSString *zone = 0; NSString *strVal = 0; NSString *source = 0; NSString *code = 0; NSString *text = 0; NSString *object_created = [jResp StringOf: @"object_created"]; NSString *object_updated = [jResp StringOf: @"object_updated"]; NSString *object_id = [jResp StringOf: @"object_id"]; NSString *object_owner = [jResp StringOf: @"object_owner"]; NSString *status = [jResp StringOf: @"status"]; NSString *address_fromObject_id = [jResp StringOf: @"address_from.object_id"]; BOOL address_fromIs_complete = [jResp BoolOf: @"address_from.is_complete"]; NSString *address_fromName = [jResp StringOf: @"address_from.name"]; NSString *address_fromCompany = [jResp StringOf: @"address_from.company"]; NSString *address_fromStreet_no = [jResp StringOf: @"address_from.street_no"]; NSString *address_fromStreet1 = [jResp StringOf: @"address_from.street1"]; NSString *address_fromStreet2 = [jResp StringOf: @"address_from.street2"]; NSString *address_fromStreet3 = [jResp StringOf: @"address_from.street3"]; NSString *address_fromCity = [jResp StringOf: @"address_from.city"]; NSString *address_fromState = [jResp StringOf: @"address_from.state"]; NSString *address_fromZip = [jResp StringOf: @"address_from.zip"]; NSString *address_fromCountry = [jResp StringOf: @"address_from.country"]; NSString *address_fromPhone = [jResp StringOf: @"address_from.phone"]; NSString *address_fromEmail = [jResp StringOf: @"address_from.email"]; NSString *address_fromIs_residential = [jResp StringOf: @"address_from.is_residential"]; BOOL address_fromTest = [jResp BoolOf: @"address_from.test"]; NSString *address_toObject_id = [jResp StringOf: @"address_to.object_id"]; BOOL address_toIs_complete = [jResp BoolOf: @"address_to.is_complete"]; NSString *address_toName = [jResp StringOf: @"address_to.name"]; NSString *address_toCompany = [jResp StringOf: @"address_to.company"]; NSString *address_toStreet_no = [jResp StringOf: @"address_to.street_no"]; NSString *address_toStreet1 = [jResp StringOf: @"address_to.street1"]; NSString *address_toStreet2 = [jResp StringOf: @"address_to.street2"]; NSString *address_toStreet3 = [jResp StringOf: @"address_to.street3"]; NSString *address_toCity = [jResp StringOf: @"address_to.city"]; NSString *address_toState = [jResp StringOf: @"address_to.state"]; NSString *address_toZip = [jResp StringOf: @"address_to.zip"]; NSString *address_toCountry = [jResp StringOf: @"address_to.country"]; NSString *address_toPhone = [jResp StringOf: @"address_to.phone"]; NSString *address_toEmail = [jResp StringOf: @"address_to.email"]; NSString *address_toIs_residential = [jResp StringOf: @"address_to.is_residential"]; BOOL address_toTest = [jResp BoolOf: @"address_to.test"]; NSString *shipment_date = [jResp StringOf: @"shipment_date"]; NSString *address_returnObject_id = [jResp StringOf: @"address_return.object_id"]; BOOL address_returnIs_complete = [jResp BoolOf: @"address_return.is_complete"]; NSString *address_returnName = [jResp StringOf: @"address_return.name"]; NSString *address_returnCompany = [jResp StringOf: @"address_return.company"]; NSString *address_returnStreet_no = [jResp StringOf: @"address_return.street_no"]; NSString *address_returnStreet1 = [jResp StringOf: @"address_return.street1"]; NSString *address_returnStreet2 = [jResp StringOf: @"address_return.street2"]; NSString *address_returnStreet3 = [jResp StringOf: @"address_return.street3"]; NSString *address_returnCity = [jResp StringOf: @"address_return.city"]; NSString *address_returnState = [jResp StringOf: @"address_return.state"]; NSString *address_returnZip = [jResp StringOf: @"address_return.zip"]; NSString *address_returnCountry = [jResp StringOf: @"address_return.country"]; NSString *address_returnPhone = [jResp StringOf: @"address_return.phone"]; NSString *address_returnEmail = [jResp StringOf: @"address_return.email"]; NSString *address_returnIs_residential = [jResp StringOf: @"address_return.is_residential"]; BOOL address_returnTest = [jResp BoolOf: @"address_return.test"]; NSString *alternate_address_to = [jResp StringOf: @"alternate_address_to"]; NSString *customs_declaration = [jResp StringOf: @"customs_declaration"]; NSString *metadata = [jResp StringOf: @"metadata"]; BOOL test = [jResp BoolOf: @"test"]; NSString *order = [jResp StringOf: @"order"]; int i = 0; int count_i = [[jResp SizeOfArray: @"carrier_accounts"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; i = i + 1; } i = 0; count_i = [[jResp SizeOfArray: @"parcels"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; object_state = [jResp StringOf: @"parcels[i].object_state"]; object_created = [jResp StringOf: @"parcels[i].object_created"]; object_updated = [jResp StringOf: @"parcels[i].object_updated"]; object_id = [jResp StringOf: @"parcels[i].object_id"]; object_owner = [jResp StringOf: @"parcels[i].object_owner"]; template = [jResp StringOf: @"parcels[i].template"]; length = [jResp StringOf: @"parcels[i].length"]; width = [jResp StringOf: @"parcels[i].width"]; height = [jResp StringOf: @"parcels[i].height"]; distance_unit = [jResp StringOf: @"parcels[i].distance_unit"]; weight = [jResp StringOf: @"parcels[i].weight"]; mass_unit = [jResp StringOf: @"parcels[i].mass_unit"]; value_amount = [jResp StringOf: @"parcels[i].value_amount"]; value_currency = [jResp StringOf: @"parcels[i].value_currency"]; metadata = [jResp StringOf: @"parcels[i].metadata"]; test = [jResp BoolOf: @"parcels[i].test"]; j = 0; count_j = [[jResp SizeOfArray: @"parcels[i].line_items"] intValue]; while (j < count_j) { jResp.J = [NSNumber numberWithInt: j]; j = j + 1; } i = i + 1; } i = 0; count_i = [[jResp SizeOfArray: @"rates"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; object_created = [jResp StringOf: @"rates[i].object_created"]; object_id = [jResp StringOf: @"rates[i].object_id"]; object_owner = [jResp StringOf: @"rates[i].object_owner"]; shipment = [jResp StringOf: @"rates[i].shipment"]; amount = [jResp StringOf: @"rates[i].amount"]; currency = [jResp StringOf: @"rates[i].currency"]; amount_local = [jResp StringOf: @"rates[i].amount_local"]; currency_local = [jResp StringOf: @"rates[i].currency_local"]; provider = [jResp StringOf: @"rates[i].provider"]; provider_image_75 = [jResp StringOf: @"rates[i].provider_image_75"]; provider_image_200 = [jResp StringOf: @"rates[i].provider_image_200"]; servicelevelName = [jResp StringOf: @"rates[i].servicelevel.name"]; servicelevelToken = [jResp StringOf: @"rates[i].servicelevel.token"]; servicelevelTerms = [jResp StringOf: @"rates[i].servicelevel.terms"]; estimated_days = [[jResp IntOf: @"rates[i].estimated_days"] intValue]; arrives_by = [jResp StringOf: @"rates[i].arrives_by"]; duration_terms = [jResp StringOf: @"rates[i].duration_terms"]; carrier_account = [jResp StringOf: @"rates[i].carrier_account"]; test = [jResp BoolOf: @"rates[i].test"]; zone = [jResp StringOf: @"rates[i].zone"]; j = 0; count_j = [[jResp SizeOfArray: @"rates[i].attributes"] intValue]; while (j < count_j) { jResp.J = [NSNumber numberWithInt: j]; strVal = [jResp StringOf: @"rates[i].attributes[j]"]; j = j + 1; } j = 0; count_j = [[jResp SizeOfArray: @"rates[i].messages"] intValue]; while (j < count_j) { jResp.J = [NSNumber numberWithInt: j]; j = j + 1; } i = i + 1; } i = 0; count_i = [[jResp SizeOfArray: @"messages"] intValue]; while (i < count_i) { jResp.I = [NSNumber numberWithInt: i]; source = [jResp StringOf: @"messages[i].source"]; code = [jResp StringOf: @"messages[i].code"]; text = [jResp StringOf: @"messages[i].text"]; i = i + 1; } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.