
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
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,
});
}

Here is the logs
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)

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.


yep I added host as <IP>

but still same error

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

It's better to use a valid domain name

Okay let me try that

cannot connect to custom domain @safwan

I changed _APP_DOMAIN and _APP_DOMAIN_TARGET as appwrite.mydomain.com

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

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

also generated ssl

finally added custom domain, but still same error

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

yep finally fixed, I needed to give valid url for the redirect for teams.createmembership
Recommended threads
- Random Execution Timeouts and getaddrinf...
Hi, I’m running a self-hosted Appwrite (v1.5.10) on a VPS. My setup involves calling an external API many times from Appwrite Functions. Under higher load, I oc...
- Can't create repos/ clone templates, or ...
My GitHub app can see all my repos, and even create new ones, but the branch isn't visible, which prevents appwrite from deploying. Is this a GitHub app permis...
- Login to appwrite CLI
Hi, appwrite login in cli seems not work for me on localhost when I tried `appwrite login --endpoint http://localhost --verbose` I got an error (file attached)....
