#I get Undefined in console even though i should get a link

15 messages · Page 1 of 1 (latest)

formal estuaryBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

      🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in <id:customize>

      ✅ You can mark a message as the answer for your post with `Right click -> Apps -> Mark Solution`
      (if you don't see the option, try refreshing Discord with Ctrl + R)
gusty laurel
#

Did you try to console.log(response.data)?
What do you get if you do that?

#

You probably just need to add .then((r) => r.json()) after .post but before .then

#

Like this:

const handleBuyClick = () => {
    axios
      .post("http://localhost:3000/api/fruit/buy", {
        line_items: [{
          price_data: {
            currency: 'eur',
            product_data: {
              name: fruit.type,
            },
            unit_amount: fruit.price,
          },
          quantity: quantity,
        }]
      })
      .then((r) => r.json())
      .then((response) => {
        const url = response.data.url;
        // router.push(${url});
        console.log(url);
      })
      .catch((error) => {
        console.log(error.response);
      });
  };
#

oh

#

also I just noticed

#

this is not how you send data from routes

#

in your backend you have to do response.status(200).json(YourDataHere) instead of NextResponse.json()

solar cradle
#

either way i get undefined

#

i use nextResponse because in my other route this was the only way it worked

#

i think the problem is this part line_items: [NextRequest.body.line_items[0]], "NextRequest"

gusty laurel
#

yeah :/ change that from NextRequest to just request

solar cradle
#

error TypeError: response.json is not a function :Dd

gusty laurel
#

then try without that one line

solar cradle
#

i need that line