> For the complete documentation index, see [llms.txt](https://mujahid.gitbook.io/decast-gating-document/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mujahid.gitbook.io/decast-gating-document/helper-view-functions/gettokenidofaccesslevel.md).

# getTokenIdOfAccessLevel

This view function retrieves the token ID associated with a specific access level for an event. It takes two parameters:

* `_eventId`: The unique identifier for the event.
* `_accessLevel`: The access level for which to retrieve the token ID.

````solidity
// Some code

```remix-solidity
 /**
    GetTokenIdOfAccessLevel: Get the token ID associated with a specific access level for an event.
    @param _eventId: The unique identifier for the event.
    @param _accessLevel: The access level for which to retrieve the token ID.
    @return _tokenId: The token ID associated with the specified access level.
    */
    function getTokenIdOfAccessLevel(
        string calldata _eventId,
        string calldata _accessLevel
    ) public view returns (uint256) {
        uint256 _tokenId;

        // Retrieve all token IDs and access levels for the event
        uint256[] memory tokenIds = getTokenIdsFromEventId(_eventId);
        string[] memory accessLevels = getAccessLevelsFromEventId(_eventId);

        // Loop through access levels to find matching access level and retrieve corresponding token ID
        for (
            uint256 i = 0;
            i < tokenIds.length && i < accessLevels.length;
            ++i
        ) {
            if (
                keccak256(bytes(_accessLevel)) ==
                keccak256(bytes(accessLevels[i]))
            ) {
                _tokenId = tokenIds[i];
                break;
            }
        }

        // Revert if no matching token ID is found
        if (_tokenId == 0) {
            revert DecastGating__TokenIdDoesNotExists();
        }
        return _tokenId;
    }
```
````

## Explanation:

The function first retrieves all token IDs and access levels associated with the provided event ID using helper functions [`getTokenIdsFromEventId` ](/decast-gating-document/getter-view-functions.md)and [`getAccessLevelsFromEventId`](/decast-gating-document/getter-view-functions.md). Then, it iterates through these arrays to find a match between the provided access level and the access levels associated with the event. If a match is found, it retrieves the corresponding token ID.

If no matching token ID is found, the function reverts with the error message `DecastGating__TokenIdDoesNotExists`.

Finally, the function returns the retrieved token ID associated with the specified access level.
