Chilkat Online Tools

Objective-C / ORACLE Hospitality OPERA Cloud REST API Workflows / Update the guest profile with new contact details

Back to Collection Items

#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <CkoStringBuilder.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": {
//     "addresses": {
//       "addressInfo": [
//         {
//           "address": {
//             "addressLine": [
//               "2640 Golden Gate Parkway",
//               "Suite 300",
//               "",
//               ""
//             ],
//             "cityName": "Naples",
//             "postalCode": "34105",
//             "state": "FL",
//             "language": "E",
//             "type": "HOME",
//             "typeDescription": "Home Address",
//             "primaryInd": true
//           }
//         }
//       ]
//     },
//     "telephones": {
//       "telephoneInfo": [
//         {
//           "telephone": {
//             "phoneTechType": "PHONE",
//             "phoneUseType": "MOBILE",
//             "phoneUseTypeDescription": "Mobile Phone Number",
//             "phoneNumber": "+1 415 555 0101",
//             "primaryInd": true,
//             "orderSequence": "1"
//           }
//         }
//       ]
//     },
//     "statusCode": "ACTIVE",
//     "markForHistory": false,
//     "hasCommission": false
//   }
// }

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"profileDetails.addresses.addressInfo[0].address.addressLine[0]" value: @"2640 Golden Gate Parkway"];
[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: @"Naples"];
[json UpdateString: @"profileDetails.addresses.addressInfo[0].address.postalCode" value: @"34105"];
[json UpdateString: @"profileDetails.addresses.addressInfo[0].address.state" value: @"FL"];
[json UpdateString: @"profileDetails.addresses.addressInfo[0].address.language" value: @"E"];
[json UpdateString: @"profileDetails.addresses.addressInfo[0].address.type" value: @"HOME"];
[json UpdateString: @"profileDetails.addresses.addressInfo[0].address.typeDescription" value: @"Home Address"];
[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: @"MOBILE"];
[json UpdateString: @"profileDetails.telephones.telephoneInfo[0].telephone.phoneUseTypeDescription" value: @"Mobile Phone Number"];
[json UpdateString: @"profileDetails.telephones.telephoneInfo[0].telephone.phoneNumber" value: @"+1 415 555 0101"];
[json UpdateBool: @"profileDetails.telephones.telephoneInfo[0].telephone.primaryInd" value: YES];
[json UpdateString: @"profileDetails.telephones.telephoneInfo[0].telephone.orderSequence" value: @"1"];
[json UpdateString: @"profileDetails.statusCode" value: @"ACTIVE"];
[json UpdateBool: @"profileDetails.markForHistory" value: NO];
[json UpdateBool: @"profileDetails.hasCommission" value: NO];

[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>";

CkoStringBuilder *sbRequestBody = [[CkoStringBuilder alloc] init];
[json EmitSb: sbRequestBody];

CkoHttpResponse *resp = [http PTextSb: @"PUT" url: @"https://domain.com/crm/v1/profiles/{{ProfileId}}" textData: sbRequestBody charset: @"utf-8" contentType: @"application/json" md5: NO gzip: NO];
if (http.LastMethodSuccess == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

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

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-H "x-app-key: {{AppKey}}"
	-H "x-hotelid: {{HotelId}}"
	-d '{
  "profileDetails": {
    "addresses": {
      "addressInfo": [
        {
          "address": {
            "addressLine": [
              "2640 Golden Gate Parkway",
              "Suite 300",
              "",
              ""
            ],
            "cityName": "Naples",
            "postalCode": "34105",
            "state": "FL",
            "language": "E",
            "type": "HOME",
            "typeDescription": "Home Address",
            "primaryInd": true
          }
        }
      ]
    },
    "telephones": {
      "telephoneInfo": [
        {
          "telephone": {
            "phoneTechType": "PHONE",
            "phoneUseType": "MOBILE",
            "phoneUseTypeDescription": "Mobile Phone Number",
            "phoneNumber": "+1 415 555 0101",
            "primaryInd": true,
            "orderSequence": "1"
          }
        }
      ]
    },
    "statusCode": "ACTIVE",
    "markForHistory": false,
    "hasCommission": false
  }
}'
https://domain.com/crm/v1/profiles/{{ProfileId}}

Postman Collection Item JSON

{
  "name": "Update the guest profile with new contact details",
  "request": {
    "auth": {
      "type": "bearer",
      "bearer": [
        {
          "key": "token",
          "value": "{{Token}}",
          "type": "string"
        }
      ]
    },
    "method": "PUT",
    "header": [
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "value": "application/json",
        "type": "text"
      },
      {
        "key": "x-app-key",
        "value": "{{AppKey}}",
        "type": "text"
      },
      {
        "key": "x-hotelid",
        "value": "{{HotelId}}",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"profileDetails\": {\n    \"addresses\": {\n      \"addressInfo\": [\n        {\n          \"address\": {\n            \"addressLine\": [\n              \"2640 Golden Gate Parkway\",\n              \"Suite 300\",\n              \"\",\n              \"\"\n            ],\n            \"cityName\": \"Naples\",\n            \"postalCode\": \"34105\",\n            \"state\": \"FL\",\n            \"language\": \"E\",\n            \"type\": \"HOME\",\n            \"typeDescription\": \"Home Address\",\n            \"primaryInd\": true\n          }\n        }\n      ]\n    },\n    \"telephones\": {\n      \"telephoneInfo\": [\n        {\n          \"telephone\": {\n            \"phoneTechType\": \"PHONE\",\n            \"phoneUseType\": \"MOBILE\",\n            \"phoneUseTypeDescription\": \"Mobile Phone Number\",\n            \"phoneNumber\": \"+1 415 555 0101\",\n            \"primaryInd\": true,\n            \"orderSequence\": \"1\"\n          }\n        }\n      ]\n    },\n    \"statusCode\": \"ACTIVE\",\n    \"markForHistory\": false,\n    \"hasCommission\": false\n  }\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{HostName}}/crm/v1/profiles/{{ProfileId}}",
      "host": [
        "{{HostName}}"
      ],
      "path": [
        "crm",
        "v1",
        "profiles",
        "{{ProfileId}}"
      ]
    }
  },
  "response": [
  ]
}