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) Add order to a ShippingEasy accountAdds an order to a ShippingEasy account (calls the ShippingEasy REST API).
#import <CkoJsonObject.h> #import <NSString.h> #import <CkoStringBuilder.h> #import <CkoDateTime.h> #import <CkoCrypt2.h> #import <CkoHttp.h> #import <CkoHttpResponse.h> // This requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. BOOL success; // First create the JSON for the order. // See https://shippingeasy.readme.io/v1.0/docs/creating-a-signature // for sample JSON. // You may use the online tool at https://tools.chilkat.io/Default.cshtml to // generate the following code by pasting sample JSON into the tool. CkoJsonObject *json = [[CkoJsonObject alloc] init]; [json UpdateString: @"order.external_order_identifier" value: @"ABC-100"]; [json UpdateString: @"order.ordered_at" value: @"2014-01-16 14:37:56 -0600"]; [json UpdateString: @"order.order_status" value: @"awaiting_shipment"]; [json UpdateString: @"order.subtotal_including_tax" value: @"10.00"]; [json UpdateString: @"order.total_including_tax" value: @"10.00"]; [json UpdateString: @"order.total_excluding_tax" value: @"10.00"]; [json UpdateString: @"order.discount_amount" value: @"0.00"]; [json UpdateString: @"order.coupon_discount" value: @"1.00"]; [json UpdateString: @"order.subtotal_including_tax" value: @"0.00"]; [json UpdateString: @"order.subtotal_excluding_tax" value: @"0.00"]; [json UpdateString: @"order.subtotal_excluding_tax" value: @"0.00"]; [json UpdateString: @"order.subtotal_tax" value: @"0.00"]; [json UpdateString: @"order.total_tax" value: @"0"]; [json UpdateString: @"order.base_shipping_cost" value: @"0.00"]; [json UpdateString: @"order.shipping_cost_including_tax" value: @"0.00"]; [json UpdateString: @"order.shipping_cost_excluding_tax" value: @"0.00"]; [json UpdateString: @"order.shipping_cost_tax" value: @"0.00"]; [json UpdateString: @"order.base_handling_cost" value: @"0.00"]; [json UpdateString: @"order.handling_cost_excluding_tax" value: @"0.00"]; [json UpdateString: @"order.handling_cost_including_tax" value: @"0.00"]; [json UpdateString: @"order.handling_cost_tax" value: @"0.00"]; [json UpdateString: @"order.base_wrapping_cost" value: @"0.00"]; [json UpdateString: @"order.wrapping_cost_excluding_tax" value: @"0.00"]; [json UpdateString: @"order.wrapping_cost_including_tax" value: @"0.00"]; [json UpdateString: @"order.wrapping_cost_tax" value: @"0.00"]; [json UpdateString: @"order.notes" value: @"Please send promptly."]; [json UpdateString: @"order.billing_company" value: @"Acme Inc."]; [json UpdateString: @"order.billing_first_name" value: @"Fred"]; [json UpdateString: @"order.billing_last_name" value: @"Jones"]; [json UpdateString: @"order.billing_address" value: @"1234 Street"]; [json UpdateString: @"order.billing_address2" value: @"Suite 100"]; [json UpdateString: @"order.billing_city" value: @"Austin"]; [json UpdateString: @"order.billing_state" value: @"TX"]; [json UpdateString: @"order.billing_postal_code" value: @"78701"]; [json UpdateString: @"order.billing_country" value: @"USA"]; [json UpdateString: @"order.billing_phone_number" value: @"512-123-1234"]; [json UpdateString: @"order.billing_email" value: @"test@test.com"]; [json UpdateString: @"order.recipients[0].first_name" value: @"Colin"]; [json UpdateString: @"order.recipients[0].last_name" value: @"Homenick"]; [json UpdateString: @"order.recipients[0].company" value: @"Wintheiser-Hickle"]; [json UpdateString: @"order.recipients[0].email" value: @"charles.crona@okeefe.org"]; [json UpdateString: @"order.recipients[0].phone_number" value: @"637-481-6505"]; [json UpdateString: @"order.recipients[0].residential" value: @"true"]; [json UpdateString: @"order.recipients[0].address" value: @"21937 Adelbert Springs"]; [json UpdateString: @"order.recipients[0].address2" value: @""]; [json UpdateString: @"order.recipients[0].province" value: @""]; [json UpdateString: @"order.recipients[0].state" value: @"CT"]; [json UpdateString: @"order.recipients[0].city" value: @"Terryfurt"]; [json UpdateString: @"order.recipients[0].postal_code" value: @"93322"]; [json UpdateString: @"order.recipients[0].postal_code_plus_4" value: @"1234"]; [json UpdateString: @"order.recipients[0].country" value: @"Andorra"]; [json UpdateString: @"order.recipients[0].shipping_method" value: @"Ground"]; [json UpdateString: @"order.recipients[0].base_cost" value: @"10.00"]; [json UpdateString: @"order.recipients[0].cost_excluding_tax" value: @"10.00"]; [json UpdateString: @"order.recipients[0].cost_tax" value: @"0.00"]; [json UpdateString: @"order.recipients[0].base_handling_cost" value: @"0.00"]; [json UpdateString: @"order.recipients[0].handling_cost_excluding_tax" value: @"0.00"]; [json UpdateString: @"order.recipients[0].handling_cost_including_tax" value: @"0.00"]; [json UpdateString: @"order.recipients[0].handling_cost_tax" value: @"0.00"]; [json UpdateString: @"order.recipients[0].shipping_zone_id" value: @"123"]; [json UpdateString: @"order.recipients[0].shipping_zone_name" value: @"XYZ"]; [json UpdateString: @"order.recipients[0].items_total" value: @"1"]; [json UpdateString: @"order.recipients[0].items_shipped" value: @"0"]; [json UpdateString: @"order.recipients[0].line_items[0].item_name" value: @"Pencil Holder"]; [json UpdateString: @"order.recipients[0].line_items[0].sku" value: @"9876543"]; [json UpdateString: @"order.recipients[0].line_items[0].bin_picking_number" value: @"7"]; [json UpdateString: @"order.recipients[0].line_items[0].unit_price" value: @"1.30"]; [json UpdateString: @"order.recipients[0].line_items[0].total_excluding_tax" value: @"1.30"]; [json UpdateString: @"order.recipients[0].line_items[0].weight_in_ounces" value: @"10"]; [json UpdateString: @"order.recipients[0].line_items[0].product_options.pa_size" value: @"large"]; [json UpdateString: @"order.recipients[0].line_items[0].product_options.Colour" value: @"Blue"]; [json UpdateString: @"order.recipients[0].line_items[0].quantity" value: @"1"]; // Replace these values with your actual apiKey and apiSecret. // (These are not valid values..) NSString *storeApiKey = @"569dc30d267f2c4d1f85f9920b2bf9f4"; NSString *apiKey = @"f9a7c8ebdfd34beaf260d9b0296c7059"; NSString *apiSecret = @"d3e9f8737d7196b1271a725f89e2156672bc1d900a25e6e0c1364e2f7a20f605"; // Our request will be sent to: // https://app.shippingeasy.com/api/stores/:store_api_key/orders // The path part of this request is: /api/stores/:store_api_key/orders // See https://shippingeasy.readme.io/v1.0/docs/authentication-signing-requests CkoStringBuilder *sbSigStr = [[CkoStringBuilder alloc] init]; [sbSigStr Append: @"POST&/api/stores/"]; [sbSigStr Append: storeApiKey]; [sbSigStr Append: @"/orders&"]; [sbSigStr Append: @"api_key="]; [sbSigStr Append: apiKey]; [sbSigStr Append: @"&api_timestamp="]; CkoDateTime *dt = [[CkoDateTime alloc] init]; [dt SetFromCurrentSystemTime]; [sbSigStr Append: [dt GetAsUnixTimeStr: NO]]; [sbSigStr Append: @"&"]; json.EmitCompact = YES; [json EmitSb: sbSigStr]; // Calculate the HMAC-SHA256 of the API Signature String using the API Secret as the HMAC key. CkoCrypt2 *crypt = [[CkoCrypt2 alloc] init]; crypt.MacAlgorithm = @"hmac"; crypt.EncodingMode = @"hex"; [crypt SetMacKeyString: apiSecret]; crypt.HashAlgorithm = @"sha256"; CkoStringBuilder *sbSignature = [[CkoStringBuilder alloc] init]; [sbSignature Append: [crypt MacStringENC: [sbSigStr GetAsString]]]; [sbSignature ToLowercase]; CkoStringBuilder *sbUrl = [[CkoStringBuilder alloc] init]; [sbUrl Append: @"https://app.shippingeasy.com/api/stores/"]; [sbUrl Append: storeApiKey]; [sbUrl Append: @"/orders?"]; [sbUrl Append: @"api_key="]; [sbUrl Append: apiKey]; [sbUrl Append: @"&api_timestamp="]; [sbUrl Append: [dt GetAsUnixTimeStr: NO]]; [sbUrl Append: @"&api_signature="]; [sbUrl Append: [sbSignature GetAsString]]; // Send a POST equivalent the following curl request: // curl -H "Content-Type: application/json" --data @body.json "https://app.shippingeasy.com/api/stores/27aa472e16faa83dd13b7758d31974ed/orders? // api_key=f9a7c8ebdfd34beaf260d9b0296c7059& // api_timestamp=1401803554& // api_signature=c65f43beed46e581939898a78acd10064cfa146845e97885ec02124d7ad648e4" CkoHttp *http = [[CkoHttp alloc] init]; http.SessionLogFilename = @"qa_output/shippingEasy.txt"; CkoHttpResponse *resp = [http PostJson2: [sbUrl GetAsString] contentType: @"application/json" jsonText: [json Emit]]; if (http.LastMethodSuccess != YES) { NSLog(@"%@",http.LastErrorText); return; } NSLog(@"%@%d",@"response status code = ",[resp.StatusCode intValue]); NSLog(@"%@",@"response body:"); NSLog(@"%@",resp.BodyStr); |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.