hasurahasura-jwt

Creating new roles Using Hasura metadata API


I am new to Hasura metadata API, Are there any REST API options to create roles via REST API. I am not asking about inherited roles. Inherited roles don't meet my requirements.


Solution

  • You can use HASURA Metadata API to create a Permission and Pass the new role.

    For example, let's say you're going to create a role called "MODERATOR" and give insert permission to the "comments" table.

    you can use the pg_insert_permission POST API with body:

    {
    "type": "pg_create_insert_permission",
    "args": {
        "table": "comments",
        "source": "default",
        "role": "MODERATOR",
        "permission": {
            "check": {},
            "columns": ["comment"]
            }
        }
     }
    

    This will create New Role "MODERATOR" in Hasura and also set the insert permission as well. Hope that answers your question.