Help with 3rd party api call in Actions
So i am trying to reach clerk's backend api in a convex action. The action needs a node package so i am using the
"use node"
at the top of the document where i am defining the action.
So the issue now is, the call works just fine but when i return the result of the call, Convex throws an error. However, when i console log the result of the call, it returns the data just as expected.
The error i am getting is as follows:7 Replies
This error message says that you can't store a
_User
object
try calling JSON.stringify() on it to get something you can store
is not a supported Convex typeYou can't store instance of classes in the Convex database, only plain objects
Thank you so much. That worked! ✅
@DaReal I'm trying to reach several apis to allow users to integrate specific apps trough the login process. Did you use the Convex Action Function for this one? My tech stack is NextJs and Typescript.
@Ulrich Yes! i did use the Convex action.
But when working with Clerk and trying to reach their backend api, use the node sdk and also use the
"use node"
declarative at the top of your action file.
So you have to have a separate file for such actions. For me, I just used the same file to store all my 3rd party api calls for clerk because they all use the node sdk.
I hope i answered your question though.
Also, can you give more context on what you mean by integrating specific apps through the login process?Hi @DaReal thanks for your prompt response and help. I finally done what I was looking. I wanted to allow users to sign into an external apps through an API and then save the token in Convex. However, I'm facing a new issue.
I cannot make a simple api request from Convex to this same web-app thought their API .
Here is an exemple of the code
CODE WITH THE CONVEX ACTION FUNCTION
import { action } from "../_generated/server";
export const fetcher = action({
args: {},
handler: async () => {
try {
const response = await fetch("https://my-api.com/v2/order", {
method: "GET",
headers: {
"accept": "application/json",
"Authorization": "Bearer dsjkfsdjkhfdh"
},
});
if (!response.ok) {
throw new Error(
Error fetching: ${response.statusText}
);
}
const data = await response.json();
return data;
} catch (error) {
console.error("Failed to fetch campaigns", error);
throw new Error("Failed to fetch campaigns");
}
}
});
STEP 2
I used useAction and api to call this CONVEX ACTION into my app page.
Then I used useEffect to make sure that this will run once and then fech the all the needed data from this external website trought this api.
When I run the same api with the same info in the terminal it works like a charm but it doesn't work with Convex. Even if it's really basic.
cc: @ballingt
@DaReal @ballingt Problem solved. The returned JSON was a nested object so I needed to add "rows" to access the correct data.Hello! I'm new to convex and I need help to send mail using nodemailer and Gmail.