@fusionauth-qhj5e I am checking with the team if you indeed should be able to send in the Id for the role as you are in the example. For now you should be able to add Subscriber
which is the name of your new role.
Here is a full example.
app.get('/registration', async (req, res, next) => {
let returnResult;
try {
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);
// make sure to remove role each time
await fa.deleteApplicationRole(applicationId,subscriberRoleId);
// add role
await fa.createApplicationRole(applicationId, subscriberRoleId, { role: {
id: subscriberRoleId,
isDefault: false,
isSuperRole: false,
name: 'Subscriber',
description: 'Subscriber'
} });
const user = {
"email": "a@example.com",
"encryptionScheme": "phpass-md5", // I updated this from wordpress
"factor": 8, "password": "JFAkQi9rQ3pUTURWN2NjQ2xhUlNoSlB6OHN1V1FkS2M1Lw==",
"salt": "JFAkQi9rQ3pUTURWN2NjQ2xhUlNoSlB6OHN1V1FkS2M1Lw==",
"uniqueUsername": "a",
"username": "a",
"verified": false,
"active": true,
"registrations": [{ "applicationId": applicationId, "roles": ['Subscriber'] }],
"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" }
}
const importRequest = { users: [user], validateDbConstraints: true };
const result = await fa.importUsers(importRequest);
console.log("result", result)
returnResult = result;
} catch (e) {
returnResult = JSON.stringify(e);
console.error("error", returnResult);
}
res.json(JSON.stringify({
returnResult
}))
});
Please also take note you may need to update your encryptionScheme
to phpass-md5
as I believe this is what will come from Wordpress.
You can find more details https://fusionauth.io/docs/reference/password-hashes