Back

How to pass dynamic value after deployment of function

  • 0
  • Self Hosted
  • Flutter
conqueror
6 May, 2023, 18:33

its just above the (Future start) , its a long data that is why i did not provided it here.

TL;DR
The user is trying to pass dynamic values after deploying a function but is facing some issues. They tried using `Future(() async { ...})`, but it's not working for long data and taking time. They asked for examples of performing batch operations and asked if they can create batch documents in a single response. There is a suggestion to use GraphQL for batch operations. There is a conversation about passing the correct data structure and using valid JSON strings. The user also asked for guidance on using the payload, but didn't provide enough information. Solution: The user should make sure they are passing valid JSON strings and use the correct data structure. They
Drake
6 May, 2023, 18:35

2 please tell me how to use payload as i dont have any idea

It's a String...how do you work with strings? What did you pass as data when you executed the function?

conqueror
6 May, 2023, 18:37

paste this same line as map of object not as string { 'image': 'image', 'productName': 'productName', 'productUnit': 'productUnit', // Provide default value for null 'barcode': 12245, 'id': " dataid", 'sellingPrice': 44.0, 'totalQuantity': 100.0, 'quantity': 1.0, }, { 'image': 'image', 'productName': 'productName222', 'productUnit': 'productUnit', // Provide default value for null 'barcode': 456566565, 'id': " dataid", 'sellingPrice': 44.0, 'totalQuantity': 100.0, 'quantity': 1.0, },

Drake
6 May, 2023, 18:38

no...it's a string

conqueror
6 May, 2023, 18:39

should i use like this 'image': 'image', 'productName': 'productName222', 'productUnit': 'productUnit', // Provide default value for null 'barcode': 456566565, 'id': " dataid", 'sellingPrice': 44.0, 'totalQuantity': 100.0, 'quantity': 1.0,

Drake
6 May, 2023, 18:39

Do you see what's wrong with this code:

TypeScript
  final String payload = "";
  payload['6439e7ae4abb3e14f2b1'];
Drake
6 May, 2023, 18:39

You need to pass a valid JSON string and then parse it in your function. what you passed is not a valid JSON string.

conqueror
6 May, 2023, 18:43

should i use like this? , commented the previous line of codedart //databaseId: payload['6439e7ae4abb3e14f2b1'], //collectionId: payload['64444e34a0ce20bc4ac8'], databaseId:'6439e7ae4abb3e14f2b1', collectionId: '64444e34a0ce20bc4ac8',

conqueror
6 May, 2023, 18:48
TypeScript
'image': 'image',
        'productName': 'productName',
        'productUnit': 'productUnit', // Provide default value for null
        'barcode': 12245,
        'id': " dataid",
        'sellingPrice': 44.0,
        'totalQuantity': 100.0,
        'quantity': 1.0,
      },
      {
        'image': 'image',
        'productName': 'productName222',
        'productUnit': 'productUnit', // Provide default value for null
        'barcode': 456566565,
        'id': " dataid",
        'sellingPrice': 44.0,
        'totalQuantity': 100.0,
        'quantity': 1.0,
      },, APPWRITE_FUNCTION_USER_ID: 64386aeb90452ea0c185, APPWRITE_FUNCTION_JWT: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiI2NDM4NmFlYjkwNDUyZWEwYzE4NSIsInNlc3Npb25JZCI6IjY0Mzg2YWViYTc0NzA1MjcwZGZjIiwiZXhwIjoxNjgzMzk5NzU5fQ.Qksi0AnCQ5BbScKXAV3Ef1LjDMoX2sZoLoDuFLepNyo}
{
'image': 'image',
        'productName': 'productName',
        'productUnit': 'productUnit', // Provide default value for null
        'barcode': 12245,
        'id': " dataid",
        'sellingPrice': 44.0,
        'totalQuantity': 100.0,
        'quantity': 1.0,
      },
      {
        'image': 'image',
        'productName': 'productName222',
        'productUnit': 'productUnit', // Provide default value for null
        'barcode': 456566565,
        'id': " dataid",
        'sellingPrice': 44.0,
        'totalQuantity': 100.0,
        'quantity': 1.0,
      },
AppwriteException: document_invalid_structure, Invalid document structure: Unknown attribute: "c1667f4f-d1aa-4310-933d-fd4244e30a29" (400)```
conqueror
6 May, 2023, 18:52

this is a log from appwrite after execution function

Drake
6 May, 2023, 18:53

so you're passing something like this as batchData:

TypeScript
{
  "some-uuid-id": {
     "image": "",
     "barcode": ""
     // so on...
  },
  {"another-uuid-id": {
     "image": "",
     "barcode": ""
     // so on...
  }
}

This is not a valid document. have you gone through the basics about how to use the Appwrite databases api?

conqueror
6 May, 2023, 18:56

yse i have gone through the database api, and created document also, if i can not use uuid then what is best way to create batch document in a single response

Drake
6 May, 2023, 18:57

If you really need to make 1 API request, you can try using graphql: https://appwrite.io/docs/graphql

Drake
6 May, 2023, 18:58

Otherwise, it's much simpler to just call createDocument() for each document concurrently

conqueror
6 May, 2023, 19:31

ok, any example so that can perform batch operation.

Drake
6 May, 2023, 19:32

Did you read what I linked?

conqueror
6 May, 2023, 19:34

yes, but dont want to use graphql.

Drake
6 May, 2023, 19:35

So youre asking about how to execute create document concurrently?

conqueror
6 May, 2023, 19:36

yes, as i used for loop for creating document which is working fine but its taking time and every time its making new request for every new document creation.

conqueror
6 May, 2023, 20:11

also tried this but not working for long data and taking time dart Future<void> uploadProducts(List<Map<String, dynamic>> products) async { final futures = <Future>[]; for (final product in products) { futures.add(Future(() async { try { final document = await database.createDocument( databaseId: '6439e7ae4abb3e14f2b1', collectionId: collectionId, documentId: '', data: product, ); print('Product ${document.data['productName']} uploaded successfully.'); } catch (e) { print('Error uploading product ${product['productName']}: $e'); } })); } await Future.wait(futures); print('All products uploaded successfully.'); }

Drake
6 May, 2023, 20:19

Uh I don't think you create a future like Future(() async { ...})

Drake
6 May, 2023, 20:21

NVM I guess you could...

Drake
6 May, 2023, 20:23

It will still take time...the point is this will not wait for each document creation before proceeding to the next

conqueror
6 May, 2023, 20:26

ok

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