Generate API Key

Endpoint

/users/generateApiKey

Description

This endpoint allows an administrator to issue new API keys for their Pinata account programmatically. The only key type that can be used to issue new keys is the Admin key. See the API Keys page to generate keys in the UI.

The purpose of this endpoint is to allow for the programmatic creation of API keys that may be used for multiple projects, individual users, or a variety of other use cases where a single API key pair across an account is not sufficient.

This endpoint will return three values: The API Key, the API Secret, and a JWT Bearer Token.

Make sure to record the API Secret and the JWT as they will not be accessible again.

Type

POST

Headers

Body

The format for creating new keys is as follows:

Basic Request

You must set the admin property to true or you must include at least one enabled endpoint in the endpoints object.

{
keyName: (A name for your new key for easy reference - Required),
maxUses: (Number of times the new api keys can be used - Optional),
permissions: {
admin boolean,
endpoints: {
data: {
pinList: boolean,
userPinnedDataTotal: boolean
},
pinning: {
hashMetadata: boolean,
hashPinPolicy: boolean,
pinByHash: boolean,
pinFileToIPFS: boolean,
pinJSONToIPFS: boolean,
pinJobs: boolean,
unpin: boolean,
userPinPolicy: boolean
}
}
}
}

Response

{
"pinata_api_key": "KEY",
"pinata_api_secret": "SECRET",
"JWT": "JWT"
}

Postman Example

JavaScript With Axios Example

When setting the body payload, you must have either the admin property set to true or you must have the endpoints object with at least one endpoint enabled with a true value.

const axios = require('axios');
‚Äč
export const generateApiKey = (pinataApiKey, pinataSecretApiKey) => {
const url = `https://api.pinata.cloud/users/generateApiKey`;
const body = {
keyName: 'Example Key',
permissions: {
endpoints: {
data: {
userPinnedDataTotal: true
},
pinning: {
pinJobs: true,
unpin: true,
userPinPolicy: true
}
}
}
};
return axios
.post(url, body, {
headers: {
pinata_api_key: pinataApiKey,
pinata_secret_api_key: pinataSecretApiKey
}
})
.then(function (response) {
//handle response here
})
.catch(function (error) {
//handle error here
});
};

We want your feedback!

Have a suggestion? Have a complaint? Confused about something in the documentation? Just want to say hi?

We want to make Pinata the best product available. That involves listening to our users and addressing their needs.

Send us an email at [email protected] and we'll see how we can help.