Create an API key
Usage
import { PinataSDK } from "pinata";
const pinata = new PinataSDK({
pinataJwt: process.env.PINATA_JWT!,
pinataGateway: "example-gateway.mypinata.cloud",
});
const key = await pinata.keys.create({
keyName: "user 1",
permissions: {
resources: [
"org:files:read",
"org:groups:read"
]
},
maxUses: 1,
});
Returns
type KeyResponse = {
JWT: string;
pinata_api_key: string;
pinata_api_secret: string;
};
Parameters
keyName
Name for the API key
const key = await pinata.keys.create({
keyName: "user 1",
permissions: {
admin: true,
},
maxUses: 1,
});
maxUses (Optional)
Limit the number of uses a key is valid for
const key = await pinata.keys.create({
keyName: "user 1",
permissions: {
admin: true,
},
maxUses: 1,
});
permissions
admin (Optional)
Grants the key admin access to all endpoints
const key = await pinata.keys.create({
keyName: "user 1",
permissions: {
admin: true,
}
});
resources (Optional)
- Type:
ResourcePermission[]
export type ResourcePermission =
| "org:read"
| "org:write"
| "org:files:read"
| "org:files:write"
| "org:groups:read"
| "org:groups:write"
| "org:gateways:read"
| "org:gateways:write"
| "org:analytics:read"
| "org:analytics:write";
Scope the API key by ResourcePermission
const key = await pinata.keys.create({
keyName: "user 1",
permissions: {
resources: [
"org:files:read",
"org:groups:read",
]
}
});
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
}
}
}
});