So I have these functions and passing the value into another function works fine with regular javascript functions. My problem is passing this same value through post request on express.
Here is the regular JS functions without express that currently works
Inside of one file called quote.js I have this code that generates a random ID
export const response = await client.deliveryQuote({
external_delivery_id: uuidv4(),
});
console.log(response);
Then in another file called quoteNew.js I have this code which receives the value from the quote.js file and gets the external_delivery_id value
import { response } from "./quote.js";
const response1 = client
.deliveryQuoteAccept(response.data.external_delivery_id)
.then((resp) => {
console.log(resp);
})
.catch((err) => {
console.log(err);
});
console.log(response1);
So this code above works perfectly fine when getting the external_delivery_id value.
Now what I want to do is replicate this same thing except using express.
So in my server.js file I have this code. When I add this code response.data.external_delivery_id into the deliveryQuoteAccept it doesn't work the same and says response is not defined since it can't access the response value from the app.post get-quote function
Right now it just says response is not defined when passing it into the 2nd app.post function
app.post("/get-quote", async (req, res) => {
const response = await client.deliveryQuote({
external_delivery_id: uuidv4(),
});
res.send(response);
});
app.post("/accept-quote", (req, res) => {
const response1 = client
.deliveryQuoteAccept(response.data.external_delivery_id) //response is not defined
.then((response) => {
console.log("Delivery Created", response);
})
.catch((err) => {
console.log(err);
});
console.log("ACCEPT", response1);
})
How do I access the response value from the first app.post function and transfer it into my 2nd app.post function in this section
const response1 = client
.deliveryQuoteAccept(I NEED THE EXTERNAL_DELIVERY_ID VALUE HERE)