# Access Grants

## View Access Requests

The **`readInbox`** function visualizes all access requests by utilizing a user session to interact with the Data Wallet API. It retrieves pending access requests by sending a GET request to the **`https://datawallet.inrupt.com/inbox`** endpoint, returning a JSON object detailing each request. The session is explained in the [Quickstart](/getting-started/readme.md) section.

```javascript
async function readInbox() {
  const session = await initializeAndLoginSession();
  const walletAPI = `https://datawallet.inrupt.com/inbox`;

  if (!session) {
    throw new Error("Session is undefined");
  }
  const response = await session.fetch(walletAPI, {
    method: "GET",
  });
  if (response.status === 200) {
    const fetchAR = await response.json();
    return fetchAR;
  }
}
```

## Accept Access Request

To obtain the **`id`** needed for the **`acceptAccessRequest`** function, initially utilize the **`readInbox`** function to retrieve all pending access requests. The **`readInbox`** function returns a JSON object containing details of these requests, including their unique identifiers. Identify the specific request you wish to accept and extract its **`id`** from this object to pass it as a parameter when calling the **`acceptAccessRequest`** function.

```javascript

async function acceptAccessRequest(id) {
  const session = await initializeAndLoginSession();
  const walletAPI = `https://datawallet.inrupt.com/inbox`;
  const fullURL = walletAPI + "/" + id + "/grantAccess";

  if (!session) {
    throw new Error("Session is undefined");
  }
  const response = await session.fetch(fullURL, {
    method: "PUT",
  });

  if (response.status === 200) {
    return "Access Request accepted";
  }
}
```

## View Access Grants

The **`getAccessGrants`** function retrieves a list of access grants associated with different agents, users, or businesses by making a GET request to the specified **`walletAPI`** URL. This URL points to the endpoint that contains access grant information. The function first initializes and logs into a session. If the session is valid, it requests the **`/accessgrants`** endpoint and processes the response. The function parses the returned JSON data, which contains details about the access grants.

```javascript
async function getAccessGrants() {
  const session = await initializeAndLoginSession();
  const walletAPI = `https://datawallet.inrupt.com/accessgrants`;

  if (!session) {
    throw new Error("Session is undefined");
  }
  const response = await session.fetch(walletAPI, {
    method: "GET",
  });
  if (response.status === 200) {
    const fetchCredential = await response.json();
    return fetchCredential;
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.inrupt.com/getting-started/access-grants.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
