Ulrich
Ulrich
CCConvex Community
Created by DaReal on 7/16/2024 in #support-community
Help with 3rd party api call in Actions
@DaReal @ballingt Problem solved. The returned JSON was a nested object so I needed to add "rows" to access the correct data.
13 replies
CCConvex Community
Created by DaReal on 7/16/2024 in #support-community
Help with 3rd party api call in Actions
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
13 replies
CCConvex Community
Created by DaReal on 7/16/2024 in #support-community
Help with 3rd party api call in Actions
@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.
13 replies