Chilkat Online Tools

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

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkHttpResponseW resp;

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

    http = CkHttpW_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 = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"profileDetails.customer.personName[0].givenName",L"James");
    CkJsonObjectW_UpdateString(json,L"profileDetails.customer.personName[0].surname",L"Smith");
    CkJsonObjectW_UpdateString(json,L"profileDetails.customer.personName[0].nameType",L"Primary");
    CkJsonObjectW_UpdateString(json,L"profileDetails.customer.personName[1].nameType",L"Alternate");
    CkJsonObjectW_UpdateString(json,L"profileDetails.customer.personName[2].nameType",L"Incognito");
    CkJsonObjectW_UpdateNewObject(json,L"profileDetails.customer.alienInfo");
    CkJsonObjectW_UpdateString(json,L"profileDetails.customer.birthCountry.code",L"");
    CkJsonObjectW_UpdateString(json,L"profileDetails.customer.language",L"E");
    CkJsonObjectW_UpdateBool(json,L"profileDetails.addresses.addressInfo[0].address.isValidated",FALSE);
    CkJsonObjectW_UpdateString(json,L"profileDetails.addresses.addressInfo[0].address.addressLine[0]",L"3450 North Triumph Boulevard");
    CkJsonObjectW_UpdateString(json,L"profileDetails.addresses.addressInfo[0].address.addressLine[1]",L"Suite 300");
    CkJsonObjectW_UpdateString(json,L"profileDetails.addresses.addressInfo[0].address.addressLine[2]",L"");
    CkJsonObjectW_UpdateString(json,L"profileDetails.addresses.addressInfo[0].address.addressLine[3]",L"");
    CkJsonObjectW_UpdateString(json,L"profileDetails.addresses.addressInfo[0].address.cityName",L"Lehi");
    CkJsonObjectW_UpdateString(json,L"profileDetails.addresses.addressInfo[0].address.postalCode",L"84043");
    CkJsonObjectW_UpdateString(json,L"profileDetails.addresses.addressInfo[0].address.state",L"UT");
    CkJsonObjectW_UpdateString(json,L"profileDetails.addresses.addressInfo[0].address.country.value",L"US");
    CkJsonObjectW_UpdateString(json,L"profileDetails.addresses.addressInfo[0].address.language",L"E");
    CkJsonObjectW_UpdateString(json,L"profileDetails.addresses.addressInfo[0].address.type",L"BUSINESS");
    CkJsonObjectW_UpdateBool(json,L"profileDetails.addresses.addressInfo[0].address.primaryInd",TRUE);
    CkJsonObjectW_UpdateString(json,L"profileDetails.telephones.telephoneInfo[0].telephone.phoneTechType",L"PHONE");
    CkJsonObjectW_UpdateString(json,L"profileDetails.telephones.telephoneInfo[0].telephone.phoneUseType",L"HOME");
    CkJsonObjectW_UpdateString(json,L"profileDetails.telephones.telephoneInfo[0].telephone.phoneNumber",L"+1 385 555 0102");
    CkJsonObjectW_UpdateString(json,L"profileDetails.telephones.telephoneInfo[0].telephone.orderSequence",L"1");
    CkJsonObjectW_UpdateBool(json,L"profileDetails.telephones.telephoneInfo[0].telephone.primaryInd",TRUE);
    CkJsonObjectW_UpdateBool(json,L"profileDetails.mailingActions.active",TRUE);
    CkJsonObjectW_UpdateBool(json,L"profileDetails.privacyInfo.marketResearchParticipation",TRUE);
    CkJsonObjectW_UpdateBool(json,L"profileDetails.privacyInfo.infoFromThirdParty",TRUE);
    CkJsonObjectW_UpdateBool(json,L"profileDetails.privacyInfo.autoEnrollLoyaltyProgram",FALSE);
    CkJsonObjectW_UpdateBool(json,L"profileDetails.privacyInfo.allowPhone",TRUE);
    CkJsonObjectW_UpdateBool(json,L"profileDetails.privacyInfo.allowSMS",TRUE);
    CkJsonObjectW_UpdateBool(json,L"profileDetails.privacyInfo.allowEmail",TRUE);
    CkJsonObjectW_UpdateBool(json,L"profileDetails.privacyInfo.optInMailingList",TRUE);
    CkJsonObjectW_UpdateBool(json,L"profileDetails.privacyInfo.optInMarketResearch",TRUE);
    CkJsonObjectW_UpdateBool(json,L"profileDetails.privacyInfo.optInThirdParty",TRUE);
    CkJsonObjectW_UpdateBool(json,L"profileDetails.privacyInfo.optInAutoEnrollmentMember",TRUE);
    CkJsonObjectW_UpdateBool(json,L"profileDetails.privacyInfo.optInPhone",TRUE);
    CkJsonObjectW_UpdateBool(json,L"profileDetails.privacyInfo.optInSms",TRUE);
    CkJsonObjectW_UpdateBool(json,L"profileDetails.privacyInfo.optInEmail",TRUE);
    CkJsonObjectW_UpdateNewObject(json,L"profileDetails.taxInfo");
    CkJsonObjectW_UpdateString(json,L"profileDetails.statusCode",L"Active");
    CkJsonObjectW_UpdateString(json,L"profileDetails.requestForHotel",L"{{HotelId}}");
    CkJsonObjectW_UpdateBool(json,L"profileDetails.markAsRecentlyAccessed",TRUE);
    CkJsonObjectW_UpdateString(json,L"profileDetails.profileType",L"Guest");
    CkJsonObjectW_UpdateNewArray(json,L"profileIdList");

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

    resp = CkHttpW_PostJson3(http,L"https://domain.com/crm/v1/profiles",L"application/json",json);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonObjectW_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": [
  ]
}