diff --git a/lib/api.dart b/lib/api.dart index 8f75df30..e53c2a3e 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -198,8 +198,8 @@ class InvenTreeAPI { bool _strictHttps = false; // Endpoint for requesting an API token - static const _URL_TOKEN = "user/token/"; - static const _URL_ROLES = "user/roles/"; + static const _URL_TOKEN = "user/me/token/"; + static const _URL_ROLES = "user/me/roles/"; static const _URL_ME = "user/me/"; // Accessors for various url endpoints @@ -357,6 +357,10 @@ class InvenTreeAPI { // Ref: https://github.com/inventree/InvenTree/pull/10699 bool get supportsModernParameters => apiVersion >= 429; + // Does the server use the new "user/me/" endpoints? + // Ref: https://github.com/inventree/InvenTree/pull/11963 + bool get supportsNewUserEndpoints => apiVersion >= 490; + // Cached list of plugins (refreshed when we connect to the server) List _plugins = []; @@ -588,9 +592,13 @@ class InvenTreeAPI { String authHeader = "Basic " + base64Encode(utf8.encode("${username}:${password}")); + String actualTokenUrl = supportsNewUserEndpoints + ? _URL_TOKEN + : "user/token/"; + // Perform request to get a token final response = await get( - _URL_TOKEN, + actualTokenUrl, params: {"name": platform_name}, headers: {HttpHeaders.authorizationHeader: authHeader}, ); @@ -709,8 +717,10 @@ class InvenTreeAPI { roles.clear(); debug("API: Requesting user role data"); - - final response = await get(_URL_ROLES, expectedStatusCode: 200); + String actualRoleUrl = supportsNewUserEndpoints + ? _URL_ROLES + : "user/roles/"; + final response = await get(actualRoleUrl, expectedStatusCode: 200); if (!response.successful()) { return false;