Back

how to pass map data through the string that createExecution receives, (flutter)

  • 0
  • Functions
Binyamin
31 Oct, 2023, 16:08

<:appwritefire:823999000330895380>

TL;DR
The user is asking how to pass map data through a string that the createExecution function receives in Flutter. They also shared a traceback error they encountered. Solution: Import the 'dart:convert' package and use the json.encode() method to convert the context.req.body into a JSON string. To access the data sent by the client-side inside the function, use the context.req.body. The 'async' parameter is used to execute the function in the background and fetch results later. The 'method' parameter specifies the HTTP method used for the request. The 'headers' parameter can be used to include custom headers. In Python, the data
frankenstein
31 Oct, 2023, 16:10

how do i import data coming from function execution?

Binyamin
31 Oct, 2023, 16:10

What do you mean by import?

frankenstein
31 Oct, 2023, 16:11

the data you pass through when executing a function. how do i access them in my function?

Binyamin
31 Oct, 2023, 16:13

Like so

TypeScript
 data = response.json()
Binyamin
31 Oct, 2023, 16:13

You can see a good example here

frankenstein
31 Oct, 2023, 16:34

yeah yeah yeaaaaaaah

frankenstein
31 Oct, 2023, 16:35

so in python context.req.body ill access the body attached to the function execution?

Binyamin
31 Oct, 2023, 16:36

Yes

frankenstein
31 Oct, 2023, 16:40
TypeScript
        functionId: '[FUNCTION_ID]',
        body: json.encode({ 'foo': 'bar' }),
        async: false,
        path: '/',
        method: 'GET',
        headers: {
            'X-Custom-Header': '123'
        }
    );```
frankenstein
31 Oct, 2023, 16:40

what is async importance in the function execution?

frankenstein
31 Oct, 2023, 16:41

and method?

Binyamin
31 Oct, 2023, 17:31
  • Method is relevant only when you want to check it inside the function.
  • xasync is if you want to execute the function in the background and fetch the results later using the getExecution function. this is probably what you don't want to do so just ignore it or set it as false.
dammy
1 Nov, 2023, 03:10

what about getting the data that client side sent inside the function, using dart?

Binyamin
1 Nov, 2023, 03:25

With dart? it's inside the req.body

TypeScript
import 'dart:convert';

final body = json.encode(context.req.body)

Check here

dammy
1 Nov, 2023, 03:26

okay

Binyamin
1 Nov, 2023, 03:27

<a:agooglethumbsup:635256484682530825>

dammy
1 Nov, 2023, 03:28

you just saved my time

frankenstein
1 Nov, 2023, 08:16

hello @Binyamin ive deployed a python function and im get below logs

frankenstein
1 Nov, 2023, 08:17
TypeScript
  File "/usr/local/server/src/server.py", line 165, in handler
    output = await asyncio.wait_for(execute(context), timeout=safeTimeout)
  File "/usr/local/lib/python3.9/asyncio/tasks.py", line 479, in wait_for
    return fut.result()
  File "/usr/local/server/src/server.py", line 150, in execute
    userModule = importlib.import_module("function." + userPath)
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'function.main'```
Binyamin
1 Nov, 2023, 13:37

Have you used the appwrite cli or a python function starter to create your function? As their is a specific structure for the function

frankenstein
1 Nov, 2023, 14:19

i figured out the issue. i was creating a tar.gz of a folder instead of files

frankenstein
1 Nov, 2023, 14:20

if i have function domain like this https://64d4d22db370ae41a32e.appwrite.global/

frankenstein
1 Nov, 2023, 14:21

how do i pass data when im triggering it with url

Drake
1 Nov, 2023, 14:51

please create your own <#1072905050399191082> for distinct problems instead of using someone else's

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