OrderCloud Environment / Permission Setup for API Calls with flow diagrams
While invoking the product list API from both asp.net core SDK and JavaScript SDK (refer my earlier blogs), I realised that the API Client must be setup with proper relationships and permissions. Else, the invocation failed with different errors based on the missing relationship/permission. In this blog post, although I cover the use case for product browsing this setup should be similar for all API calls except the role assignment. I have interspersed the blog with flow diagrams to demonstrate the code flow and possible reason for failure.
Since I cover the use case for product browsing, I take the buyer/buyer user into account. So, in this case, the buyer user is the api client context user. You need to add the relevant user and permission based on your scenario.
- Create Market Place
- Create an API Client
- Create a Buyer
- Create a Buyer User
- Create a Security Profile
- Create a Security Profile Assignment
- Assign Default Context User to API Client
Create Marketplace:
In OrderCloud Portal, create New Marketplace:
Just add the mandatory field, which is Marketplace Name:
New Marketplace created successfully with auto-generated id:
Also, if you have multiple market places, ensure that the correct marketplace is selected as the context:
Note that you can add multiple tabs with the + button and switch the marketplace context for each tab!
Create an API Client
Next, an API Client is needed within the marketplace:
POST /apiclients
Create New API Client with unique name and in an enabled state:
Since we want to allow product browsing , enable the anonymous buyer option:
The request must look something like this:
Click the Create the API Client button and a API Client Id is generated:
To attach the API Client to a default context user, a user must be created first
Before that, a buyer must be created:
POST Create a new buyer
POST /buyers
Ensure Active toggle is enabled.
Next, create a new buyer user for the buyer:
POST Create a new user
POST /buyers/{buyerID}/users
POST Response:
In case if you already assigned the context user to the API Client and, if you execute the code, you will get the forbidden error:
Create a new Security Profile:
POST /securityprofiles
Ensure to choose the appropriate roles needed for the user(s).
Next, link the API Client Id, User Id and Buyer Id:
POST Create or update a security profile assignment
POST securityprofiles/assignment
Back in the API Client, assign the buyer user as default context user and save changes:
Also, ensure that the active toggle is enabled for the product else, use the PUT request:
So, your code must reflect the above url:
Else, the api call will throw an invalid_client error.
Comments
Post a Comment