Seed a New OrderCloud Environment

Seed a New OrderCloud Environment

OrderCloud allows you to seed a new environment to avoid the complex initialization it usually requires. In this blog post we will try to explain how you can achieve this and have a OC environment ready to go. So without further due, lets begin.

First, we need to access to the OrderCloud site and in the dashboard create a new marketplace

Set as region, whatever you need, in our case US-EAST, set the marketplace name and optionally a marketplace identifier

Click the create marketplace button and as soon as the creation process is done you will see your new empty OC environment created with its proper identifier if you did no set one. Remember the marketplace Id which we will use later in the seed process.

Now, we need to clone the latest repository from the OC HeadStart project that you can find it here in your local machine.

Then, open the Headstart.sln visual studio 2022 solution file to open the middleware API project which you can find it in the /src/Middleware folder and runs on the .NET Core 3.1 framework (Check you have the runtime installed in your machine, if not you can do it in Visual Studio).

When the VS solution opens, choose the Headstart.API project as the startup project and compile the solution.

Add an appsettings.json file to the Headstart.API project that have a Azure blob storage connection string, unfortunately for the moment you cannot seed a project without it.

{
  "StorageAccountSettings:ConnectionString": "DefaultEndpointsProtocol=CONNECTION_STRING",
  "StorageAccountSettings:BlobPrimaryEndpoint": "https://ENDPOINT.blob.core.windows.net/",
  "StorageAccountSettings:BlobContainerNameQueue": "queue",
  "StorageAccountSettings:BlobContainerNameCache": "cache",
  "StorageAccountSettings:BlobContainerNameExchangeRates": "currency",
  "StorageAccountSettings:BlobContainerNameTranslations": "ngx-translate"
}

Then, execute the project and If you see the swagger UI, it means that everything is working as expected.

Now, go to the environment seed section and then the seed endpoint.
Click the try it out button and send the JSON request with the environment that you want to seed. This is the JSON request with all the properties
{
  "Portal": {
    "Username": "string",
    "Password": "string"
  },
  "Marketplace": {
    "Environment": "Production",
    "Region": "string",
    "ID": "string",
    "Name": "string",
    "InitialAdmin": {
      "Password": "string",
      "Username": "string"
    },
    "EnableAnonymousShopping": true,
    "AnonymousShoppingBuyerID": "string",
    "MiddlewareBaseUrl": "string",
    "WebhookHashKey": "string",
    "Suppliers": [
      {
        "xp": {
          "Description": "string",
          "SupportContact": {
            "Name": "string",
            "Email": "string",
            "Phone": "string"
          },
          "SyncFreightPop": true,
          "ApiClientID": "string",
          "Currency": "CAD",
          "ProductTypes": [
            "Standard"
          ],
          "CountriesServicing": [
            "string"
          ],
          "BuyersServicing": [
            "string"
          ],
          "Categories": [
            {
              "ServiceCategory": "string",
              "VendorLevel": "string"
            }
          ],
          "NotificationRcpts": [
            "string"
          ],
          "FreeShippingThreshold": 0,
          "Image": {
            "Url": "string",
            "ThumbnailUrl": "string",
            "Tags": [
              "string"
            ]
          }
        },
        "ID": "string",
        "Name": "string",
        "Active": true,
        "DateCreated": "2022-08-10T06:28:35.017Z",
        "AllBuyersCanOrder": true
      }
    ],
    "Buyers": [
      {
        "xp": {
          "MarkupPercent": 0,
          "URL": "string"
        },
        "ID": "string",
        "Name": "string",
        "DefaultCatalogID": "string",
        "Active": true,
        "DateCreated": "2022-08-10T06:28:35.017Z"
      }
    ]
  }
}

But, we do not need the whole request, below you have a smaller version of the JSON request with only the basic data

{
  "Portal": {
    "Username": "PORTAL_USER_NAME",
    "Password": "PORTAL_PASSWORD"
  },
  "Marketplace": {
    "Environment": "Sandbox",
    "Region": "Us-East",
    "ID": "IE2pn1ftYeoP3bPK",
    "InitialAdmin": {
      "Password": "ADMIN_PASSWORD",
      "Username": "ADMIN_USER_NAME"
    },
    "EnableAnonymousShopping": true,
    "MiddlewareBaseUrl": "http://demodomain.ddns.net",
    "WebhookHashKey": "ABCTUYZRNCBD2LZ"
  }
}

The fields we included in the request are explained in the table below:

FieldDescription
Portal / UsernameOC Portal user name that you use to log in
Portal / PasswordOC Portal password that you use to log in
Marketplace / EnvironmentThe environment of the current marketplace: Sandbox, Staging or Production
Marketplace / RegionRegion of the current marketplace: Us-East, etc.
Marketplace / IDThe marketplace id of the current marketplace
Marketplace / InitialAdmin / UsernameMarketplace initial admin user name
Marketplace / InitialAdmin / PasswordMarketplace initial admin password
Marketplace / EnableAnonymousShoppingSet the anonymous shopping future for your marketplace
Marketplace / MiddlewareBaseUrlThe URL of the middleware API, it should be something accessible because integration events and senders use it.
Marketplace / WebhookHashKeyAn additional security layer that will be used when reaching webhooks in the middleware

If everything is correct you will receive a 200 http response code with a JSON response similar to the one below:

{
  "Comments": "Success! Your environment is now seeded. The following clientIDs & secrets should be used to finalize the configuration of your application. The initial admin username and password can be used to sign into your admin application",
  "MarketplaceName": "ExampleBlog",
  "MarketplaceID": "IE2pn1ftYeoP3bPK",
  "OrderCloudEnvironment": "Sandbox",
  "ApiClients": {
    "Middleware": {
      "ClientID": "GUID_MIDDLEWARE_CLIENT_ID",
      "ClientSecret": "MIDDLEWARE_CLIENT_SECRET"
    },
    "Seller": {
      "ClientID": "GUID_SELLER_CLIENT_ID"
    },
    "Buyer": {
      "ClientID": "GUID_BUYER_CLIENT_ID"
    }
  },
  "Success": true,
  "Exception": null
}

And that is it. You now have a seeded OC environment with basic data such as: a default buyer, buyer users, buyer groups, buyer addresses, catalog, admin users, integration events, message senders, API clients and security profiles which will allow you to easily work with the Headstart application. If you have any questions or suggestions please let me know in the comments. I hope it can help someone and as always keep learning !!!

Written by:

Jorge Cardenas

Developer with several years of experience who is passionate about technology and how to solve problems through it.

View All Posts

1 COMMENT

Leave a Reply