DaReal
DaReal6mo ago

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
DaReal
DaRealOP6mo ago
[Request ID: 88be81b71f8c4892] Server Error
Uncaught Error: _User {"id":"RETRACTED","passwordEnabled":true,"totpEnabled":false,"backupCodeEnabled":false,"twoFactorEnabled":false,"banned":false,"createdAt":1721091887995,"updatedAt":1721100657301,"imageUrl":"RETRACTED","hasImage":false,"primaryEmailAddressId":"RETRACTED","primaryPhoneNumberId":"RETRACTED","primaryWeb3WalletId":null,"lastSignInAt":1721100657277,"externalId":null,"username":null,"firstName":"RETRACTED","lastName":"RETRACTED","publicMetadata":{},"privateMetadata":{},"unsafeMetadata":{},"emailAddresses":[{"id":"RETRACTED","emailAddress":"RETRACTED","verification":{"status":"verified","strategy":"admin","externalVerificationRedirectURL":null,"attempts":null,"expireAt":null,"nonce":null},"linkedTo":[]}],"phoneNumbers":[{"id":"RETRACTED","phoneNumber":"RETRACTED","reservedForSecondFactor":false,"defaultSecondFactor":false,"verification":{"status":"verified","strategy":"admin","externalVerificationRedirectURL":null,"attempts":null,"expireAt":null,"nonce":null},"linkedTo":[]}],"web3Wallets":[],"externalAccounts":[],"samlAccounts":[],"lastActiveAt":1721100657328,"createOrganizationEnabled":false} is not a supported Convex type (present at path .data[0] in original object {SAME DATA RETRACTED}). To learn about Convex's supported types, see https://docs.convex.dev/using/types.
at convexToJsonInternal (../../node_modules/convex/src/values/value.ts:339:6)
at <anonymous> (../../node_modules/convex/src/values/value.ts:322:4)
at convexToJsonInternal (../../node_modules/convex/src/values/value.ts:320:29)
at convexToJsonInternal (../../node_modules/convex/src/values/value.ts:350:15)
at convexToJson (../../node_modules/convex/src/values/value.ts:417:0)
[Request ID: 88be81b71f8c4892] Server Error
Uncaught Error: _User {"id":"RETRACTED","passwordEnabled":true,"totpEnabled":false,"backupCodeEnabled":false,"twoFactorEnabled":false,"banned":false,"createdAt":1721091887995,"updatedAt":1721100657301,"imageUrl":"RETRACTED","hasImage":false,"primaryEmailAddressId":"RETRACTED","primaryPhoneNumberId":"RETRACTED","primaryWeb3WalletId":null,"lastSignInAt":1721100657277,"externalId":null,"username":null,"firstName":"RETRACTED","lastName":"RETRACTED","publicMetadata":{},"privateMetadata":{},"unsafeMetadata":{},"emailAddresses":[{"id":"RETRACTED","emailAddress":"RETRACTED","verification":{"status":"verified","strategy":"admin","externalVerificationRedirectURL":null,"attempts":null,"expireAt":null,"nonce":null},"linkedTo":[]}],"phoneNumbers":[{"id":"RETRACTED","phoneNumber":"RETRACTED","reservedForSecondFactor":false,"defaultSecondFactor":false,"verification":{"status":"verified","strategy":"admin","externalVerificationRedirectURL":null,"attempts":null,"expireAt":null,"nonce":null},"linkedTo":[]}],"web3Wallets":[],"externalAccounts":[],"samlAccounts":[],"lastActiveAt":1721100657328,"createOrganizationEnabled":false} is not a supported Convex type (present at path .data[0] in original object {SAME DATA RETRACTED}). To learn about Convex's supported types, see https://docs.convex.dev/using/types.
at convexToJsonInternal (../../node_modules/convex/src/values/value.ts:339:6)
at <anonymous> (../../node_modules/convex/src/values/value.ts:322:4)
at convexToJsonInternal (../../node_modules/convex/src/values/value.ts:320:29)
at convexToJsonInternal (../../node_modules/convex/src/values/value.ts:350:15)
at convexToJson (../../node_modules/convex/src/values/value.ts:417:0)
ballingt
ballingt6mo ago
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 type
You can't store instance of classes in the Convex database, only plain objects
DaReal
DaRealOP6mo ago
Thank you so much. That worked! ✅
Ulrich
Ulrich6mo ago
@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.
DaReal
DaRealOP6mo ago
@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?
Ulrich
Ulrich6mo ago
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.
Ferdinand
Ferdinand6mo ago
Hello! I'm new to convex and I need help to send mail using nodemailer and Gmail.

Did you find this page helpful?