Back

Invalid url: URL host must be one of: localhost, <IP> (400)

  • 0
  • Self Hosted
burakcbdn
12 Aug, 2023, 06:56

I created a dart function that adds user to team, when I call teams.createMembership I got this error

Error: AppwriteException: general_argument_invalid, Invalid url: URL host must be one of: localhost, <IP> (400)

Code

TypeScript

  if (req.variables['APPWRITE_FUNCTION_ENDPOINT'] == null || req.variables['APPWRITE_FUNCTION_API_KEY'] == null) {
    print("Environment variables are not set. Function cannot use Appwrite SDK.");
    return;
  }
  try {
    print("Initing function");

    final client = Client();

    client
        .setEndpoint(req.variables['APPWRITE_FUNCTION_ENDPOINT'])
        .setProject(req.variables['APPWRITE_FUNCTION_PROJECT_ID'])
        .setKey(req.variables['APPWRITE_FUNCTION_API_KEY'])
        .setSelfSigned(status: true);

    final teams = Teams(client);

    print("client init");
    print("Data type: ${req.payload.runtimeType}");
    print("Data: ${req.payload}");
    Map<String, dynamic> payload = jsonDecode(req.payload.replaceAll("\n", ""));

    String businessID = payload['businessID'];
    String email = payload['email'];

    print("businessID: " + businessID);
    print("email: " + email);

    await teams.createMembership(
      teamId: 'business',
      email: email,
      roles: [],
      url: 'url.com'
    );
    res.json({
      'success': true,
    });
  } catch (e) {
    print("Error: $e");
    res.json({
      'success': false,
    });
  }
TL;DR
The user is experiencing an "Invalid url: URL host must be one of: localhost, appwrite.mydomain.com" error when trying to use the `teams.createMembership` function in their Dart code. They have already added a custom domain and generated an SSL certificate, but the error still persists. It is suggested to use a valid domain name instead of an IP address. The user is also provided with an example of how to set the base URL for the `teams.createMembership` redirect parameter. It is recommended to review the code and make sure all necessary environment variables are set correctly.
burakcbdn
12 Aug, 2023, 06:56

Here is the logs

TypeScript
Initing function
client init
Data type: String
Data: {"businessID": "hello","email": "email@email.com"}
businessID: hello
email: email@email.com
Error: AppwriteException: general_argument_invalid, Invalid url: URL host must be one of: localhost, <IP> (400)
safwan
12 Aug, 2023, 07:15

For instance, when you create a web app, you need to add it as a platform in your Appwrite console (the dashboard). When you do so, you're asked for a "hostname" which is essentially the domain of the app that will sending requests to your appwrite endpoint.

If you add something like mydomain.com as the hostname for your web platform, then you can only use mydomain.com as the base URL for the teams.createMembership redirect parameter.

burakcbdn
12 Aug, 2023, 07:16

yep I added host as <IP>

burakcbdn
12 Aug, 2023, 07:16

but still same error

safwan
12 Aug, 2023, 07:17

i don't think IPs are a good way to do this

safwan
12 Aug, 2023, 07:17

It's better to use a valid domain name

burakcbdn
12 Aug, 2023, 07:18

Okay let me try that

burakcbdn
12 Aug, 2023, 07:36

cannot connect to custom domain @safwan

burakcbdn
12 Aug, 2023, 07:36

I changed _APP_DOMAIN and _APP_DOMAIN_TARGET as appwrite.mydomain.com

burakcbdn
12 Aug, 2023, 07:36

and added A record to my server api from dns dashboard to appwrite.mydomain.com

burakcbdn
12 Aug, 2023, 07:37

but it does not works, do I need any more conifguration

burakcbdn
12 Aug, 2023, 07:40

also generated ssl

burakcbdn
12 Aug, 2023, 07:51

finally added custom domain, but still same error

burakcbdn
12 Aug, 2023, 07:52

Error: AppwriteException: general_argument_invalid, Invalid url: URL host must be one of: localhost, appwrite.mydomain.com

burakcbdn
12 Aug, 2023, 08:05

yep finally fixed, I needed to give valid url for the redirect for teams.createmembership

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