Burial0268 Doorman uses a REST endpoint internally to update its database. You can use the same endpoints from a script.
Authenticate as any admin using Flarum Authentication headers https://docs.flarum.org/rest-api
And then it should be something like this (untested):
POST /api/fof/doorkeys
{
"data": {
"attributes": {
"key": "<random value>",
"groupId": 3,
"maxUses": 10,
"activates": false
}
}
}
There are also endpoints to list, update and delete the codes, and one to send emails.
You can use the browser development tools to inspect the requests Doorman makes when you use the admin panel to see how each endpoint works.
Since those endpoints are not officially documented they could be subject to changes in future updates but it's very unlikely.