# The stateManager.getMatch() method
This documents the `stateManager.getMatch()` method.

This method has input parameters. The function could easily be defined as:
```ts
function getMatch(tournamentGuid: string, matchGuid: string): Match | undefined {
    // backend logic
}
```
## General usage:
```ts
const matchResponse: Match | undefined = taClient.stateManager.getMatch(tournamentGuid, matchGuid);
```

This method will return either the `Match` object or undefined. A `Match` can be described by the following TypeScript Interface:
```ts
interface Match {
    /**
     * @generated from protobuf field: string guid = 1;
     */
    guid: string;
    /**
     * @generated from protobuf field: repeated string associated_users = 2;
     */
    associatedUsers: string[];
    /**
     * @generated from protobuf field: string leader = 3;
     */
    leader: string;
    /**
     * @generated from protobuf field: proto.models.Map selected_map = 4;
     */
    selectedMap?: Map;
}
```

For the definition of a Map please look at the [Modals -> Map page](/documentation#Modals/4-Map)

A direct implementation:
```ts
try {
    // Check if the client is connected, connect to the server if not
    if(!client.isConnected) {
        // Connec to the server
        const connectResult = await client.connect($TAServerUrl, $TAServerPort);
        // Check if the connection is successful
        if (connectResult.details.oneofKind === "connect" && connectResult.type === Response_ResponseType.Fail) {
            throw new Error(connectResult.details.connect.message);
        }
    }
    
    // Get tournament and match data
    tournament = client.stateManager.getTournament(tournamentGuid);

    // This is the implementation, we just set the match object to the one we neem
    match = client.stateManager.getMatch(tournamentGuid, matchGuid);

    // Check if the logged in coordinator or user is added to the match properly
    if(!match?.associatedUsers.includes(client.stateManager.getSelfGuid())) {
        // If not, add the user to the match
        await addSelfToMatch();
    }
    
    // Check to see if we are actually viewing a valid match
    if (!match) {
        throw new Error('Match not found');
    }

    // This function just does some magic with the beatsaver data of the currently selected map
    await refreshMatchDetails(match);
} catch (err) {
    console.error('Error fetching match data:', err);
    error = err instanceof Error ? err.message : 'An unknown error occurred';
} finally {
    // Stop loading the page and allow everything to show data without errors
    isLoading = false;
}
```
<div class="info-box">
    <span class="material-icons">info</span>
    <div>
        <strong>Example:</strong> This is an example from the page of ShyyTAUI within the match coorination page. 
    </div>
</div>