Create an API key

Usage

import { PinataSDK } from "pinata-web3";

const pinata = new PinataSDK({
  pinataJwt: process.env.PINATA_JWT!,
  pinataGateway: "example-gateway.mypinata.cloud",
});

const key = await pinata.keys.create({
  keyName: "user 1",
  permissions: {
    admin: true,
  },
  maxUses: 1,
});

Returns

type KeyResponse = {
  JWT: string;
  pinata_api_key: string;
  pinata_api_secret: string;
};

Parameters

keyName

  • Type: string

Name for the API key

const key = await pinata.keys.create({
  keyName: "user 1"
});

maxUses (Optional)

  • Type: number

Limit the number of uses a key is valid for

const key = await pinata.keys.create({
  maxUses: 2
});

permissions

admin (Optional)

  • Type: boolean

Grants the key admin access to all endpoints

const key = await pinata.keys.create({
  keyName: "user 1",
  permissions: {
    admin: true,
  }
});

endpoints (Optional)

const key = await pinata.keys.create({
  keyName: "user 1",
  permissions: {
    endpoints: {
      data: {
        pinList: true,
        userPinnedDataTotal: false
      },
      pinning: {
        hashMetadata: true,
        hashPinPolicy: false,
        pinByHash: true,
        pinFileToIPFS: true,
        pinJSONToIPFS: true,
        pinJobs: false,
        unpin: false,
        userPinPolicy: false
      }
    }
  }
});