After handling a large Sitecore OrderCloud project, I sifted through my leftover PowerShell fragments and started a reusable tool set. As a senior architect at a Sitecore OrderCloud development agency, I thought I would share this information with you all!
For captions, click "CC" within the video player. To read the transcript of this episode, click the transcript link within the description of the video on YouTube.
OrderCloud’s Seed Mechanism’s Key Limitations
First, the biggest need we had was pushing data from a sandbox marketplace to our production marketplace. I wrongly assumed the OrderCloud seed mechanism was the tool to export/import, and found this only works for seeding new sandboxes. It won't work for existing, production (or staging) scenarios. So, I ventured to leverage the seed file format and script a process to allow deploying it to any existing marketplace.
Utilizing PowerShell Scripts for OrderCloud Data Management
Second, a recurring need was pulling quick reports from OrderCloud. Early in the project, the portal console was sufficient to quickly check test data. However, once lists grew over the max 100-page size limit and as we needed to survey nested data like variants over the whole marketplace, we quickly turned to PowerShell scripts to pull the data we needed to see. Finally, as we worked through product import integrations we needed quick ways to purge data sets.
OrderCloud Developer’s Toolbox
Putting these data management solutions all together, we now have a set of complimentary Sitecore OrderCloud Data Management tools. The PowerShell Script is designed to assist OrderCloud projects with a set of tools to report, export, import, and bulk delete data.
- Report: rapid data extraction into CSV
- Export: executing the OrderCloud seed export
- Import: deploy OrderCloud seed file to any marketplace!
- Delete: quickly purge data
This Sitecore Ordercloud developer tool box is available as a single PowerShell script on GitHub to assist OrderCloud projects with a set of tools to report, export, import, and bulk delete data.
Decision Point: Data Retrieval Strategy
Which way should we read data from the source marketplace?
The two options were:
- Iterate and read with GET calls on the fly.
- Run full seed export, then iterate it with some scripted process.
I opted for B, for essentially two reasons:
- Reliability
- Having a static file will avoid interference issues caused by users or systems modifying data mid sync
- Having a static file will be consistent across retries if needed
- Having offline copy reduces connectivity/latency concerns
- Able to run seed validate to verify all is in tact
- Flexibility
- Able to edit data before importing; option to remove records to skip
- Able to fill in redacted data - easier to manage secret keys per environment
- Can create and reuse pre-configured accelerator seeds
- Useful to have full export as searchable text in one file
There was also an option to use POST or PUT calls. PUT was favored, allowing seamless re-runs and playing nice with any existing records, avoiding unwanted partial update cases.
Navigating OrderCloud Implementation Challenges
A few challenges popped up during the OrderCloud implementation:
- API client IDs
- Discovered API Client IDs must be unique across all marketplaces. Those are the only non-writeable IDs. So, I created a seamless lookup by name to sync across marketplaces.
- Order matters
- Needed to handle the order of dependencies to avoid 404 errors so any referenced ID was already imported.
- Variants
- Can't create variants individually. Needed to loop products (with specs already defined) and call GenerateVariants first.
- Also discovered an issue that if source system used writeable IDs for variants then generated IDs won't match, so needed to match those by same spec options.
- Nested objects
- Various entities are nested under other types, such as under buyers or under products. Interacting with the sub types needed a level of sophistication.
- Also added caching layer to limit redundant fetching of parent types. Cache is cleared at the end of each tool to be mindful that changes can occur outside the tool, allowing it to be fresh for the next tool.
While it was tedious to script out all the OC object mappings, and a lot to test, this was a fun and rewarding little project. The OrderCloud API is so slick to use and performs so quickly. Very impressive.
Partner with a Top Sitecore Development Agency
Americaneagle.com is proud to be a top Sitecore solution partner with more than 10 years of experience providing support and website development services to clients in all industries. As a Sitecore Platinum Implementation and Hosting Partner, we provide a wide variety of Sitecore development services, some of which include enterprise implementations, version upgrades, solution audits, hosting and migrations, and more. We’re dedicated to helping your business succeed with Sitecore and are confident in our ability to help you achieve meaningful results. For more information about our Sitecore services, OrderCloud consulting, or to keep up with us at Sitecore conferences, contact us today.