On success reponse from Async Await API call,how to do one moreAPI call with request params

Viewed 28

const activeStepOne = async () => {

const formData = new FormData();
formData.append("file", csvData);
formData.append("filetype", fileType);
let postData = {
  filetype: fileType,
  file: csvData,
};
let getData = {
  filetype: fileType,
  file: csvData.name,
};
sessionStorage.setItem("uploadDetails", JSON.stringify(getData));
const requestOptions = {
  method: "POST",
  body: formData,
};

let responseData = await callAPI(`${API_URL}/fileupload`, requestOptions);
if (responseData?.status) {
  setDisable(true);
  setActiveStep((prevActiveStep) => prevActiveStep + 1);
  setIsLoading(false);
  setShowSnackbar(false);
  setSnackbarType("success");
  setSnackbarMessage("File uploaded successfully!");
  setShowSnackbar(true);
} else {
  setStatusCode(true);
  setIsLoading(false);
  setSnackbarMessage(
    "Error uploading file. Please try again with proper data."
  );
  setSnackbarType("error");
  setShowSnackbar(true);
}
console.log(responseData);

};

Iam doing here API call ,Once i get success response i want to do one more API call with below request params

{"Upload":"True", "Name":"Bolzen", "WorkflowName":"file1.csv", "UserId":1}

1 Answers

Not sure, if I understand the challenge you're having. You could initiate another request like this:

let responseData = await callAPI(`${API_URL}/fileupload`, requestOptions);
if (responseData?.status) {
  let responseData = await callAPI(`${API_URL}/endpoint`, { method: "POST", body: {"Upload":"True", "Name":"Bolzen", "WorkflowName":"file1.csv", "UserId":1} };
}

I tried to infer the usage of callAPI.

I'd suggest to use const instead of let if the value won't be changed, though.

Related