- Goal: Hey folks,
Here i'm trying to hit the multiple api's one by one
`let contractsMap = new Map();
contractsMap.set(9716, "eligibility_AHC");
contractsMap.set(10389, "eligibility_Investigations");
contractsMap.set(10386,"eligibility_HealthCheck");
contractsMap.set(10846,"eligibility_OnlineConsultation");
contractsMap.set(10401,"eligibility_Consultation");
let whitelistMap = new Map();
whitelistMap.set(9716, "ms_AHC_Include");
whitelistMap.set(10389, "ms_Invs_Include");
whitelistMap.set(10386,"ms_HealthCheck_Include");
whitelistMap.set(10846,"ms_OnlineConsultation_Include");
contractsMap.set(10401,"ms_Consultation_Include");
let blacklistMap = new Map();
blacklistMap.set(9716, "ms_AHC_Exclude");
blacklistMap.set(10389, "ms_Invs_Exclude");
blacklistMap.set(10386,"ms_HealthCheck_Exclude");
blacklistMap.set(10846,"ms_OnlineConsultation_Exclude");
contractsMap.set(10401,"ms_Consultation_Exclude");
// Function to execute contracts API iteratively
const executeContractsAPI = async () => {
// Define the number of iterations for the contracts API
const contractIterations = contracts.value;
console.log("Contracts started");
for (let i = 0; i < contractIterations.length; i++) {
const cid =contractIterations[i];
// const status = eligibility_AHC.value;
const status = contractsMap.get(cid).value;
console.log(status);
Execute contracts API for each iteration
const contractsData = await createEntityPolicyBucketContract.trigger({
additionalScope: { dynamic_contractids: cid,
eligibility_status: status
}
});
console.log(contractsMap.get(cid)); // undefined
// Execute items API five times for each contract iteration
// contractId , List of Item id
if(contractsMap.get(cid).value=="whitelist"){
await executeItemsAPI(cid,whitelistMap.get(cid).value);
}
else if(contractsMap.get(cid).value=="blacklist"){
await executeItemsAPI(cid,blacklistMap.get(cid).value);
}
}
};
// Function to execute items API multiple times
const executeItemsAPI = async (cid,items) => {
// Iterate for the specified number of item iterations
await items.forEach(item =>{
createBucketContractItems.trigger({
additionalScope: { item_cid: cid,
item_id: item
}
});
});
for (let i = 0; i < iterations; i++) {
Execute items API for each iteration
const itemsData = await retool.query['items_api'].trigger();
}
};
// Execute the contracts API iteratively
executeContractsAPI();
console.log("Completed");
`
- Steps: I want to achieve that
- trigger the contracts api once, wait for the response
- After contracts api response call the items API as list of times
- This process will continues upto list of contractIterations array in the code
-
Details: Now, i'm not able to pass the eligibility_status dynamically in the createEntityPolicyBucketContract (Contracts api).
-
Screenshots: