Skip to content
Advertisement

How to Display Value Created from API Onto My Browser?

So I am working with this API and it auto calculates the delivery fee based on the address you input.

Here’s the API docs I am using https://developer.doordash.com/en-US/api/drive#operation/DeliveryQuote

So when I add my values to my form and get my data, it logs the fee in my console like this

enter image description here

My issue is how do I get this value from the data field?

I tried to do

 const response = await client.createDelivery(
      {
        order_value: req.body.item1,
        fee: fee,
        tip: req.body.item1,
      },
      console.log(fee)
    );

    console.log(response);

    res.send(response);
  }
 )

But it says fee is not defined?

I also tried fee: "" and that doesn’t work either.

I even put console.log(data.fee) and it says data is not defined

My last attempt I change it to console.log(response.fee) and it still showed undefined in the console?

How do I even get the fee value to console.log?

Note I am using express and for my tip value I have my input form named “item1” so I can access it by saying req.body.item1 to get that value

However, for the fee value its auto generated by the API, so I can’t change it or update it manually myself.

Advertisement

Answer

Try using

console.log(response.data.fee)

And I am not sure what your client.createDelivery does. If it sends response, then you need to display it like

const response = await client.createDelivery(
  {
    order_value: req.body.item1,
    fee: fee,
    tip: req.body.item1,
  },
  console.log(fee)
).then((res) => res.json()).then((resData) => console.log(resData.data.fee));
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement