For non required fields, you can either omit from the JSON string or set it to a default value
(e.g. String = "", Integer/Double = 0, Boolean = false, DateTime = 1900-01-01T00:00:00.000Z)
{"auth": {"api_username": "", "api_password": "", "api_key": "", "company_no": 0, "username": "", "password": "", "timezone_offset": 0, "auth_type": "", "system_name": "", "system_company_no": 0 }, "order": {"notify": false, "order_coupon_no": 0, "payment_id": "", "purchase_order": "", "referrer": "", "customer_no": 0, "external_order_no": "", "order_shipping_no": 0, "payment_type": "", "session_id": "", "address_type": "", "commerce_coupon_no": 0, "order_no": 0, "order_sync": "", "product_no": 0, "address1": "", "card_no": 0, "cart_flag": "", "customer_address_no": 0, "sync_status": "", "address2": "", "card_name": "", "last_sync": "1/1/1900 12:00 AM", "shipping_courier": "", "address3": "", "balance_due": 0, "card_number": "", "device_type": "", "product_type": "", "shipping_method": "", "card_month": 0, "city": "", "order_via": "", "sortby": "", "tracking_number": "", "card_year": 0, "returnTotal": 0, "shipping_status": "", "skipEmailConfirmation": false, "state": "", "shipping_quantity": 0, "zip_code": "", "card_type": "", "country": "", "order_item_no": 0, "address_notes": "", "created_on": "1/1/1900 12:00 AM", "order_date": "1/1/1900 12:00 AM", "status": "", "address_verified": false, "card_description": "", "order_status": "", "phone_number": "", "modified_on": "1/1/1900 12:00 AM", "order_total": 0, "first_name": "", "ip_address": "", "sub_total": 0, "last_name": "", "sessionid": "", "shipping_total": 0, "company_name": "", "tax_total": 0, "user_info": "", "company_No": 0, "device_info": "", "discount_total": 0, "tip_total": 0, "card_security": "", "user_no": 0, "order_note": "", "order_type": "", "flag_paid": 0, "flag_verified": 0, "flag_pulled": 0, "flag_shipped": 0, "flag_completed": 0, "flag_followup": 0, "flag_returned": 0, "flag_modified": 0, "flag_paid_date": "1/1/1900 12:00 AM", "flag_verified_date": "1/1/1900 12:00 AM", "flag_pulled_date": "1/1/1900 12:00 AM", "flag_shipped_date": "1/1/1900 12:00 AM", "flag_completed_date": "1/1/1900 12:00 AM", "flag_followup_date": "1/1/1900 12:00 AM", "flag_returned_date": "1/1/1900 12:00 AM", "flag_modified_date": "1/1/1900 12:00 AM", "affiliate_no": 0 } }
{"auth": {"api_username": "", "api_password": "", "api_key": "", "company_no": 0, "username": "", "password": "" }, "order": {"notify": false, "order_coupon_no": 0, "payment_id": "", "purchase_order": "", "referrer": "", "customer_no": 0, "external_order_no": "", "order_shipping_no": 0, "payment_type": "", "session_id": "", "address_type": "", "commerce_coupon_no": 0, "order_no": 0, "order_sync": "", "product_no": 0, "address1": "", "card_no": 0, "cart_flag": "", "customer_address_no": 0, "sync_status": "", "address2": "", "card_name": "", "last_sync": "1/1/1900 12:00 AM", "shipping_courier": "", "address3": "", "balance_due": 0, "card_number": "", "device_type": "", "product_type": "", "shipping_method": "", "card_month": 0, "city": "", "order_via": "", "sortby": "", "tracking_number": "", "card_year": 0, "returnTotal": 0, "shipping_status": "", "skipEmailConfirmation": false, "state": "", "shipping_quantity": 0, "zip_code": "", "card_type": "", "country": "", "order_item_no": 0, "address_notes": "", "created_on": "1/1/1900 12:00 AM", "order_date": "1/1/1900 12:00 AM", "status": "", "address_verified": false, "card_description": "", "order_status": "", "phone_number": "", "modified_on": "1/1/1900 12:00 AM", "order_total": 0, "first_name": "", "ip_address": "", "sub_total": 0, "last_name": "", "sessionid": "", "shipping_total": 0, "company_name": "", "tax_total": 0, "user_info": "", "company_No": 0, "device_info": "", "discount_total": 0, "tip_total": 0, "card_security": "", "user_no": 0, "order_note": "", "order_type": "", "flag_paid": 0, "flag_verified": 0, "flag_pulled": 0, "flag_shipped": 0, "flag_completed": 0, "flag_followup": 0, "flag_returned": 0, "flag_modified": 0, "flag_paid_date": "1/1/1900 12:00 AM", "flag_verified_date": "1/1/1900 12:00 AM", "flag_pulled_date": "1/1/1900 12:00 AM", "flag_shipped_date": "1/1/1900 12:00 AM", "flag_completed_date": "1/1/1900 12:00 AM", "flag_followup_date": "1/1/1900 12:00 AM", "flag_returned_date": "1/1/1900 12:00 AM", "flag_modified_date": "1/1/1900 12:00 AM", "affiliate_no": 0 } }
This sample code is to generate a function leveraging existing core functions you've already built.
func getAPIKit() -> (url: String, dict: Dictionary<String, AnyObject>) {
var notify = false
var order_coupon_no = 0
var payment_id = ""
var purchase_order = ""
var referrer = ""
var customer_no = 0
var external_order_no = ""
var order_shipping_no = 0
var payment_type = ""
var session_id = ""
var address_type = ""
var commerce_coupon_no = 0
var order_no = 0
var order_sync = ""
var product_no = 0
var address1 = ""
var card_no = 0
var cart_flag = ""
var customer_address_no = 0
var sync_status = ""
var address2 = ""
var card_name = ""
var last_sync = "1/1/1900 12:00 AM"
var shipping_courier = ""
var address3 = ""
var balance_due = 0
var card_number = ""
var device_type = ""
var product_type = ""
var shipping_method = ""
var card_month = 0
var city = ""
var order_via = ""
var sortby = ""
var tracking_number = ""
var card_year = 0
var returnTotal = 0
var shipping_status = ""
var skipEmailConfirmation = false
var state = ""
var shipping_quantity = 0
var zip_code = ""
var card_type = ""
var country = ""
var order_item_no = 0
var address_notes = ""
var created_on = "1/1/1900 12:00 AM"
var order_date = "1/1/1900 12:00 AM"
var status = ""
var address_verified = false
var card_description = ""
var order_status = ""
var phone_number = ""
var modified_on = "1/1/1900 12:00 AM"
var order_total = 0
var first_name = ""
var ip_address = ""
var sub_total = 0
var last_name = ""
var sessionid = ""
var shipping_total = 0
var company_name = ""
var tax_total = 0
var user_info = ""
var company_No = 0
var device_info = ""
var discount_total = 0
var tip_total = 0
var card_security = ""
var user_no = 0
var order_note = ""
var order_type = ""
var flag_paid = 0
var flag_verified = 0
var flag_pulled = 0
var flag_shipped = 0
var flag_completed = 0
var flag_followup = 0
var flag_returned = 0
var flag_modified = 0
var flag_paid_date = "1/1/1900 12:00 AM"
var flag_verified_date = "1/1/1900 12:00 AM"
var flag_pulled_date = "1/1/1900 12:00 AM"
var flag_shipped_date = "1/1/1900 12:00 AM"
var flag_completed_date = "1/1/1900 12:00 AM"
var flag_followup_date = "1/1/1900 12:00 AM"
var flag_returned_date = "1/1/1900 12:00 AM"
var flag_modified_date = "1/1/1900 12:00 AM"
var affiliate_no = 0
let url = "https://api.peoplevine.com/commerce.asmx/processOrder"
let key = "order"
let orderDict: Dictionary<String, AnyObject> = ["notify": notify, "order_coupon_no": order_coupon_no, "payment_id": payment_id, "purchase_order": purchase_order, "referrer": referrer, "customer_no": customer_no, "external_order_no": external_order_no, "order_shipping_no": order_shipping_no, "payment_type": payment_type, "session_id": session_id, "address_type": address_type, "commerce_coupon_no": commerce_coupon_no, "order_no": order_no, "order_sync": order_sync, "product_no": product_no, "address1": address1, "card_no": card_no, "cart_flag": cart_flag, "customer_address_no": customer_address_no, "sync_status": sync_status, "address2": address2, "card_name": card_name, "last_sync": last_sync, "shipping_courier": shipping_courier, "address3": address3, "balance_due": balance_due, "card_number": card_number, "device_type": device_type, "product_type": product_type, "shipping_method": shipping_method, "card_month": card_month, "city": city, "order_via": order_via, "sortby": sortby, "tracking_number": tracking_number, "card_year": card_year, "returnTotal": returnTotal, "shipping_status": shipping_status, "skipEmailConfirmation": skipEmailConfirmation, "state": state, "shipping_quantity": shipping_quantity, "zip_code": zip_code, "card_type": card_type, "country": country, "order_item_no": order_item_no, "address_notes": address_notes, "created_on": created_on, "order_date": order_date, "status": status, "address_verified": address_verified, "card_description": card_description, "order_status": order_status, "phone_number": phone_number, "modified_on": modified_on, "order_total": order_total, "first_name": first_name, "ip_address": ip_address, "sub_total": sub_total, "last_name": last_name, "sessionid": sessionid, "shipping_total": shipping_total, "company_name": company_name, "tax_total": tax_total, "user_info": user_info, "company_No": company_No, "device_info": device_info, "discount_total": discount_total, "tip_total": tip_total, "card_security": card_security, "user_no": user_no, "order_note": order_note, "order_type": order_type, "flag_paid": flag_paid, "flag_verified": flag_verified, "flag_pulled": flag_pulled, "flag_shipped": flag_shipped, "flag_completed": flag_completed, "flag_followup": flag_followup, "flag_returned": flag_returned, "flag_modified": flag_modified, "flag_paid_date": flag_paid_date, "flag_verified_date": flag_verified_date, "flag_pulled_date": flag_pulled_date, "flag_shipped_date": flag_shipped_date, "flag_completed_date": flag_completed_date, "flag_followup_date": flag_followup_date, "flag_returned_date": flag_returned_date, "flag_modified_date": flag_modified_date, "affiliate_no": affiliate_no ]
let finalDict = User.getAuthDict(dictToAdd: orderDict, dictKey: key)
return (url, finalDict)
}
To get started we reccomend that you download the Alamofire project to simplify integration: https://github.com/Alamofire/Alamofire, in addition to SwiftyJSON: https://github.com/SwiftyJSON/SwiftyJSON
import Foundation
struct AUTH {
static var api_username = <string>
static var api_password = <string>
static var api_key = <string>
static var company_no = <double>
static var username = <string>
static var password = <string>
static var timezone_offset = <double>
static var auth_type = <string>
static var system_name = <string>
static var system_company_no = <double>}
struct ORDER {
static var notify = <boolean>
static var order_coupon_no = <double>
static var payment_id = <string>
static var purchase_order = <string>
static var referrer = <string>
static var customer_no = <double>
static var external_order_no = <string>
static var order_shipping_no = <double>
static var payment_type = <string>
static var session_id = <string>
static var address_type = <string>
static var commerce_coupon_no = <double>
static var order_no = <double>
static var order_sync = <string>
static var product_no = <double>
static var address1 = <string>
static var card_no = <double>
static var cart_flag = <string>
static var customer_address_no = <double>
static var sync_status = <string>
static var address2 = <string>
static var card_name = <string>
static var last_sync = <dateTime>
static var shipping_courier = <string>
static var address3 = <string>
static var balance_due = <double>
static var card_number = <string>
static var device_type = <string>
static var product_type = <string>
static var shipping_method = <string>
static var card_month = <double>
static var city = <string>
static var order_via = <string>
static var sortby = <string>
static var tracking_number = <string>
static var card_year = <double>
static var returnTotal = <double>
static var shipping_status = <string>
static var skipEmailConfirmation = <boolean>
static var state = <string>
static var shipping_quantity = <double>
static var zip_code = <string>
static var card_type = <string>
static var country = <string>
static var order_item_no = <double>
static var address_notes = <string>
static var created_on = <dateTime>
static var order_date = <dateTime>
static var status = <string>
static var address_verified = <boolean>
static var card_description = <string>
static var order_status = <string>
static var phone_number = <string>
static var modified_on = <dateTime>
static var order_total = <double>
static var first_name = <string>
static var ip_address = <string>
static var sub_total = <double>
static var last_name = <string>
static var sessionid = <string>
static var shipping_total = <double>
static var company_name = <string>
static var tax_total = <double>
static var user_info = <string>
static var company_No = <double>
static var device_info = <string>
static var discount_total = <double>
static var tip_total = <double>
static var card_security = <string>
static var user_no = <double>
static var order_note = <string>
static var order_type = <string>
static var flag_paid = <double>
static var flag_verified = <double>
static var flag_pulled = <double>
static var flag_shipped = <double>
static var flag_completed = <double>
static var flag_followup = <double>
static var flag_returned = <double>
static var flag_modified = <double>
static var flag_paid_date = <dateTime>
static var flag_verified_date = <dateTime>
static var flag_pulled_date = <dateTime>
static var flag_shipped_date = <dateTime>
static var flag_completed_date = <dateTime>
static var flag_followup_date = <dateTime>
static var flag_returned_date = <dateTime>
static var flag_modified_date = <dateTime>
static var affiliate_no = <double>}
func processOrderRequest() {
var processOrderObjects = [AnyObject]()
let postsEndpoint: String = "https://api.peoplevine.com/commerce.asmx/processOrder"
let authAndFieldsDict = ["auth": ["api_username": AUTH.api_username, "api_password": AUTH.api_password, "api_key": AUTH.api_key, "company_no": AUTH.company_no, "username": AUTH.username, "password": AUTH.password, "timezone_offset": AUTH.timezone_offset, "auth_type": AUTH.auth_type, "system_name": AUTH.system_name, "system_company_no": AUTH.system_company_no ], "order": ["notify": ORDER.notify, "order_coupon_no": ORDER.order_coupon_no, "payment_id": ORDER.payment_id, "purchase_order": ORDER.purchase_order, "referrer": ORDER.referrer, "customer_no": ORDER.customer_no, "external_order_no": ORDER.external_order_no, "order_shipping_no": ORDER.order_shipping_no, "payment_type": ORDER.payment_type, "session_id": ORDER.session_id, "address_type": ORDER.address_type, "commerce_coupon_no": ORDER.commerce_coupon_no, "order_no": ORDER.order_no, "order_sync": ORDER.order_sync, "product_no": ORDER.product_no, "address1": ORDER.address1, "card_no": ORDER.card_no, "cart_flag": ORDER.cart_flag, "customer_address_no": ORDER.customer_address_no, "sync_status": ORDER.sync_status, "address2": ORDER.address2, "card_name": ORDER.card_name, "last_sync": ORDER.last_sync, "shipping_courier": ORDER.shipping_courier, "address3": ORDER.address3, "balance_due": ORDER.balance_due, "card_number": ORDER.card_number, "device_type": ORDER.device_type, "product_type": ORDER.product_type, "shipping_method": ORDER.shipping_method, "card_month": ORDER.card_month, "city": ORDER.city, "order_via": ORDER.order_via, "sortby": ORDER.sortby, "tracking_number": ORDER.tracking_number, "card_year": ORDER.card_year, "returnTotal": ORDER.returnTotal, "shipping_status": ORDER.shipping_status, "skipEmailConfirmation": ORDER.skipEmailConfirmation, "state": ORDER.state, "shipping_quantity": ORDER.shipping_quantity, "zip_code": ORDER.zip_code, "card_type": ORDER.card_type, "country": ORDER.country, "order_item_no": ORDER.order_item_no, "address_notes": ORDER.address_notes, "created_on": ORDER.created_on, "order_date": ORDER.order_date, "status": ORDER.status, "address_verified": ORDER.address_verified, "card_description": ORDER.card_description, "order_status": ORDER.order_status, "phone_number": ORDER.phone_number, "modified_on": ORDER.modified_on, "order_total": ORDER.order_total, "first_name": ORDER.first_name, "ip_address": ORDER.ip_address, "sub_total": ORDER.sub_total, "last_name": ORDER.last_name, "sessionid": ORDER.sessionid, "shipping_total": ORDER.shipping_total, "company_name": ORDER.company_name, "tax_total": ORDER.tax_total, "user_info": ORDER.user_info, "company_No": ORDER.company_No, "device_info": ORDER.device_info, "discount_total": ORDER.discount_total, "tip_total": ORDER.tip_total, "card_security": ORDER.card_security, "user_no": ORDER.user_no, "order_note": ORDER.order_note, "order_type": ORDER.order_type, "flag_paid": ORDER.flag_paid, "flag_verified": ORDER.flag_verified, "flag_pulled": ORDER.flag_pulled, "flag_shipped": ORDER.flag_shipped, "flag_completed": ORDER.flag_completed, "flag_followup": ORDER.flag_followup, "flag_returned": ORDER.flag_returned, "flag_modified": ORDER.flag_modified, "flag_paid_date": ORDER.flag_paid_date, "flag_verified_date": ORDER.flag_verified_date, "flag_pulled_date": ORDER.flag_pulled_date, "flag_shipped_date": ORDER.flag_shipped_date, "flag_completed_date": ORDER.flag_completed_date, "flag_followup_date": ORDER.flag_followup_date, "flag_returned_date": ORDER.flag_returned_date, "flag_modified_date": ORDER.flag_modified_date, "affiliate_no": ORDER.affiliate_no ] ]
Alamofire.request(.POST, postsEndpoint, parameters: authAndFieldsDict, encoding: .JSON).responseJSON { (request, response, data, error) in
if let anError = error {
println("error calling POST on /posts")
println(error)
} else if let jsonData: AnyObject = data {
if let dataString = (jsonData.valueForKey("d") as! String).dataUsingEncoding(NSUTF8StringEncoding) {
let json = JSON(data: dataString) //use this object to parse data
//SAMPLE PARSING
let varData = json["returnObject"][0]["object"].stringValue
// ----------
// BELOW REPRESENTS AN EXAMPLE USING PURE SWIFT JSONSERIALIZATION INSTEAD OF SWIFTYJSON --------//
// if let processOrderDict = NSJSONSerialization.JSONObjectWithData(encoString, options: .MutableContainers, error: nil) as? NSDictionary {
// if let returnObjectArray = processOrderDict["returnObject"] as? NSArray {
//
// for processOrderObject in returnObjectArray {
// processOrderObjects.append(processOrderObject)
// if let item = processOrderObject["object_name"] as? NSDictionary {
// let varItem = item["field_name"] as! String
// }
// }
//
// println("\n\(processOrderObjects.count) Total")
// }
// }
}
}
}
}
<!DOCTYPE html>
<html>
<head>
<title>API Call - processOrder</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(function() {
var dataValue = {
"auth": {
"api_username": "",
"api_password": "",
"api_key": "",
"company_no": 0,
"username": "",
"password": "",
"timezone_offset": 0,
"auth_type": "",
"system_name": "",
"system_company_no": 0,
},
"order": {
"notify": false,
"order_coupon_no": 0,
"payment_id": "",
"purchase_order": "",
"referrer": "",
"customer_no": 0,
"external_order_no": "",
"order_shipping_no": 0,
"payment_type": "",
"session_id": "",
"address_type": "",
"commerce_coupon_no": 0,
"order_no": 0,
"order_sync": "",
"product_no": 0,
"address1": "",
"card_no": 0,
"cart_flag": "",
"customer_address_no": 0,
"sync_status": "",
"address2": "",
"card_name": "",
"last_sync": "1/1/1900 12:00 AM",
"shipping_courier": "",
"address3": "",
"balance_due": 0,
"card_number": "",
"device_type": "",
"product_type": "",
"shipping_method": "",
"card_month": 0,
"city": "",
"order_via": "",
"sortby": "",
"tracking_number": "",
"card_year": 0,
"returnTotal": 0,
"shipping_status": "",
"skipEmailConfirmation": false,
"state": "",
"shipping_quantity": 0,
"zip_code": "",
"card_type": "",
"country": "",
"order_item_no": 0,
"address_notes": "",
"created_on": "1/1/1900 12:00 AM",
"order_date": "1/1/1900 12:00 AM",
"status": "",
"address_verified": false,
"card_description": "",
"order_status": "",
"phone_number": "",
"modified_on": "1/1/1900 12:00 AM",
"order_total": 0,
"first_name": "",
"ip_address": "",
"sub_total": 0,
"last_name": "",
"sessionid": "",
"shipping_total": 0,
"company_name": "",
"tax_total": 0,
"user_info": "",
"company_No": 0,
"device_info": "",
"discount_total": 0,
"tip_total": 0,
"card_security": "",
"user_no": 0,
"order_note": "",
"order_type": "",
"flag_paid": 0,
"flag_verified": 0,
"flag_pulled": 0,
"flag_shipped": 0,
"flag_completed": 0,
"flag_followup": 0,
"flag_returned": 0,
"flag_modified": 0,
"flag_paid_date": "1/1/1900 12:00 AM",
"flag_verified_date": "1/1/1900 12:00 AM",
"flag_pulled_date": "1/1/1900 12:00 AM",
"flag_shipped_date": "1/1/1900 12:00 AM",
"flag_completed_date": "1/1/1900 12:00 AM",
"flag_followup_date": "1/1/1900 12:00 AM",
"flag_returned_date": "1/1/1900 12:00 AM",
"flag_modified_date": "1/1/1900 12:00 AM",
"affiliate_no": 0,
},
};
$.ajax({
url: 'https://api.peoplevine.com/commerce.asmx/processOrder',
type: 'POST',
data: JSON.stringify(dataValue),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("ERROR");
},
success: function (result) {
var obj = JSON.parse(result.d).returnObject;
$.each(obj, function(i) {
$("#divID").html(obj[i].field_name); //do something with the data
})
}
})
});
</script>
</body>
</html>
System.Net.HttpWebRequest req = System.Net.HttpWebRequest.Create("https://api.peoplevine.com/commerce.asmx/processOrder");
req.Method = "POST";
req.ContentType = "application/json; charset=utf-8";
string dataValue = "{auth: {api_username: <string>, api_password: <string>, api_key: <string>, company_no: <double>, username: <string>, password: <string>, timezone_offset: <double>, auth_type: <string>, system_name: <string>, system_company_no: <double> },order: {notify: <boolean>, order_coupon_no: <double>, payment_id: <string>, purchase_order: <string>, referrer: <string>, customer_no: <double>, external_order_no: <string>, order_shipping_no: <double>, payment_type: <string>, session_id: <string>, address_type: <string>, commerce_coupon_no: <double>, order_no: <double>, order_sync: <string>, product_no: <double>, address1: <string>, card_no: <double>, cart_flag: <string>, customer_address_no: <double>, sync_status: <string>, address2: <string>, card_name: <string>, last_sync: <dateTime>, shipping_courier: <string>, address3: <string>, balance_due: <double>, card_number: <string>, device_type: <string>, product_type: <string>, shipping_method: <string>, card_month: <double>, city: <string>, order_via: <string>, sortby: <string>, tracking_number: <string>, card_year: <double>, returnTotal: <double>, shipping_status: <string>, skipEmailConfirmation: <boolean>, state: <string>, shipping_quantity: <double>, zip_code: <string>, card_type: <string>, country: <string>, order_item_no: <double>, address_notes: <string>, created_on: <dateTime>, order_date: <dateTime>, status: <string>, address_verified: <boolean>, card_description: <string>, order_status: <string>, phone_number: <string>, modified_on: <dateTime>, order_total: <double>, first_name: <string>, ip_address: <string>, sub_total: <double>, last_name: <string>, sessionid: <string>, shipping_total: <double>, company_name: <string>, tax_total: <double>, user_info: <string>, company_No: <double>, device_info: <string>, discount_total: <double>, tip_total: <double>, card_security: <string>, user_no: <double>, order_note: <string>, order_type: <string>, flag_paid: <double>, flag_verified: <double>, flag_pulled: <double>, flag_shipped: <double>, flag_completed: <double>, flag_followup: <double>, flag_returned: <double>, flag_modified: <double>, flag_paid_date: <dateTime>, flag_verified_date: <dateTime>, flag_pulled_date: <dateTime>, flag_shipped_date: <dateTime>, flag_completed_date: <dateTime>, flag_followup_date: <dateTime>, flag_returned_date: <dateTime>, flag_modified_date: <dateTime>, affiliate_no: <double> }}";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] bytes = encoding.GetBytes(dataValue);
req.ContentLength = bytes.Length;
System.IO.Stream strm = req.GetRequestStream();
strm.Write(bytes, 0, bytes.Length);
strm.Close();
System.Net.HttpWebResponse rsp = req.GetResponse();
System.IO.Stream data = rsp.GetResponseStream();
System.IO.StreamReader rdr = new System.IO.StreamReader(data);
string response = rdr.ReadToEnd();
Dim req As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("https://api.peoplevine.com/commerce.asmx/processOrder")
req.Method = "POST"
req.ContentType = "application/json; charset=utf-8"
Dim dataValue As String = "{auth: {api_username: <string>, api_password: <string>, api_key: <string>, company_no: <double>, username: <string>, password: <string>, timezone_offset: <double>, auth_type: <string>, system_name: <string>, system_company_no: <double> },order: {notify: <boolean>, order_coupon_no: <double>, payment_id: <string>, purchase_order: <string>, referrer: <string>, customer_no: <double>, external_order_no: <string>, order_shipping_no: <double>, payment_type: <string>, session_id: <string>, address_type: <string>, commerce_coupon_no: <double>, order_no: <double>, order_sync: <string>, product_no: <double>, address1: <string>, card_no: <double>, cart_flag: <string>, customer_address_no: <double>, sync_status: <string>, address2: <string>, card_name: <string>, last_sync: <dateTime>, shipping_courier: <string>, address3: <string>, balance_due: <double>, card_number: <string>, device_type: <string>, product_type: <string>, shipping_method: <string>, card_month: <double>, city: <string>, order_via: <string>, sortby: <string>, tracking_number: <string>, card_year: <double>, returnTotal: <double>, shipping_status: <string>, skipEmailConfirmation: <boolean>, state: <string>, shipping_quantity: <double>, zip_code: <string>, card_type: <string>, country: <string>, order_item_no: <double>, address_notes: <string>, created_on: <dateTime>, order_date: <dateTime>, status: <string>, address_verified: <boolean>, card_description: <string>, order_status: <string>, phone_number: <string>, modified_on: <dateTime>, order_total: <double>, first_name: <string>, ip_address: <string>, sub_total: <double>, last_name: <string>, sessionid: <string>, shipping_total: <double>, company_name: <string>, tax_total: <double>, user_info: <string>, company_No: <double>, device_info: <string>, discount_total: <double>, tip_total: <double>, card_security: <string>, user_no: <double>, order_note: <string>, order_type: <string>, flag_paid: <double>, flag_verified: <double>, flag_pulled: <double>, flag_shipped: <double>, flag_completed: <double>, flag_followup: <double>, flag_returned: <double>, flag_modified: <double>, flag_paid_date: <dateTime>, flag_verified_date: <dateTime>, flag_pulled_date: <dateTime>, flag_shipped_date: <dateTime>, flag_completed_date: <dateTime>, flag_followup_date: <dateTime>, flag_returned_date: <dateTime>, flag_modified_date: <dateTime>, affiliate_no: <double> }}"
Dim encoding As New ASCIIEncoding()
Dim bytes As Byte() = encoding.GetBytes(dataValue)
req.ContentLength = bytes.Length
Dim strm As System.IO.Stream = req.GetRequestStream()
strm.Write(bytes, 0, bytes.Length)
strm.Close()
Dim rsp As System.Net.HttpWebResponse = req.GetResponse()
Dim data As System.IO.Stream = rsp.GetResponseStream()
Dim rdr As New System.IO.StreamReader(data)
Dim response As String = rdr.ReadToEnd()
// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
import java.net.URI;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class JavaSample {
public static void main(String[] args) {
HttpClient httpclient = HttpClients.createDefault();
try
{
URIBuilder builder = new URIBuilder("https://peoplevine.azure-api.net/customer/customer/registerCustomer");
// Specify your subscription key
builder.setParameter("subscription-key", "");
URI uri = builder.build();
HttpPost request = new HttpPost(uri);
StringEntity reqEntity = new StringEntity("", ContentType.create("application/json"));
request.setEntity(reqEntity);
HttpResponse response = httpclient.execute(request);
HttpEntity entity = response.getEntity();
if (entity != null) {
System.out.println(EntityUtils.toString(entity));
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}
<?php
// This sample uses the HTTP_Request2 package. (for more information: http://pear.php.net/package/HTTP_Request2)
require_once 'HTTP/Request2.php';
$headers = array(
'Content-Type' => 'application/json',
);
$query_params = array(
// Specify your subscription key
'subscription-key' => '',
);
$request = new Http_Request2('https://peoplevine.azure-api.net/customer/customer/registerCustomer');
$request->setMethod(HTTP_Request2::METHOD_POST);
// Basic Authorization Sample
// $request-setAuth('{username}', '{password}');
$request->setHeader($headers);
$url = $request->getUrl();
$url->setQueryVariables($query_params);
$request->setBody("");
try
{
$response = $request->send();
echo $response->getBody();
}
catch (HttpException $ex)
{
echo $ex;
}
?>
#import <Foundation/Foundation.h>
NSDictionary *authDic = [NSDictionary dictionaryWithObjectsAndKeys:
<string>, @"api_username",
<string>, @"api_password",
<string>, @"api_key",
<double>, @"company_no",
<string>, @"username",
<string>, @"password",
<double>, @"timezone_offset",
<string>, @"auth_type",
<string>, @"system_name",
<double>, @"system_company_no", nil];
NSDictionary *orderDic = [NSDictionary dictionaryWithObjectsAndKeys:
<boolean>, @"notify",
<double>, @"order_coupon_no",
<string>, @"payment_id",
<string>, @"purchase_order",
<string>, @"referrer",
<double>, @"customer_no",
<string>, @"external_order_no",
<double>, @"order_shipping_no",
<string>, @"payment_type",
<string>, @"session_id",
<string>, @"address_type",
<double>, @"commerce_coupon_no",
<double>, @"order_no",
<string>, @"order_sync",
<double>, @"product_no",
<string>, @"address1",
<double>, @"card_no",
<string>, @"cart_flag",
<double>, @"customer_address_no",
<string>, @"sync_status",
<string>, @"address2",
<string>, @"card_name",
<dateTime>, @"last_sync",
<string>, @"shipping_courier",
<string>, @"address3",
<double>, @"balance_due",
<string>, @"card_number",
<string>, @"device_type",
<string>, @"product_type",
<string>, @"shipping_method",
<double>, @"card_month",
<string>, @"city",
<string>, @"order_via",
<string>, @"sortby",
<string>, @"tracking_number",
<double>, @"card_year",
<double>, @"returnTotal",
<string>, @"shipping_status",
<boolean>, @"skipEmailConfirmation",
<string>, @"state",
<double>, @"shipping_quantity",
<string>, @"zip_code",
<string>, @"card_type",
<string>, @"country",
<double>, @"order_item_no",
<string>, @"address_notes",
<dateTime>, @"created_on",
<dateTime>, @"order_date",
<string>, @"status",
<boolean>, @"address_verified",
<string>, @"card_description",
<string>, @"order_status",
<string>, @"phone_number",
<dateTime>, @"modified_on",
<double>, @"order_total",
<string>, @"first_name",
<string>, @"ip_address",
<double>, @"sub_total",
<string>, @"last_name",
<string>, @"sessionid",
<double>, @"shipping_total",
<string>, @"company_name",
<double>, @"tax_total",
<string>, @"user_info",
<double>, @"company_No",
<string>, @"device_info",
<double>, @"discount_total",
<double>, @"tip_total",
<string>, @"card_security",
<double>, @"user_no",
<string>, @"order_note",
<string>, @"order_type",
<double>, @"flag_paid",
<double>, @"flag_verified",
<double>, @"flag_pulled",
<double>, @"flag_shipped",
<double>, @"flag_completed",
<double>, @"flag_followup",
<double>, @"flag_returned",
<double>, @"flag_modified",
<dateTime>, @"flag_paid_date",
<dateTime>, @"flag_verified_date",
<dateTime>, @"flag_pulled_date",
<dateTime>, @"flag_shipped_date",
<dateTime>, @"flag_completed_date",
<dateTime>, @"flag_followup_date",
<dateTime>, @"flag_returned_date",
<dateTime>, @"flag_modified_date",
<double>, @"affiliate_no", nil];
NSDictionary *finalDic = [NSDictionary dictionaryWithObjectsAndKeys:
authDic, @"auth",orderDic, @"order", nil];
NSMutableDictionary* jsonString = nil;
jsonString = [NSJSONSerialization JSONObjectWithData: findalDic options:NSJSONReadingMutableContainers];
NSMutableData *bodyData = [NSMutableData dataWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding]];
NSString *urlString = @"https://api.peoplevine.com/commerce.asmx/processOrder";
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:urlString]];
[request setTimeOutSeconds:250];
[request setRequestMethod:@"POST"];
[request addRequestHeader:@"Content-Type" value:@"application/json"];
[request addRequestHeader:[NSString stringWithFormat:@"%d",bodyData.length] value:@"Content-length"];
[request setPostBody:bodyData];
[request startSynchronous];
NSDictionary *responseDic = (NSDictionary*)[request.responseString JSONValue];
if (responseDic || [responseDic objectForKey:@"d"])
{
NSMutableDictionary *dicSave=[responseDic objectForKey:@"d"];
// -------------------------------------------------------------------
// convert into the data and NSUTF8StringEncoding
// -------------------------------------------------------------------
NSString *strDic=[dicSave copy];
NSMutableDictionary *dirJson;
if (strDic)
{
NSData* dataFile=[strDic dataUsingEncoding:NSUTF8StringEncoding];
NSString* newStr = [[NSString alloc] initWithData:dataFile
encoding:NSUTF8StringEncoding];
dirJson = [newStr JSONValue] ;
}
// -------------------------------------------------------------------
NSString *str=[[dirJson objectForKey:@"returnObject"]valueForKey:@"customer_no"];
}
else
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error" message:@"An Error Occurred" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
}
require 'net/http'
uri = URI('https://peoplevine.azure-api.net/customer/customer/registerCustomer')
uri.query = URI.encode_www_form({
# Specify your subscription key
'subscription-key' => '',
})
request = Net::HTTP::Post.new(uri.request_uri)
# Basic Authorization Sample
# request.basic_auth 'username', 'password'
request['Content-type'] = 'application/json'
request.body = ""
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
http.request(request)
end
puts response.body
########### Python 2.7 #############
import httplib, urllib, base64
headers = {
# Basic Authorization Sample
# 'Authorization': 'Basic %s' % base64.encodestring('{username}:{password}'),
'Content-type': 'application/json',
}
params = urllib.urlencode({
# Specify your subscription key
'subscription-key': '',
})
try:
conn = httplib.HTTPSConnection('peoplevine.azure-api.net')
conn.request("POST", "/customer/customer/registerCustomer?%s" % params, "", headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
####################################
########### Python 3.2 #############
import http.client, urllib.request, urllib.parse, urllib.error, base64
headers = {
# Basic Authorization Sample
# 'Authorization': 'Basic %s' % base64.encodestring('{username}:{password}'),
'Content-type': 'application/json',
}
params = urllib.parse.urlencode({
# Specify your subscription key
'subscription-key': '',
})
try:
conn = http.client.HTTPSConnection('peoplevine.azure-api.net')
conn.request("POST", "/customer/customer/registerCustomer?%s" % params, "", headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
####################################
@ECHO OFF
REM for Basic Authorization use: --user {username}:{password}
REM Specify values for path parameters (shown as {...}), your subscription key and values for query parameters
curl -v -X POST "https://peoplevine.azure-api.net/customer/customer/registerCustomer?subscription-key="^
-H "Content-Type: application/json"