'How to allow new custom api endpoint accessable via code without admin panel?

I am creating api from commands in version 3 and want to give new created api head permission public or authenticated for access manually via nodejs code, without use of admin panel from backend. i want programatic solution of steps in strapi headless cms ( from admin panel go to settings >roles>public or authenticated>grant or revoke permission) .



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source