Chilkat Online Tools

delphiDll / ORACLE Hospitality OPERA Cloud REST API Workflows / Create New Profile If one doesn't exist

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
json: HCkJsonObject;
resp: HCkHttpResponse;

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

http := CkHttp_Create();

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

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

// {
//   "profileDetails": {
//     "customer": {
//       "personName": [
//         {
//           "givenName": "James",
//           "surname": "Smith",
//           "nameType": "Primary"
//         },
//         {
//           "nameType": "Alternate"
//         },
//         {
//           "nameType": "Incognito"
//         }
//       ],
//       "alienInfo": {},
//       "birthCountry": {
//         "code": ""
//       },
//       "language": "E"
//     },
//     "addresses": {
//       "addressInfo": [
//         {
//           "address": {
//             "isValidated": false,
//             "addressLine": [
//               "3450 North Triumph Boulevard",
//               "Suite 300",
//               "",
//               ""
//             ],
//             "cityName": "Lehi",
//             "postalCode": "84043",
//             "state": "UT",
//             "country": {
//               "value": "US"
//             },
//             "language": "E",
//             "type": "BUSINESS",
//             "primaryInd": true
//           }
//         }
//       ]
//     },
//     "telephones": {
//       "telephoneInfo": [
//         {
//           "telephone": {
//             "phoneTechType": "PHONE",
//             "phoneUseType": "HOME",
//             "phoneNumber": "+1 385 555 0102",
//             "orderSequence": "1",
//             "primaryInd": true
//           }
//         }
//       ]
//     },
//     "mailingActions": {
//       "active": true
//     },
//     "privacyInfo": {
//       "marketResearchParticipation": true,
//       "infoFromThirdParty": true,
//       "autoEnrollLoyaltyProgram": false,
//       "allowPhone": true,
//       "allowSMS": true,
//       "allowEmail": true,
//       "optInMailingList": true,
//       "optInMarketResearch": true,
//       "optInThirdParty": true,
//       "optInAutoEnrollmentMember": true,
//       "optInPhone": true,
//       "optInSms": true,
//       "optInEmail": true
//     },
//     "taxInfo": {},
//     "statusCode": "Active",
//     "requestForHotel": "{{HotelId}}",
//     "markAsRecentlyAccessed": true,
//     "profileType": "Guest"
//   },
//   "profileIdList": [
//   ]
// }

