Quickstart

This guide shows you how to get started creating and managing a Wallet with our API

Create an Account

  1. Create your account on Inrupt's PodSpaces

  2. Save your login credentials securely

Generate Client Credentials

For simplicity in these first examples, we will interact with the Wallet directly from a backend service via OAuth Client Credentials. User-login via Solid OIDC is covered in Authentication.

  1. Generate client credentials on the Application Registration page

  2. Use the client credential to create a session.

async function initializeAndLoginSession() {
  const session = new Session();
  await session.login({
    clientId: process.env.CLIENT_ID,
    clientSecret: process.env.CLIENT_SECRET,
    oidcIssuer: "https://login.inrupt.com",
    tokenType: "Bearer",
  });
  
  if (session.info.isLoggedIn && session.info.webId) {
    console.log("Session logged in successfully with WebID");
    return session;
  } else {
    console.error("User is not logged in");
    return null;
  }
}

Add Data to the Wallet

async function uploadFile() {
  const session = await initializeAndLoginSession();
  const walletContainer = "https://datawallet.inrupt.com/wallet";
  const path = "path/where/the/file/is/located" + "/text.txt";
  const fileBuffer = await readFile(path);
  const formData = new FormData();
  const file = new File([fileBuffer], path);
  formData.append("file", file);
  formData.append("fileName", fileName);

  const response = await session.fetch(walletContainer, {
    method: "PUT",
    body: formData,
  });

  if (response.status === 200) {
    return "File uploaded successfully";
  } else {
    console.log(response);
  }
}

Get the Wallet Data

async function getFile() {
  const session = await initializeAndLoginSession();
  const walletContainer = "https://datawallet.inrupt.com/wallet";
  const file = walletContainer + "/text.txt";
  
  if (!session) {
    throw new Error("Session is undefined");
  }
  
  const response = await session.fetch(file, {
    method: "GET",
  });
  
  if (response.status === 200) {
    const fetchCredential = await response.text();
    return fetchCredential;
  }
}

Delete Data from the Wallet

async function deleteFile() {
  const session = await initializeAndLoginSession();
  const walletContainer = "https://datawallet.inrupt.com/wallet";
  const file = walletContainer + "/text.txt";
  
  if (!session) {
    throw new Error("Session is undefined");
  }
  
  const response = await session.fetch(file, {
    method: "DELETE",
  });
  
  if (response.status === 200) {
    return "file deleted successfully";
  }
}

Last updated