0

What Im trying to do is use the string that is sent from the frontend as the key to retrieve the information I need. The problem part is the let answer, when I use it, I receive undefined. But if if I use "Apple.com" instead for example, the fetch works and I receive the information I want.

My code so far is:

app.post('/todo', function(req, res){

//here we use JSON.stringify to make the object a string
let answer = JSON.stringify(req.body.name);
console.log(answer);

 //here is where we make the api call to get info on the stock
fetch('https://api.fullcontact.com/v3/company.enrich',{
    method: 'POST',
    headers: {
        "Authorization": "Bearer JTm3BBNMqo7xu9PHoG35x8NeohUNfuXl"
    },
    body: JSON.stringify({
        "domain": answer
    })
}).then(function(res) {
    return res.json();
}).then(function(json){
    console.log(json.name);
});

and the html code is this:

<form action="/todo" method="POST">
    <input type="text" name="name" class="search" placeholder="todo">
    <button type="submit" id="searchButton">submit</button>
</form>

0 Answers0