json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'profileDetails.customer.personName[0].givenName','James');
CkJsonObject_UpdateString(json,'profileDetails.customer.personName[0].surname','Smith');
CkJsonObject_UpdateString(json,'profileDetails.customer.personName[0].nameType','Primary');
CkJsonObject_UpdateString(json,'profileDetails.customer.personName[1].nameType','Alternate');
CkJsonObject_UpdateString(json,'profileDetails.customer.personName[2].nameType','Incognito');
CkJsonObject_UpdateNewObject(json,'profileDetails.customer.alienInfo');
CkJsonObject_UpdateString(json,'profileDetails.customer.birthCountry.code','');
CkJsonObject_UpdateString(json,'profileDetails.customer.language','E');
CkJsonObject_UpdateBool(json,'profileDetails.addresses.addressInfo[0].address.isValidated',False);
CkJsonObject_UpdateString(json,'profileDetails.addresses.addressInfo[0].address.addressLine[0]','3450 North Triumph Boulevard');
CkJsonObject_UpdateString(json,'profileDetails.addresses.addressInfo[0].address.addressLine[1]','Suite 300');
CkJsonObject_UpdateString(json,'profileDetails.addresses.addressInfo[0].address.addressLine[2]','');
CkJsonObject_UpdateString(json,'profileDetails.addresses.addressInfo[0].address.addressLine[3]','');
CkJsonObject_UpdateString(json,'profileDetails.addresses.addressInfo[0].address.cityName','Lehi');
CkJsonObject_UpdateString(json,'profileDetails.addresses.addressInfo[0].address.postalCode','84043');
CkJsonObject_UpdateString(json,'profileDetails.addresses.addressInfo[0].address.state','UT');
CkJsonObject_UpdateString(json,'profileDetails.addresses.addressInfo[0].address.country.value','US');
CkJsonObject_UpdateString(json,'profileDetails.addresses.addressInfo[0].address.language','E');
CkJsonObject_UpdateString(json,'profileDetails.addresses.addressInfo[0].address.type','BUSINESS');
CkJsonObject_UpdateBool(json,'profileDetails.addresses.addressInfo[0].address.primaryInd',True);
CkJsonObject_UpdateString(json,'profileDetails.telephones.telephoneInfo[0].telephone.phoneTechType','PHONE');
CkJsonObject_UpdateString(json,'profileDetails.telephones.telephoneInfo[0].telephone.phoneUseType','HOME');
CkJsonObject_UpdateString(json,'profileDetails.telephones.telephoneInfo[0].telephone.phoneNumber','+1 385 555 0102');
CkJsonObject_UpdateString(json,'profileDetails.telephones.telephoneInfo[0].telephone.orderSequence','1');
CkJsonObject_UpdateBool(json,'profileDetails.telephones.telephoneInfo[0].telephone.primaryInd',True);
CkJsonObject_UpdateBool(json,'profileDetails.mailingActions.active',True);
CkJsonObject_UpdateBool(json,'profileDetails.privacyInfo.marketResearchParticipation',True);
CkJsonObject_UpdateBool(json,'profileDetails.privacyInfo.infoFromThirdParty',True);
CkJsonObject_UpdateBool(json,'profileDetails.privacyInfo.autoEnrollLoyaltyProgram',False);
CkJsonObject_UpdateBool(json,'profileDetails.privacyInfo.allowPhone',True);
CkJsonObject_UpdateBool(json,'profileDetails.privacyInfo.allowSMS',True);
CkJsonObject_UpdateBool(json,'profileDetails.privacyInfo.allowEmail',True);
CkJsonObject_UpdateBool(json,'profileDetails.privacyInfo.optInMailingList',True);
CkJsonObject_UpdateBool(json,'profileDetails.privacyInfo.optInMarketResearch',True);
CkJsonObject_UpdateBool(json,'profileDetails.privacyInfo.optInThirdParty',True);
CkJsonObject_UpdateBool(json,'profileDetails.privacyInfo.optInAutoEnrollmentMember',True);
CkJsonObject_UpdateBool(json,'profileDetails.privacyInfo.optInPhone',True);
CkJsonObject_UpdateBool(json,'profileDetails.privacyInfo.optInSms',True);
CkJsonObject_UpdateBool(json,'profileDetails.privacyInfo.optInEmail',True);
CkJsonObject_UpdateNewObject(json,'profileDetails.taxInfo');
CkJsonObject_UpdateString(json,'profileDetails.statusCode','Active');
CkJsonObject_UpdateString(json,'profileDetails.requestForHotel','{{HotelId}}');
CkJsonObject_UpdateBool(json,'profileDetails.markAsRecentlyAccessed',True);
CkJsonObject_UpdateString(json,'profileDetails.profileType','Guest');
CkJsonObject_UpdateNewArray(json,'profileIdList');

CkHttp_SetRequestHeader(http,'Content-Type','application/json');
CkHttp_SetRequestHeader(http,'x-app-key','{{AppKey}}');
CkHttp_SetRequestHeader(http,'x-hotelid','{{HotelId}}');
// Adds the "Authorization: Bearer <access_token>" header.
CkHttp_putAuthToken(http,'<access_token>');

resp := CkHttp_PostJson3(http,'https://domain.com/crm/v1/profiles','application/json',json);
if (CkHttp_getLastMethodSuccess(http) = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

Memo1.Lines.Add(IntToStr(CkHttpResponse_getStatusCode(resp)));
Memo1.Lines.Add(CkHttpResponse__bodyStr(resp));
CkHttpResponse_Dispose(resp);

CkHttp_Dispose(http);
CkJsonObject_Dispose(json);

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-H "x-app-key: {{AppKey}}"
	-H "x-hotelid: {{HotelId}}"
	-d '{
    "profileDetails": {
        "customer": {
            "personName": [
                {
                    "givenName": "James",
                    "surname": "Smith",
                    "nameType": "Primary"
                },
                {
                    "nameType": "Alternate"
                },
                {
                    "nameType": "Incognito"
                }
            ],
            "alienInfo": {},
            "birthCountry": {
                "code": ""
            },
            "language": "E"
        },
        "addresses": {
            "addressInfo": [
                {
                    "address": {
                        "isValidated": false,
                        "addressLine": [
                            "3450 North Triumph Boulevard",
                            "Suite 300",
                            "",
                            ""
                        ],
                        "cityName": "Lehi",
                        "postalCode": "84043",
                        "state": "UT",
                        "country": {
                            "value": "US"
                        },
                        "language": "E",
                        "type": "BUSINESS",
                        "primaryInd": true
                    }
                }
            ]
        },
        "telephones": {
            "telephoneInfo": [
                {
                    "telephone": {
                        "phoneTechType": "PHONE",
                        "phoneUseType": "HOME",
                        "phoneNumber": "+1 385 555 0102",
                        "orderSequence": "1",
                        "primaryInd": true
                    }
                }
            ]
        },
        "mailingActions": {
            "active": true
        },
        "privacyInfo": {
            "marketResearchParticipation": true,
            "infoFromThirdParty": true,
            "autoEnrollLoyaltyProgram": false,
            "allowPhone": true,
            "allowSMS": true,
            "allowEmail": true,
            "optInMailingList": true,
            "optInMarketResearch": true,
            "optInThirdParty": true,
            "optInAutoEnrollmentMember": true,
            "optInPhone": true,
            "optInSms": true,
            "optInEmail": true
        },
        "taxInfo": {},
        "statusCode": "Active",
        "requestForHotel": "{{HotelId}}",
        "markAsRecentlyAccessed": true,
        "profileType": "Guest"
    },
    "profileIdList": []
}'
https://domain.com/crm/v1/profiles

