I have the following API call and a local activesubscribers = {}
variable
//Add Subscriber to the List
app.post("/AddSubscriber", (req, res) => {
const { Name, EmailAddress } = req.body;
request(
{
method: "POST",
uri: "https://website.json}",
headers: {
Authorization:
"Bearer" +
"+0znPsUJtRLLInRp",
},
body: JSON.stringify(Name, EmailAddress),
},
function (error, response, body) {
if (error) {
console.error(error);
}
const data = JSON.parse(body);
}
);
});
the response from the api looks like this :
{
"Results": [
{
"EmailAddress": "[email protected]",
"Name": "Person One",
}
]
}
what i want is to get the API’s response and store it to the activesubscribers = {}
variable so i can make a validation if the user already exists in req.body user data already exist. What i have tried so far is activesubscribers = JSON.parse(data) but im stuck.