Help making external API request from server actions is throwing an Error.
Unanswered
Satin Angora posted this in #help-forum
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 Angora 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.
are you able to open
https://dummyjson.com/products with your browser?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 terminalSatin AngoraOP
sure
It does fetch data
@Satin Angora 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.
try to remove
'use server', you don't need server action for fetching data in the server componentand could you try
curl https://jsonplaceholder.typicode.com/posts in the terminal of vscodeSatin 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 errorSatin 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 Angora 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 .
could you try this url
https://jsonplaceholder.typicode.com/postsSatin 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
?
?I don't know. This is a weird bug. 
