#[SOLVED] 500 error creating document using dart SDK

21 messages · Page 1 of 1 (latest)

cobalt glacier
#

AppwriteException: general_unknown, Server Error (500)

fair ridge
#

500 error creating document using dart SDK

cobalt glacier
fair ridge
# cobalt glacier

Please share your project id as text and details about your collection, not just the collection id

cobalt glacier
#

There is no need to share the build key

fair ridge
cobalt glacier
#

class AppwriteServer {
final Client client;
final AppwriteEnvironment environment;
AppwriteServer(this.environment) : client = Client() {
client
..setEndpoint(environment.endPoint)
..setProject(environment.projectId)
..setKey(environment.apiKey);
}

Databases get databases => Databases(client);

Future<Database?> getDatabase() async {
try {
return databases.get(databaseId: environment.databaseId);
} catch (e) {
return null;
}
}

Future<Collection?> getCollection() async {
try {
return databases.getCollection(
databaseId: environment.databaseId,
collectionId: environment.collectionId,
);
} catch (e) {
return null;
}
}
}

#

Future<bool> setBuildConfig({
required BuildInfo buildInfo,
required String buildName,
required int buildTime,
}) async {
final appwriteServer = AppwriteServer(environment);
final databases = appwriteServer.databases;
try {
await databases.createDocument(
databaseId: environment.databaseId,
collectionId: environment.collectionId,
documentId: ID.unique(),
data: {
'platform': platform,
'build_name': buildName,
'build_time':
DateTime.fromMillisecondsSinceEpoch(buildTime).toIso8601String(),
'build_config_json': json.encode(buildInfo.toJson()),
'build_number': '$buildTime',
},
);
return true;
} catch (e) {
logger.log(e.toString(), status: LogStatus.error);
return false;
}
}

fair ridge
cobalt glacier
#
Future<bool> setBuildConfig({
    required BuildInfo buildInfo,
    required String buildName,
    required int buildTime,
  }) async {
    final appwriteServer = AppwriteServer(environment);
    final databases = appwriteServer.databases;
    try {
      await databases.createDocument(
        databaseId: environment.databaseId,
        collectionId: environment.collectionId,
        documentId: ID.unique(),
        data: {
          'platform': platform,
          'build_name': buildName,
          'build_time':
              DateTime.fromMillisecondsSinceEpoch(buildTime).toIso8601String(),
          'build_config_json': json.encode(buildInfo.toJson()),
          'build_number': '$buildTime',
        },
      );
      return true;
    } catch (e) {
      logger.log(e.toString(), status: LogStatus.error);
      return false;
    }
  }
#
class AppwriteServer {
  final Client client;
  final AppwriteEnvironment environment;
  AppwriteServer(this.environment) : client = Client() {
    client
      ..setEndpoint(environment.endPoint)
      ..setProject(environment.projectId)
      ..setKey(environment.apiKey);
  }

  Databases get databases => Databases(client);

  Future<Database?> getDatabase() async {
    try {
      return databases.get(databaseId: environment.databaseId);
    } catch (e) {
      return null;
    }
  }

  Future<Collection?> getCollection() async {
    try {
      return databases.getCollection(
        databaseId: environment.databaseId,
        collectionId: environment.collectionId,
      );
    } catch (e) {
      return null;
    }
  }
}
fair ridge
cobalt glacier
#

These are all the details of my implementation of Collection. According to the official documentation, there is no problem with my code. There should be no permission issues with the Api Key used. Is it possible that there is currently a problem with Appwrite Cloud? I have seen that many people have reported 500 issues.

fair ridge
cobalt glacier
#

I got extra information today

#

[2023-12-28 09:09:18.796][🔴 ERROR ] AppwriteException: document_invalid_structure, Invalid document structure: Attribute "build_number" has invalid type. Value must be a valid string and no longer than 10 chars (400)

#

I'll try again after modifying it. At least it's not a 500 error now.

#

I have modified the length of build_number and it works now.