Next.js Discord

Discord Forum

Help making external API request from server actions is throwing an Error.

Unanswered
Satin Angora posted this in #help-forum
Open in Discord
Satin AngoraOP
I'm trying to make an api request to https://dummyjson.com/products in server action then later call the action in a client component but it keeps on giving the error . I have attached code snaps and the error image, please help. Thanks.

23 Replies

Satin AngoraOP
Yes I can
@Satin Angora Yes I can
are you on windows/mac/wsl?
Satin AngoraOP
I'm on ubuntu
try curl https://jsonplaceholder.typicode.com/posts in the terminal
Satin AngoraOP
sure
It does fetch data
and could you try curl https://jsonplaceholder.typicode.com/posts in the terminal of vscode
Satin AngoraOP
My intention is to use server actions in client component. Attached is the updated component. So when I remove the 'use server', it works but on the client side. 'use client'
usually, it works with 'use server' but I have no idea why you get fetch error
Satin AngoraOP
Apparently it turns out that even trying to make an API request from next route handler using GET, it throws the same error. I have no idea what the issue is .
Satin AngoraOP
Let me try it
@Ray could you try this url `https://jsonplaceholder.typicode.com/posts`
Satin AngoraOP
Imagine it worked well with this URL , seemingly I have been troubleshooting the https://dummyjson.com/products api issue 😔
Thanks for your help.
@Nelson I tested your code. There is no error.
Satin AngoraOP
Do you have any configurations set? Because I'm curious why it did work for you. It works with Jsonplaceholder API but fails with other APIs.
@Satin Angora No. I don't do anything extra. I just copied the code from your image. And paste it into my app that was created with pnpm create next-app.
@Nelson <@1157038449686220952> No. I don't do anything extra. I just copied the code from your image. And paste it into my app that was created with `pnpm create next-app`.
Satin AngoraOP
Maybe I have to use a different machine and create a new project to find out if it could be my PC but wait is that even making sense :thinq: ?
I don't know. This is a weird bug. :lolsob: