Anonymous registering fails

Hi, I’m new to Asterisk and I’m working on a complex project where I’m finding some difficulties.
I have thought a solution but I don’t know if it’s an appropiate one and I can’t get it working, so I’m going to explain my use case briefly:
I need to receive SIP calls from multiple devices and be able to control (hold, redirect, etc) those calls programatically. My idea was to use Asterisk and develop an ARI app to control the calls.
On the asterisk app I’m going to control whether the calls are vaild or not, using the SIP direction and some other headers that I’ll check on a custom DB.
Now, as the accepted devices are already available on my custom database, I don’t want to manually set up an endpoint for each different device that could call me (that would be an insane work because there could be thousands). The only way I have found to avoid this is to set up an anonymous endpoint on pjsip.conf as explained here . However, even if I set up that endpoint, I can’t register on the server with an account whose endpoint is not created, and I get multiple Endpoint ‘anonymous’ has no configured AORs errors on the log. I found [this]p(PJSIP: how to correctly describe endpoint 'anonymous'?) refrence but it doesn’t explain how to solve the problem. I can’t perform calls neither.
The logs don’t show significant information.

Could somebody help me please? Why isn’t the anonymous endpoint working? Is there a better approach to solve this problem?
Thanks a lot!

Registration uses the name of the AOR as part of the address of record, so you can’t have an anonymous endpoint that is meaningful for registrations. Do you actually need to do outbound calls.

If you need outbound calls, and don’t know the endpoint contact address, you will need to generate pjsip.conf as a database report, or create a view on your database, suitable for Asterisk Realtime Architecture, although I know very little about that, and even less about its use with chan_pjsip.

chan_sip, which is deprecated, and soon to be removed, does seem to have an autocreatepeer option, with lots of warnings about not being a safe thing to do.

What about allowguest?
Once you will allow only those with specific sip header, that could be the short way.

Allow guest is about incoming calls. Registration is about outgoing ones. You can completely ignore the identity of a guest, but you can’t ignore the identity when registering, as you need to know the identity to lookup the correct contact address for the outgoing call.

Yes, I need to receive those calls and then be able to redirect them to another client. I’ll also need to perform outgoing calls
So, the best way to accomplish this would be to generate pjsip.conf as a database report then?

Registration is irrelevant to incoming calls. If you just want to receive incoming calls, use an anonymous endpoint, and do not ask them to register.

Ok, thanks for your response!