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 section.

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.


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.

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;
  }
}

Last updated