Sitecore OrderCloud Documentation

docs

Portal login

Using Extended Properties

Published by Rob Watt on November 9, 2015

The reality of all enterprise platforms is the need to customize the data model. To accommodate this, OrderCloud designed a property called Extended Properties (XP) to allow enterprise customization of the OrderCloud data model. OrderCloud exposes the xp property on most resources allowing you to build a JSON object containing your custom properties. The JSON object can be as complex and deeply-nested as necessary. Additionally, the xp property is available for filtering, sorting and searching in all list endpoints. Extended Properties allows you to overcome platform rigidity. To optimize the use of our data model, and to help you fully implement your B2B scenarios, we created a schema-less solution with xp and exposed it on virtually every API resource. We may not have Product.YourSpecialDataPoint, but we do have Product.xp.YourSpecialDataPoint.

What is XP?

The entire xp object must be 8000 bytes or less and must be a valid JSON object. Any key-value pairs of numbers, strings, booleans, arrays, and even other objects can be used.

Note, XP should be consistently typed per object. This means if you add a custom property specialField on User and store a string value, every other User should have specialField populated with a string or be null. If you create a User later where specialField stores an nested object instead, you'll want to go back an update all your Users or risk latent errors interacting with the API.

This is very similar to how you might think about creating your own database tables, not all rows needs to have the same values optionally populated, but the structure needs to be consistent with XP for each object type.

Adding XP

Let's say one of the requirements for your solution includes storing the age and gender of users. You can accomplish this by storing those data points in the user's xp. If you do not include JSON, xp will be set to null by default on all parent objects. To declare xp, simply replace the null value with the valid JSON.

API Reference: Create a new user

POST https://api.ordercloud.io/buyers/{buyerID}/users HTTP/1.1
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...
Content-Type: application/json; charset=UTF-8

  {
    "Username": "janesmith",
    "Password": "test12345",
    "FirstName": "Jane",
    "LastName": "Smith",
    "Email": "jsmith@company.com",
    "Phone": "555-555-5555",
    "TermsAccepted": null,
    "Active": true,
    "xp": {
      "Gender": "Female",
      "Age" : 26
    },
    "AvailableRoles": [],
    "DateCreated": "2019-06-04T20:35:36.38+00:00",
    "PasswordLastSetDate": "2019-07-12T00:03:58.28+00:00"
  }

Nesting XP

Let's say requirements have shifted and the solution now requires the ability to store information about the user's employment details, specifically job title and department. This can easily be accomplished using nested objects within xp.

API Reference: Create or update a user

PUT https://api.ordercloud.io/buyers/{buyerID}/users/{userID} HTTP/1.1
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...
Content-Type: application/json; charset=UTF-8

  {
    "Username": "janesmith",
    "Password": "test12345",
    "FirstName": "Jane",
    "LastName": "Smith",
    "Email": "jsmith@company.com",
    "Phone": "555-555-5555",
    "TermsAccepted": null,
    "Active": true,
    "xp": {
      "Gender": "Female",
      "Age" : 26,
      "EmploymentDetails" : {
        "Position": "Developer",
        "Department": "Tech"
      }
    },
    "SecurityProfileID": "FullAccess",
    "AvailableRoles": [],
    "DateCreated": "2019-06-04T20:35:36.38+00:00",
    "PasswordLastSetDate": "2019-07-12T00:03:58.28+00:00"
  }

Modifying XP

Now let's say Jane Smith receives a promotion. To update her job title we can use PATCH to modify the relevant data. Instead of sending the entire user object, we can send the xp key and the object that we want to update, the other xp (gender and age) will persist.

API Reference: Partially update a user

PATCH https://api.ordercloud.io/buyers/newbuyer/users/userID HTTP/1.1
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...
Content-Type: application/json; charset=UTF-8

  {
    "xp": {
      "EmploymentDetails" : {
        "Position": "Senior Developer",
        "Department": "Tech"
      }
    }
  }

Deleting XP

The only way to remove a specific xp from your resource is to use the Update (PUT) method. First GET the resource, then copy the response body returned, paste it into your PUT request and omit the xp key/value you wish to remove. Alternatively, if you don't need it actually deleted, you are able to set any xp's value to null. In the example below, we're removing the "Age" xp from this user.

API Reference: Get a single user

GET https://api.ordercloud.io/buyers/{buyerID}/users/{userID} HTTP/1.1
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...
Content-Type: application/json; charset=UTF-8

  {
    "Username": "janesmith",
    "Password": "test12345",
    "FirstName": "Jane",
    "LastName": "Smith",
    "Email": "jsmith@company.com",
    "Phone": "555-555-5555",
    "TermsAccepted": null,
    "Active": true,
    "xp": {
      "Gender": "Female",
      "Age" : 26,
      "EmploymentDetails" : {
        "Position": "Developer",
        "Department": "Tech"
      }
    },
    "AvailableRoles": [],
    "DateCreated": "2019-06-04T20:35:36.38+00:00",
    "PasswordLastSetDate": "2019-07-12T00:03:58.28+00:00"
  }

Then, use the response body from the request above (without the xp you wish to remove).

API Reference: Create or update a user

PUT https://api.ordercloud.io/buyers/{buyerID}/users/{userID} HTTP/1.1
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...
Content-Type: application/json; charset=UTF-8

  {
    "Username": "janesmith",
    "Password": "test12345",
    "FirstName": "Jane",
    "LastName": "Smith",
    "Email": "jsmith@company.com",
    "Phone": "555-555-5555",
    "TermsAccepted": null,
    "Active": true,
    "xp": {
      "Gender": "Female",
      "EmploymentDetails" : {
        "Position": "Developer",
        "Department": "Tech"
      }
    }
  }

Filtering on XP

Not only can xp be used to extend the functionality of your application, but you can use filters to search for indexed xp values on any given resource. After all, how much benefit would xp provide if you couldn't query a subset of objects based on a specific xp value? All of the filtering capabilities that apply to regular values on OrderCloud objects also apply to xp values. This means you can search with all of the standard operators available (=,<,>). Below is an example of filtering for a deeply nested value in xp.

GET https://api.ordercloud.io/buyers/newbuyer/users?xp.EmploymentDetails.Department=Tech HTTP/1.1
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...
Content-Type: application/json; charset=UTF-8

Note how the dot (".") notation is used in the query string to filter on the specified deeply nested xp field. Check out the advanced querying guide to learn more.

Conclusion

xp is a very powerful feature to extend the capabilities of your application. It provides the flexibility developers need to meet challenging requirements, giving you the ability to provide a highly customized solutions. Head over to the API Console to try it for yourself!


Still have questions?
Ask in our Community Channel

Content Powered By
Sitecore Logo

© Copyright 2024, Sitecore OrderCloud®. All rights reserved.

Contact Us
Privacy Policy
Sitecore