January 18, 2022

Blog @ Munaf Sheikh

Latest news from tech-feeds around the world.

Update Object Store Values Using Object Store V2

Great post from our friends at Source link

Object Store in MuleSoft is used to store key-value pairs that we might need to preserve for future use. In this tutorial, we will learn how we can use Object Store V2 REST APIs to dynamically update the values present in our object store without making any changes to our code.

For a detailed explanation on Object Store and rest APIs please refer to official MuleSoft documentation.

Prerequisites: 

  1. An App that uses Object Store v2 and is deployed to CloudHub
  2. Access Token for the Anypoint Platform User

Access Object Store v2 API:

In order to access the REST APIs, we would need the following details:

  1. Organization ID
  2. Environment ID
  3. Base URL
  4. Access Token

Steps for Organization ID:

  1. Login to the Anypoint Platform.
  2. Click on Access Management:
  3. Inside Access Management, choose the organization tab and click on your desired business group.
  4. Add Business GroupCopy and save the Organization Id.

Organization ID

Steps for the Environment ID:

  1. Login to the Anypoint Platform.
  2. Click on API Manager.
  3. API ManagerMake sure you are in your desired Environment and then click on the “i” button to get Environment Information.
  4. Environment InformationCopy and save the Environment Id.

Environment ID

NOTE: Based on the region your app is deployed in you can get the Base URL from below:

Control Plane BASE_URL Region

U.S.

object-store-us-east-1.anypoint.mulesoft.com

US East (N. Virginia)

object-store-us-east-2.anypoint.mulesoft.com

US East (Ohio)

object-store-us-west-1.anypoint.mulesoft.com

US West (N. California)

object-store-us-west-2.anypoint.mulesoft.com

US West (Oregon)

object-store-ap-southeast-1.anypoint.mulesoft.com

Asia Pacific (Singapore)

object-store-ap-southeast-2.anypoint.mulesoft.com

Asia Pacific (Sydney)

object-store-ap-northeast-1.anypoint.mulesoft.com

Asia Pacific (Tokyo)

object-store-ca-central-1.anypoint.mulesoft.com

Canada (Central)

object-store-eu-central-1.anypoint.mulesoft.com

Europe (Frankfurt)

object-store-eu-west-1.anypoint.mulesoft.com

Europe (London)

object-store-eu-west-2.anypoint.mulesoft.com

Europe (Ireland)

object-store-sa-east-1.anypoint.mulesoft.com

South America (São Paulo)

Steps for the Access Token:

  1. Make a POST call to the below URL, by passing the username and password for your Anypoint platform user.

https://anypoint.mulesoft.com/accounts/login  

NOTE: The user must have Admin Access in order to retrieve the token.

Access Token2.  Copy and save the access token.

Retrieve the List of Object Stores

In order to retrieve the list of object stores in a particular Environment, make a GET call to the below URL using Postman:

https://BASE_URL/api/v1/organizations/ORG_ID/environments/ENV_ID/stores 

Change the values of BASE_URL, ORG_ID, and ENV_ID to the one retrieved earlier.

NOTE: Do pass the Access Token in headers as Type Bearer.

Store ID

On a similar line, you can use the below URL to get the list of partitions:

https://BASE_URL/api/v1/organizations/ORG_ID/environments/ENV_ID/stores/STORE_ID/partitions

Update Value for a Particular Key In Object Store

In order to update the value for a particular key, make a PUT call to the below URL and pass the body in the below format:

https://BASE_URL/api/v1/organizations/ORG_ID/environments/ENV_ID/stores/STORE_ID/partitions/PARTITION_ID/keys/KEY_ID

Change the values of BASE_URL, ORG_ID, ENV_ID, STORE_ID, and PARTITION_ID to the one retrieved earlier. Also, pass the KEY_ID (i.e. name of the key that you want to update).

BODY:

{

    "keyId" : "currentDate",

    "valueType" : "STRING",

    "stringValue" : "2021-12-30"

}

Body

This is how we can update the value of a key in Object Store v2 using REST APIs.

#Update #Object #Store #Values #Object #Store