Sample code for 30+ languages & platforms
Rust Requires Chilkat v11.0.0+

CardConnect Create Profile

See more CardConnect Examples

Demonstrates how to create a profile.
A PUT call to the profile endpoint creates a new profile or adds a new account to an existing profile. ...

See https://developer.cardconnect.com/cardconnect-api?lang=json#create-update-profile-request

Chilkat Rust Downloads

Rust

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let http = chilkat::Http::new();

http.set_basic_auth(true);
http.set_login("API_USERNAME");
http.set_password("API_PASSWORD");

// Build and send the following JSON:

// {
//   "region": "AK",
//   "phone": "7778789999",
//   "accttype": "VISA",
//   "postal": "19090",
//   "ssnl4": "3655",
//   "expiry": "0214",
//   "city": "ANYTOWN",
//   "country": "US",
//   "address": "123 MAIN STREET",
//   "merchid": "496400000840",
//   "name": "TOM JONES",
//   "account": "4444333322221111",
//   "license": "123451254",
// }

let json = chilkat::JsonObject::new();
let _ = json.update_string("region", "AK");
let _ = json.update_string("phone", "7778789999");
let _ = json.update_string("accttype", "VISA");
let _ = json.update_string("postal", "19090");
let _ = json.update_string("ssnl4", "3655");
let _ = json.update_string("expiry", "0214");
let _ = json.update_string("city", "ANYTOWN");
let _ = json.update_string("country", "US");
let _ = json.update_string("address", "123 MAIN STREET");
let _ = json.update_string("merchid", "MERCHANT_ID");
let _ = json.update_string("name", "TOM JONES");
let _ = json.update_string("account", "4444333322221111");
let _ = json.update_string("license", "123451254");

let url = "https://<site>.cardconnect.com:<port>/cardconnect/rest/profile".to_string();

let resp = chilkat::HttpResponse::new();
if http.http_str("PUT", &url, &json.emit().unwrap_or_default(), "utf-8", "application/json", &resp).is_err() {
    println!("{}", http.last_error_text());
    return;
}

// A response status of 200 indicates potential success.  The JSON response body
// must be examined to determine if it was truly successful or an error.
println!("response status code = {}", resp.status_code());

let json_resp = chilkat::JsonObject::new();
let _ = json_resp.load(&resp.body_str());
json_resp.set_emit_compact(false);

println!("response JSON:");
println!("{}", json_resp.emit().unwrap_or_default());

// A successful response looks like this:

// {
//   "country": "US",
//   "address": "123 MAIN STREET",
//   "resptext": "Profile Saved",
//   "city": "ANYTOWN",
//   "acctid": "1",
//   "respcode": "09",
//   "defaultacct": "Y",
//   "accttype": "VISA",
//   "token": "9441149619831111",
//   "license": "123451254",
//   "respproc": "PPS",
//   "phone": "7778789999",
//   "profileid": "16392957457306633141",
//   "name": "TOM JONES",
//   "auoptout": "N",
//   "postal": "19090",
//   "expiry": "0214",
//   "region": "AK",
//   "ssnl4": "3655",
//   "respstat": "A"
// }

// Use this online tool to generate parsing code from sample JSON: 
// Generate Parsing Code from JSON

let country = json_resp.string_of("country").unwrap_or_default();
let address = json_resp.string_of("address").unwrap_or_default();
let resptext = json_resp.string_of("resptext").unwrap_or_default();
let city = json_resp.string_of("city").unwrap_or_default();
let acctid = json_resp.string_of("acctid").unwrap_or_default();
let respcode = json_resp.string_of("respcode").unwrap_or_default();
let defaultacct = json_resp.string_of("defaultacct").unwrap_or_default();
let accttype = json_resp.string_of("accttype").unwrap_or_default();
let token = json_resp.string_of("token").unwrap_or_default();
let license = json_resp.string_of("license").unwrap_or_default();
let respproc = json_resp.string_of("respproc").unwrap_or_default();
let phone = json_resp.string_of("phone").unwrap_or_default();
let profileid = json_resp.string_of("profileid").unwrap_or_default();
let name = json_resp.string_of("name").unwrap_or_default();
let auoptout = json_resp.string_of("auoptout").unwrap_or_default();
let postal = json_resp.string_of("postal").unwrap_or_default();
let expiry = json_resp.string_of("expiry").unwrap_or_default();
let region = json_resp.string_of("region").unwrap_or_default();
let ssnl4 = json_resp.string_of("ssnl4").unwrap_or_default();
let respstat = json_resp.string_of("respstat").unwrap_or_default();