Back

How to get data and execution status from cloud function to client

  • 0
  • Flutter
  • Functions
hamed
12 Sep, 2023, 16:11

Hi, I’m trying to use the new cloud function by getting certain data back to the client from the execution, including the execution status, but somehow I’m getting an empty response. I would appreciate any help.

TL;DR
To get data and execution status from a cloud function to the client: 1. Set the `xasync` parameter to `false` when calling the `createExecution` function. 2. Use the `getExecution` function with the function ID obtained from `createExecution` to retrieve the execution status and results. Note: Make sure the user is logged in to have permission to read the function status.
Binyamin
12 Sep, 2023, 16:18
  1. When you're using async execution, then you won't get the result from the createExecution function. to get the results right away set xasync to false
  2. You can use the getExecution function to get the function execution status and results, for that you'll need to use the information you got from the createExecution function.

Notice: You won't get any results from the getExecution function if the current user is not logged in, as no one will have permission to read the function status.

hamed
12 Sep, 2023, 16:30

Thanks, as always. Let me try it ( I have a concern when you said getExecution does that mean I have to pass the execution id wich I need to get every time from the console? )

Binyamin
12 Sep, 2023, 16:32

Yes,

Binyamin
12 Sep, 2023, 16:32

But if you would change the xasync to false then you'll get the results when the function ended

hamed
12 Sep, 2023, 16:49

Going over to the console each time is more stressful, especially when the app is released. I tried the previous one, just switched xasync to false and voila, I got those data. But do you know why I couldn't get the default values that are mentioned in the docs while I was setting xasync to true?

Binyamin
12 Sep, 2023, 16:51

This is an example of what you should get when running the function in async

TypeScript
{
    "$id": "SomeID",
    "$createdAt": "2023-09-12T16:50:31.798+00:00",
    "$updatedAt": "2023-09-12T16:50:31.798+00:00",
    "$permissions": [
        "read(\"user:SomeID\")"
    ],
    "functionId": "SomeID",
    "trigger": "http",
    "status": "waiting",
    "requestMethod": "GET",
    "requestPath": "\/",
    "requestHeaders": [],
    "responseStatusCode": 0,
    "responseBody": "",
    "responseHeaders": [],
    "logs": "",
    "errors": "",
    "duration": 0
}
Binyamin
12 Sep, 2023, 16:51

What are you getting when you dumping the whole object

hamed
12 Sep, 2023, 17:05

false

TypeScript
{$id: 6500999a17d816914c9b, $createdAt: 2023-09-12T17:02:19.537+00:00, $updatedAt: 2023-09-12T17:02:19.537+00:00, $permissions: [read("user:646e517c33abdc84e711")], functionId: 64ff1e03053ba3ee0ee9, trigger: http, status: completed, requestMethod: POST, requestPath: /, requestHeaders: [], responseStatusCode: 200, responseBody: Success, responseHeaders: [{name: x-powered-by, value: Dart with package:shelf}, {name: date, value: Tue, 12 Sep 2023 17:02:19 GMT}, {name: content-length, value: 13}, {name: x-frame-options, value: SAMEORIGIN}, {name: content-type, value: text/plain; charset=utf-8}, {name: x-xss-protection, value: 1; mode=block}, {name: x-content-type-options, value: nosniff}], logs: , errors: , duration: 0.9277000427246094}
Binyamin
12 Sep, 2023, 17:06

Both look like xasync false,

Binyamin
12 Sep, 2023, 17:06

Can you double check

hamed
12 Sep, 2023, 17:07

My bad this one is true:

TypeScript
{$id: 6500990a4c82c383df20, $createdAt: 2023-09-12T16:59:54.313+00:00, $updatedAt: 2023-09-12T16:59:54.313+00:00, $permissions: [read("user:646e517c33abdc84e711")], functionId: 64ff1e03053ba3ee0ee9, trigger: http, status: , requestMethod: POST, requestPath: /, requestHeaders: [], responseStatusCode: , responseBody: , responseHeaders: [], logs: , errors: , duration: 0.0}
Binyamin
12 Sep, 2023, 17:07

It's interesting that it's empty But you do get the functionId back that you can use with the getExecution one.

hamed
12 Sep, 2023, 17:09

Yes, I’ll try that.

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