I'm creating a Role for the default Application like so, and then trying to import a user:
import {FusionAuthClient} from '@fusionauth/typescript-client';
const applicationId = 'e9fdb985-9173-4e01-9d73-ac2d60d1dc8e';
const subscriberRoleId = '635ef5c8-54c5-4605-ba0f-add6ad1578ce';
const apiKey = '33052c8a-c283-4e96-9d2a-eb1215c69f8f-not-for-prod';
const fusionauthUrl = 'http://localhost:9011';
const fa = new FusionAuthClient(apiKey, fusionauthUrl);
await fa.createApplicationRole(applicationId, subscriberRoleId, { role: {
id: subscriberRoleId,
isDefault: false,
isSuperRole: false,
name: 'Subscriber',
description: 'Subscriber'
} });
const importRequest = { users: [user], validateDbConstraints: true };
const result = await fa.importUsers(importRequest);
Importing without user Registrations works fine, but as soon as I add a Registration, I get this error:
fieldErrors: {
'user.registrations.roles': [
{
code: '[invalid]user.registrations.roles',
message: 'Invalid Application role(s) [635ef5c8-54c5-4605-ba0f-add6ad1578ce (app: ExampleNodeApp)].'
}
]
},
generalErrors: []
Here is the user I'm importing in JSON:
{"email":"a@example.com",
"encryptionScheme":"example-wordpress-phpass",
"factor":8,"password":"JFAkQi9rQ3pUTURWN2NjQ2xhUlNoSlB6OHN1V1FkS2M1Lw==",
"salt":"JFAkQi9rQ3pUTURWN2NjQ2xhUlNoSlB6OHN1V1FkS2M1Lw==",
"uniqueUsername":"a",
"username":"a",
"verified":false,
"active":true,
"registrations":[{"applicationId":"e9fdb985-9173-4e01-9d73-ac2d60d1dc8e","roles":["635ef5c8-54c5-4605-ba0f-add6ad1578ce"]}],
"data":{"WordPress_ID":2,"WordPress_user_nicename":"a","WordPress_user_registered":"2024-02-21 10:52:53","WordPress_display_name":"a","WordPress_nickname":"a","WordPress_wp_capabilities":{"subscriber":true},"WordPress_default_password_nag":"1"}}
What must I change in my import user to get this to work please? The applicationId is correct and the roleId, I've checked in the web interface.