Auth0 Home Blog Docs

Create Rule via Api

auth0

#1

Hi There,

I am trying to create rule via the management API. I am getting the error {“statusCode”:400,“error”:“Bad Request”,“message”:“Payload validation error: ‘Additional properties not allowed: id’.”,“errorCode”:“invalid_body”}`

here is the code which m using

const ruleScript = “function (user, context, callback) {\n callback(null, user, context);\n}”;
const ruleName = Auth Server Update;
const rules: Rule[] = [{ name: ruleName, enabled: true, id: ‘newrule’, order: 1, script: ruleScript, stage: ‘login_success’ }];

management.createRule(rules[0], (err: Error, rule) => {
console.log(err, rule);
});

Any help would be really appreciated.
Thanks


#2

Hi @akshay.verma

When creating the rule you are unable to specify the id as this is an auto-generated field.

The only fields you may specify when creating a rule are: name, script, order, and enabled.

Hope this helps!