Chilkat Online Tools

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

Back to Collection Items

load ./chilkat.dll

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

set http [new_CkHttp]

# 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"
# }

set json [new_CkJsonObject]

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

CkHttp_SetRequestHeader $http "Authorization" "{{Authorization}}"
CkHttp_SetRequestHeader $http "Content-Type" "application/json"

set sbRequestBody [new_CkStringBuilder]

CkJsonObject_EmitSb $json $sbRequestBody

# resp is a CkHttpResponse
set resp [CkHttp_PTextSb $http "PUT" "https://domain.com/profile" $sbRequestBody "utf-8" "application/json" 0 0]
if {[CkHttp_get_LastMethodSuccess $http] == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkJsonObject $json
    delete_CkStringBuilder $sbRequestBody
    exit
}

puts [CkHttpResponse_get_StatusCode $resp]
puts [CkHttpResponse_bodyStr $resp]
delete_CkHttpResponse $resp


delete_CkHttp $http
delete_CkJsonObject $json
delete_CkStringBuilder $sbRequestBody

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": [
  ]
}