#[SOLVED] 500 error creating document using dart SDK
21 messages · Page 1 of 1 (latest)
And what's your collection?
500 error creating document using dart SDK
Please share your project id as text and details about your collection, not just the collection id
end_point: https://cloud.appwrite.io/v1
project_id: mianyuzhouapp
database_id: shorebird_patchs
collection_id: build_info
There is no need to share the build key
yes...and as i said again, please share the details about your colleciton, not just the ID
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;
}
}
FYI, it's best to wrap code in backticks to format a bit nicer. You can use 1 backtick for inline code (https://www.markdownguide.org/basic-syntax/#code) and 3 backticks for multiline code (https://www.markdownguide.org/extended-syntax/#syntax-highlighting.
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;
}
}
}
so did you run this so you can share with me the actual details of the collection?
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.
I'm looking for details about your attributes, their types, sizes, etc.
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.