Back

[SOLVED] REST API with Cloud Functions

  • 0
  • Cloud
Ahmed Ibrahim
5 Nov, 2023, 19:30

Hello, I'm attempting to execute a cloud function via an HTTP request. I've read the documentation, which mentions that each function has its own domain. I've also included the project ID and content-type in the headers, and I received a dummy response as the following

TypeScript
{"motto":"Build like a team of hundreds_","learn":"https://appwrite.io/docs","connect":"https://appwrite.io/discord","getInspired":"https://builtwith.appwrite.io"}

The documentation that i read was https://appwrite.io/docs/products/functions/execution

So how can I make http request for my Appwrite cloud function using REST API?

Thanks in advance

TL;DR
User was initially unsure about executing a cloud function via REST API. They compared their code to the initial template and found a missing 'return' keyword. The issue has been resolved. To make an HTTP request for an Appwrite cloud function using REST API, the user can use the domain of the function, which can be found on the function's overview page.
Drake
5 Nov, 2023, 20:15

Yes, if you look at the overview page of your function, in the card with the details of the active deployment, there should be a link. That link is your function.

Drake
5 Nov, 2023, 20:16

Executing the function via the rest API is something different. Did you want to use the domain or REST API?

Ahmed Ibrahim
5 Nov, 2023, 20:23

@Steven I want to execute the function using REST API and get the response of the function.

for example like this http request https://dummy.restapiexample.com/api/v1/employees

Drake
5 Nov, 2023, 21:08

You could use either the Appwrite REST API or the function domain

Drake
5 Nov, 2023, 21:09

Anyways, I'm still not sure what your problem is. Can you clarify?

Ahmed Ibrahim
5 Nov, 2023, 21:32

@Steven, Actually the issue has been resolved. After you confirmed that it can be done, I compared the code that came with the initial template to my code and found the problem: I forgot to include the return keyword. Instead of writing:

TypeScript
return context.res.send(response.body.toString());

I should have written:

TypeScript
context.res.send(response.body.toString());

Thank you very much, @Steven, for your help.

Drake
6 Nov, 2023, 22:33

[SOLVED] REST API with Cloud Functions

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more