JeffWScott
JeffWScott2d ago

/api/action returning 404

Hello, I have a convex deployment and I'm trying to send some data to my table using an action from a go program. From the docs it looks straightforwards but I was having some truouble. So I set up a simple action that just prints Hello to teh console. This action runs in the dashboard manually. When I call this function from my go code I get "HTTP error 404: This Convex deployment does not have HTTP actions enabled." I don't see anywhere to "enable HTTP actions". this is my action:
// convex/items.ts
export const testHttpActions = action({
args: {},
handler: async () => {
console.log("ACTION!")
},
});
// convex/items.ts
export const testHttpActions = action({
args: {},
handler: async () => {
console.log("ACTION!")
},
});
This is my go code code:
...
url := "https://<removed_from_example>.convex.site/api/action"

body := map[string]interface{}{
"path": "items:testHttpActions",
"args": "",
"format": "json",
}

jsonBody, err := json.Marshal(body)
if err != nil {
return err
}

req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonBody))
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", CONVEX_API_KEY))

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
...
...
url := "https://<removed_from_example>.convex.site/api/action"

body := map[string]interface{}{
"path": "items:testHttpActions",
"args": "",
"format": "json",
}

jsonBody, err := json.Marshal(body)
if err != nil {
return err
}

req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonBody))
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", CONVEX_API_KEY))

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
...
When I google this error or talk to AI about it I get a lot of stuff about setting up "http actions" but that's not what I want to do.
I want to do what's in this documentation: https://docs.convex.dev/http-api/#functions-api Can someone help me understand please? I thought this was going to be pretty straightforward by looking at the docs and now i'm just spinning.
Convex HTTP API | Convex Developer Hub
Connecting to Convex directly with HTTP
4 Replies
Convex Bot
Convex Bot2d ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
Clever Tagline
HTTP actions are different from normal actions. Check out the setup here: https://docs.convex.dev/functions/http-actions
HTTP Actions | Convex Developer Hub
Build HTTP APIs directly in Convex
JeffWScott
JeffWScottOP2d ago
right. but what is this API then? https://docs.convex.dev/http-api/
Convex HTTP API | Convex Developer Hub
Connecting to Convex directly with HTTP
JeffWScott
JeffWScottOP2d ago
like what is this page and code supposed to be telling me?
const url = "https://acoustic-panther-728.convex.cloud/api/query";
const request = { path: "messages:list", args: {}, format: "json" };

const response = fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(request),
});
const url = "https://acoustic-panther-728.convex.cloud/api/query";
const request = { path: "messages:list", args: {}, format: "json" };

const response = fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(request),
});
oh, you use .cloud and not .site and it works perfectly.

Did you find this page helpful?