Postman Collection Item JSON

{
  "name": "Create New Profile If one doesn't exist",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "var data = pm.response.headers.get(\"Location\").split(\"/\").pop();\r",
          "postman.setEnvironmentVariable(\"ProfileId\", data);"
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{Token}}",
          "type": "string"
        }
      ]
    },
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "type": "text",
        "value": "application/json"
      },
      {
        "key": "x-app-key",
        "type": "text",
        "value": "{{AppKey}}"
      },
      {
        "key": "x-hotelid",
        "type": "text",
        "value": "{{HotelId}}"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"profileDetails\": {\n        \"customer\": {\n            \"personName\": [\n                {\n                    \"givenName\": \"James\",\n                    \"surname\": \"Smith\",\n                    \"nameType\": \"Primary\"\n                },\n                {\n                    \"nameType\": \"Alternate\"\n                },\n                {\n                    \"nameType\": \"Incognito\"\n                }\n            ],\n            \"alienInfo\": {},\n            \"birthCountry\": {\n                \"code\": \"\"\n            },\n            \"language\": \"E\"\n        },\n        \"addresses\": {\n            \"addressInfo\": [\n                {\n                    \"address\": {\n                        \"isValidated\": false,\n                        \"addressLine\": [\n                            \"3450 North Triumph Boulevard\",\n                            \"Suite 300\",\n                            \"\",\n                            \"\"\n                        ],\n                        \"cityName\": \"Lehi\",\n                        \"postalCode\": \"84043\",\n                        \"state\": \"UT\",\n                        \"country\": {\n                            \"value\": \"US\"\n                        },\n                        \"language\": \"E\",\n                        \"type\": \"BUSINESS\",\n                        \"primaryInd\": true\n                    }\n                }\n            ]\n        },\n        \"telephones\": {\n            \"telephoneInfo\": [\n                {\n                    \"telephone\": {\n                        \"phoneTechType\": \"PHONE\",\n                        \"phoneUseType\": \"HOME\",\n                        \"phoneNumber\": \"+1 385 555 0102\",\n                        \"orderSequence\": \"1\",\n                        \"primaryInd\": true\n                    }\n                }\n            ]\n        },\n        \"mailingActions\": {\n            \"active\": true\n        },\n        \"privacyInfo\": {\n            \"marketResearchParticipation\": true,\n            \"infoFromThirdParty\": true,\n            \"autoEnrollLoyaltyProgram\": false,\n            \"allowPhone\": true,\n            \"allowSMS\": true,\n            \"allowEmail\": true,\n            \"optInMailingList\": true,\n            \"optInMarketResearch\": true,\n            \"optInThirdParty\": true,\n            \"optInAutoEnrollmentMember\": true,\n            \"optInPhone\": true,\n            \"optInSms\": true,\n            \"optInEmail\": true\n        },\n        \"taxInfo\": {},\n        \"statusCode\": \"Active\",\n        \"requestForHotel\": \"{{HotelId}}\",\n        \"markAsRecentlyAccessed\": true,\n        \"profileType\": \"Guest\"\n    },\n    \"profileIdList\": []\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{HostName}}/crm/v1/profiles",
      "host": [
        "{{HostName}}"
      ],
      "path": [
        "crm",
        "v1",
        "profiles"
      ]
    }
  },
  "response": [
  ]
}