Back

AppwriteException null, Connection refused (0)

  • 0
  • Databases
dammy
28 Aug, 2023, 12:56

I was getting the above error while trying to update database from server code I also included: *the key *the project ID *the document ID *the database ID *the collection ID

TL;DR
The user encountered an "AppwriteException null, Connection refused (0)" error while trying to update a database from their server code. They realized they had made a mistake in the URL endpoint by using "localhost" instead of the Appwrite cloud URL. They also shared their code for the AppwriteLogic class and the function where the error occurred. They received suggestions to check their endpoint and initialize the client properly. The solution was to use the Appwrite cloud URL and ensure that the client is properly initialized before using it in the class.
joeyouss
28 Aug, 2023, 13:26

can you show network payload once?

joeyouss
28 Aug, 2023, 13:26

also the code please?

dammy
28 Aug, 2023, 20:48

okay

dammy
28 Aug, 2023, 20:52
TypeScript
minusFromDb() async {
    AppWriteLogic appwriteData = AppWriteLogic();
    appwriteData.appwriteEndpointProjectID();

    Future result = appwriteData.databases.updateDocument(
      databaseId: appwriteData.databaseID.toString(),
      collectionId: appwriteData.walletBalanceCollectionID.toString(),
      // documentId: walletDocumentID.toString(),
      documentId: "wallet_data_${userID}",
      // 
      // 
      data: {"current_wallet_balance": 100},
    );
    // 

    result.then((response) {
      print("object");
      // 
    }).catchError((error) {
      print(error);
    });
  }
Drake
28 Aug, 2023, 21:43

Where are you running this from?

dammy
28 Aug, 2023, 21:46

Dart cloud function @Steven

Drake
28 Aug, 2023, 22:26

What is AppwriteLogic and appwriteEndpointProjectID()?

dammy
28 Aug, 2023, 22:28

Appwrite class for holding my necessary details and functions

Drake
28 Aug, 2023, 22:28

Please share the code

dammy
28 Aug, 2023, 22:29

But is it healthy to use a frontend API?

dammy
28 Aug, 2023, 22:31
TypeScript
  String endpoint = "http://localhost/v1";
  String projectId = 'project id';
  String variablesKey =
      "key from console";
  String walletBalanceCollectionID = "wallet balance collection";
  String databaseID = "database id";

//  create account, function instance
  Databases databases = Databases(client);

  Functions functions = Functions(client);

  late Account account;
// Functions functions = Functions(client);

//   pass in secret data
  appwriteEndpointProjectID() {
    client
        .setEndpoint(endpoint) // Your API Endpoint
        .setProject(projectId) // ID
        .setSelfSigned(status: true)
        .setKey(variablesKey);

    account = Account(client);
  }
}
dammy
28 Aug, 2023, 22:32

the values is qoutes were changed before posting for security reasons

Drake
28 Aug, 2023, 22:35

Where's client initialized?

Drake
28 Aug, 2023, 22:35

Also, your endpoint could be the problem. You can't use localhost because the function would connect to itself instead of Appwrite

dammy
28 Aug, 2023, 22:36

It was, I didn't copy that part

It was initialized outside, since I can't initialize and use it in the class top level area at same time

dammy
28 Aug, 2023, 22:38

oooo, it supposed to be the appwrite cloud url

what a mistake

Drake
28 Aug, 2023, 22:42

That should work

dammy
28 Aug, 2023, 23:33

what was that?

it's not a local instance of appwrite

Drake
28 Aug, 2023, 23:35

Right...so what's your problem now?

dammy
28 Aug, 2023, 23:36

I think it's sorted, but 8 need to try when next my laptop is turned on

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