vontdeux
vontdeux

Reputation: 107

appwrite type String is not a subtype of type 'Map<String, dynamic>'

Sorry if the title is not descriptive enough,

I've managed to self host an appwrite on a private cloud, on a container, which incoming traffic is managed by Nginx Proxy Manager

I can connect to the appwrite SDK with flutter, I can use database.listDocuments and database.getDocument with no issue

the current collection only have 1 document, which created manually using web, so using database.listDocument will return a list of document with length of 1

my current issue is I cannot use database.createDocument, and database.updateDocument

Future<void> createRankings() async {
apwr.Databases database = apwr.Databases(client);
String docID = "BDRec0000001";
List<String> permission = [
  Permission.read(Role.any()),
  Permission.update(Role.any()),
];

try {
  var response = await database.createDocument(
    databaseId: dbID,
    collectionId: collectionID,
    documentId: docID,
    data: {"item": 1, "itemMake": 1, "sn": "GHTDD001Z001"},
    permissions: permission,
  );

} catch (e) {
  print('Error creating document: $e');
}}

the return in flutter is Error creating document : type 'String' is not a subtype of type 'Map<String, dynamic>'

so I dig further and i found this code in appwrite-9.0.0/lib/services/database.dart (the source of method createDocument) on the line inside createDocument's method

Future<models.Document> createDocument(
  {required String databaseId,
  required String collectionId,
  required String documentId,
  required Map data,
  List<String>? permissions}) async {
final String path = '/databases/{databaseId}/collections/{collectionId}/documents'
    .replaceAll('{databaseId}', databaseId)
    .replaceAll('{collectionId}', collectionId);

final Map<String, dynamic> params = {
  'documentId': documentId,
  'data': data,
  'permissions': permissions,
};

final Map<String, String> headers = {
  'content-type': 'application/json',
};

final res = await client.call(HttpMethod.post, path: path, params: params, headers: headers);
print(res.data);
print('path:$path');
print('params:$params');
print('headers:$headers');
return models.Document.fromMap(res.data);}

I've added the line print(res.data) and the 3 others to see what is the data returned

and the result printed is

flutter: <html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>openresty</center>
</body>

</html>

I've tried seeking this issue in their github and also here, nothing related to it

I'm pretty sure it is something simple, but I cant find any answer anywhere

Upvotes: 0

Views: 191

Answers (1)

Steven
Steven

Reputation: 712

Please double-check that you're using https for your endpoint as part of client.setEndpoint(). If you don't and Appwrite has force HTTPS enabled, you would see that 301 moved since Appwrite redirects to HTTPS.

Upvotes: 0

Related Questions