Chilkat Online Tools

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

Back to Collection Items

#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <CkoHttpResponse.h>

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

CkoHttp *http = [[CkoHttp alloc] init];
BOOL 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.

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

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"profileDetails.customer.personName[0].givenName" value: @"James"];
[json UpdateString: @"profileDetails.customer.personName[0].surname" value: @"Smith"];
[json UpdateString: @"profileDetails.customer.personName[0].nameType" value: @"Primary"];
[json UpdateString: @"profileDetails.customer.personName[1].nameType" value: @"Alternate"];
[json UpdateString: @"profileDetails.customer.personName[2].nameType" value: @"Incognito"];
[json UpdateNewObject: @"profileDetails.customer.alienInfo"];
[json UpdateString: @"profileDetails.customer.birthCountry.code" value: @""];
[json UpdateString: @"profileDetails.customer.language" value: @"E"];
[json UpdateBool: @"profileDetails.addresses.addressInfo[0].address.isValidated" value: NO];
[json UpdateString: @"profileDetails.addresses.addressInfo[0].address.addressLine[0]" value: @"3450 North Triumph Boulevard"];
[json UpdateString: @"profileDetails.addresses.addressInfo[0].address.addressLine[1]" value: @"Suite 300"];
[json UpdateString: @"profileDetails.addresses.addressInfo[0].address.addressLine[2]" value: @""];
[json UpdateString: @"profileDetails.addresses.addressInfo[0].address.addressLine[3]" value: @""];
[json UpdateString: @"profileDetails.addresses.addressInfo[0].address.cityName" value: @"Lehi"];
[json UpdateString: @"profileDetails.addresses.addressInfo[0].address.postalCode" value: @"84043"];
[json UpdateString: @"profileDetails.addresses.addressInfo[0].address.state" value: @"UT"];
[json UpdateString: @"profileDetails.addresses.addressInfo[0].address.country.value" value: @"US"];
[json UpdateString: @"profileDetails.addresses.addressInfo[0].address.language" value: @"E"];
[json UpdateString: @"profileDetails.addresses.addressInfo[0].address.type" value: @"BUSINESS"];
[json UpdateBool: @"profileDetails.addresses.addressInfo[0].address.primaryInd" value: YES];
[json UpdateString: @"profileDetails.telephones.telephoneInfo[0].telephone.phoneTechType" value: @"PHONE"];
[json UpdateString: @"profileDetails.telephones.telephoneInfo[0].telephone.phoneUseType" value: @"HOME"];
[json UpdateString: @"profileDetails.telephones.telephoneInfo[0].telephone.phoneNumber" value: @"+1 385 555 0102"];
[json UpdateString: @"profileDetails.telephones.telephoneInfo[0].telephone.orderSequence" value: @"1"];
[json UpdateBool: @"profileDetails.telephones.telephoneInfo[0].telephone.primaryInd" value: YES];
[json UpdateBool: @"profileDetails.mailingActions.active" value: YES];
[json UpdateBool: @"profileDetails.privacyInfo.marketResearchParticipation" value: YES];
[json UpdateBool: @"profileDetails.privacyInfo.infoFromThirdParty" value: YES];
[json UpdateBool: @"profileDetails.privacyInfo.autoEnrollLoyaltyProgram" value: NO];
[json UpdateBool: @"profileDetails.privacyInfo.allowPhone" value: YES];
[json UpdateBool: @"profileDetails.privacyInfo.allowSMS" value: YES];
[json UpdateBool: @"profileDetails.privacyInfo.allowEmail" value: YES];
[json UpdateBool: @"profileDetails.privacyInfo.optInMailingList" value: YES];
[json UpdateBool: @"profileDetails.privacyInfo.optInMarketResearch" value: YES];
[json UpdateBool: @"profileDetails.privacyInfo.optInThirdParty" value: YES];
[json UpdateBool: @"profileDetails.privacyInfo.optInAutoEnrollmentMember" value: YES];
[json UpdateBool: @"profileDetails.privacyInfo.optInPhone" value: YES];
[json UpdateBool: @"profileDetails.privacyInfo.optInSms" value: YES];
[json UpdateBool: @"profileDetails.privacyInfo.optInEmail" value: YES];
[json UpdateNewObject: @"profileDetails.taxInfo"];
[json UpdateString: @"profileDetails.statusCode" value: @"Active"];
[json UpdateString: @"profileDetails.requestForHotel" value: @"{{HotelId}}"];
[json UpdateBool: @"profileDetails.markAsRecentlyAccessed" value: YES];
[json UpdateString: @"profileDetails.profileType" value: @"Guest"];
[json UpdateNewArray: @"profileIdList"];

[http SetRequestHeader: @"Content-Type" value: @"application/json"];
[http SetRequestHeader: @"x-app-key" value: @"{{AppKey}}"];
[http SetRequestHeader: @"x-hotelid" value: @"{{HotelId}}"];
// Adds the "Authorization: Bearer <access_token>" header.
http.AuthToken = @"<access_token>";

CkoHttpResponse *resp = [http PostJson3: @"https://domain.com/crm/v1/profiles" contentType: @"application/json" json: json];
if (http.LastMethodSuccess == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

NSLog(@"%d",[resp.StatusCode intValue]);
NSLog(@"%@",resp.BodyStr);

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