Chilkat Online Tools

Java / CardPointe API Integration / Profile (New account/token/card)

Back to Collection Items

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttp http = new CkHttp();
    boolean success;

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

    // The following JSON is sent in the request body.

    // {
    //   "name": "Carson Wentz",
    //   "address": "100 S. Broad Street",
    //   "city": "Philadelphia",
    //   "region": "PA",
    //   "country": "US",
    //   "postal": "19103",
    //   "merchid": "{{merchid}}",
    //   "account": "{{account}}",
    //   "expiry": "{{expiry}}",
    //   "currency": "{{currency}}",
    //   "profile": "{{profileid}}",
    //   "profileupdate": "Y",
    //   "defaultacct": "N"
    // }

    CkJsonObject json = new CkJsonObject();
    json.UpdateString("name","Carson Wentz");
    json.UpdateString("address","100 S. Broad Street");
    json.UpdateString("city","Philadelphia");
    json.UpdateString("region","PA");
    json.UpdateString("country","US");
    json.UpdateString("postal","19103");
    json.UpdateString("merchid","{{merchid}}");
    json.UpdateString("account","{{account}}");
    json.UpdateString("expiry","{{expiry}}");
    json.UpdateString("currency","{{currency}}");
    json.UpdateString("profile","{{profileid}}");
    json.UpdateString("profileupdate","Y");
    json.UpdateString("defaultacct","N");

    http.SetRequestHeader("Authorization","{{Authorization}}");
    http.SetRequestHeader("Content-Type","application/json");

    CkStringBuilder sbRequestBody = new CkStringBuilder();
    json.EmitSb(sbRequestBody);

    CkHttpResponse resp = http.PTextSb("PUT","https://domain.com/profile",sbRequestBody,"utf-8","application/json",false,false);
    if (http.get_LastMethodSuccess() == false) {
        System.out.println(http.lastErrorText());
        return;
        }

    System.out.println(resp.get_StatusCode());
    System.out.println(resp.bodyStr());
  }
}

Curl Command

curl -X PUT
	-H "Authorization: {{Authorization}}"
	-H "Content-Type: application/json"
	-d '{
    "name": "Carson Wentz",
    "address": "100 S. Broad Street",
    "city": "Philadelphia",
    "region": "PA",
    "country": "US",
    "postal": "19103",
    "merchid": "{{merchid}}",
    "account": "{{account}}",
    "expiry": "{{expiry}}",
    "currency": "{{currency}}",
    "profile": "{{profileid}}",
    "profileupdate": "Y",
    "defaultacct": "N"
}'
https://domain.com/profile

Postman Collection Item JSON

{
  "name": "Profile (New account/token/card)",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "var jsonData = JSON.parse(responseBody);",
          "postman.setEnvironmentVariable(\"profileid\", jsonData.profileid);",
          "var jsonData = JSON.parse(responseBody);",
          "postman.setEnvironmentVariable(\"acctid\", jsonData.acctid);"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "PUT",
    "header": [
      {
        "key": "Authorization",
        "value": "{{Authorization}}"
      },
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"name\": \"Carson Wentz\",\n    \"address\": \"100 S. Broad Street\",\n    \"city\": \"Philadelphia\",\n    \"region\": \"PA\",\n    \"country\": \"US\",\n    \"postal\": \"19103\",\n    \"merchid\": \"{{merchid}}\",\n    \"account\": \"{{account}}\",\n    \"expiry\": \"{{expiry}}\",\n    \"currency\": \"{{currency}}\",\n    \"profile\": \"{{profileid}}\",\n    \"profileupdate\": \"Y\",\n    \"defaultacct\": \"N\"\n}"
    },
    "url": {
      "raw": "{{url}}/profile",
      "host": [
        "{{url}}"
      ],
      "path": [
        "profile"
      ]
    },
    "description": "[Profile Documentation](https://developer.cardconnect.com/cardconnect-api#profile)\n\n**Notes:** \n* To create subaccounts on an existing profile\n* acctid = n + 1"
  },
  "response": [
  ]
}