diff --git a/htdocs/user/api_token/card.php b/htdocs/user/api_token/card.php
index 6d533960708..2c5cc691586 100644
--- a/htdocs/user/api_token/card.php
+++ b/htdocs/user/api_token/card.php
@@ -553,9 +553,6 @@ if ($action == 'create') {
$db->commit();
- // Load perms ids for the user
- $tokenperms = explode(",", $token->rights);
-
print '
';
print '
';
@@ -671,6 +668,13 @@ if ($action == 'create') {
dol_print_error($db);
}
+ // Load perms ids for the user
+ if (empty($token->rights) && !(strlen($token->rights) == 1 && substr($token->rights, 0, 1) == 0)) {
+ $tokenperms = $allusersperms;
+ } else {
+ $tokenperms = explode(",", $token->rights);
+ }
+
// Load and show all the perms grouped by module
if (count($allusersperms) > 0) {
$sql = "SELECT r.id, r.libelle as label, r.module, r.perms, r.subperms, r.module_position, r.bydefault";