The IPFS Pinning Service API is intended to be an implementation-agnostic API:
- For use and implementation by pinning service providers
- For use in client mode by IPFS nodes and GUI-based applications
### Document scope and intended audience
The intended audience of this document is **IPFS developers** building pinning service clients or servers compatible with this OpenAPI spec.
Your input and feedback are welcome and valuable as we develop this API spec. Please join the design discussion at [github.com/ipfs/pinning-services-api-spec](https://github.com/ipfs/pinning-services-api-spec).
**IPFSusers** should see the tutorial at [docs.ipfs.io/how-to/work-with-pinning-services](https://docs.ipfs.io/how-to/work-with-pinning-services/) instead.
### Related resources
The latest version of this spec and additional resources can be found at:
- Clients and services:https://github.com/ipfs/pinning-services-api-spec#adoption
# Schemas
This section describes the most important object types and conventions.
A full list of fields and schemas can be found in the `schemas` section of the [YAML file](https://github.com/ipfs/pinning-services-api-spec/blob/master/ipfs-pinning-service.yaml).
## Identifiers
### cid
[Content Identifier (CID)](https://docs.ipfs.io/concepts/content-addressing/) points at the root of a DAG that is pinned recursively.
### requestid
Unique identifier of a pin request.
When a pin is created, the service responds with unique `requestid` that can be later used for pin removal. When the same `cid` is pinned again, a different `requestid` is returned to differentiate between those pin requests.
Service implementation should use UUID, `hash(accessToken,Pin,PinStatus.created)`, or any other opaque identifier that provides equally strong protection against race conditions.
The `Pin` object is a representation of a pin request.
It includes the `cid` of data to be pinned, as well as optional metadata in `name`, `origins`, and `meta`.
Addresses provided in `origins` list are relevant only during the initial pinning, and don't need to be persisted by the pinning service.
### Pin status response
![pin status response object](https://bafybeideck2fchyxna4wqwc2mo67yriokehw3yujboc5redjdaajrk2fjq.ipfs.dweb.link/pinstatus.png)
The `PinStatus` object is a representation of the current state of a pinning operation.
It includes values from the original `Pin` object, along with the current `status` and globally unique `requestid` of the entire pinning request, which can be used for future status checks and management.
Addresses in the `delegates` array are peers designated by pinning service that will receive the pin data over bitswap (more details in the [Provider hints](#section/Provider-hints) section). Any additional vendor-specific information is returned in optional `info`.
# The pin lifecycle
![pinning service objects and lifecycle](https://bafybeideck2fchyxna4wqwc2mo67yriokehw3yujboc5redjdaajrk2fjq.ipfs.dweb.link/lifecycle.png)
## Creating a new pin object
The user sends a `Pin` object to `POST /pins` and receives a `PinStatus` response:
- `requestid` in `PinStatus` is the identifier of the pin operation, which can can be used for checking status, and removing the pin in the future
- `status` in `PinStatus` indicates the current state of a pin
## Checking status of in-progress pinning
`status` (in `PinStatus`) may indicate one of the two pending states:`queued` or `pinning`:
- `queued` is passive:the pin was added to the queue but the service isn't consuming any resources to retrieve it yet.
- `pinning` is active:the pinning service is trying to retrieve the CIDs by finding providers for all involved CIDs, connect to these providers and download data from them.
When a new pin object is created it typically starts in a `queued` state. Once the pinning service actively seeks to retrieve the file it changes to `pinning`. `pinning` typically means that the data behind `Pin.cid` was not found on the pinning service and is being fetched from the IPFS network at large, which may take time.
In either case, the user can periodically check pinning progress via `GET /pins/{requestid}` until pinning is successful, or the user decides to remove the pending pin.
## Replacing an existing pin object
The user can replace an existing pin object via `POST /pins/{requestid}`. This is a shortcut for removing a pin object identified by `requestid` and creating a new one in a single API call that protects against undesired garbage collection of blocks common to both pins. Useful when updating a pin representing a huge dataset where most of blocks did not change. The new pin object `requestid` is returned in the `PinStatus` response. The old pin object is deleted automatically.
## Removing a pin object
A pin object can be removed via `DELETE /pins/{requestid}`.
# Provider hints
Provider hints take the form of two [multiaddr](https://docs.ipfs.io/concepts/glossary/#multiaddr) lists:`Pin.origins` and `PinStatus.delegates`
## Pin.origins
A list of known sources (providers) of the data. Sent by a client in a pin request.
Pinning service will try to connect to them to speed up data transfer.
## PinStatus.delegates
A list of temporary destination (retrievers) for the data. Returned by pinning service in a response for a pin request.
These peers are provided by a pinning service for the purpose of fetching data about to be pinned.
## Optimizing for speed and connectivity
Both ends should attempt to preconnect to each other:
- Delegates should always preconnect to origins
- Clients who initiate pin request and also have the pinned data in their own local datastore should preconnect to delegates
**NOTE:**Connections to multiaddrs in `origins` and `delegates` arrays should
be attempted in best-effort fashion, and dial failure should not fail the
pinning operation. When unable to act on explicit provider hints, DHT and
other discovery methods should be used as a fallback by a pinning service.
## Rationale
A pinning service will use the DHT and other discovery methods to locate pinned
content; however, it may not be able to retrieve data if the only provider
has no publicly diallable address (e.g. a desktop peer behind a restrictive NAT/firewall).
Leveraging provider hints mitigates potential connectivity issues and speeds up the content routing phase.
If a client has the data in their own datastore or already knows of other providers, the transfer will start immediately.
The most common scenario is a client putting its own IPFS node's multiaddrs in
`Pin.origins`, and then attempt to connect to every multiaddr returned by a
pinning service in `PinStatus.delegates` to initiate transfer. At the same
time, a pinning service will try to connect to multiaddrs provided by the client
in `Pin.origins`.
This ensures data transfer starts immediately (without waiting for provider
discovery over DHT), and mutual direct dial between a client and a service
works around peer routing issues in restrictive network topologies, such as
NATs, firewalls, etc.
**NOTE:**All multiaddrs MUST end with `/p2p/{peerID}` and SHOULD be fully
resolved and confirmed to be dialable from the public internet. Avoid sending
addresses from local networks.
# Custom metadata
Pinning services are encouraged to add support for additional features by leveraging the optional `Pin.meta` and `PinStatus.info` fields.
While these attributes can be application- or vendor-specific, we encourage the community at large to leverage these attributes as a sandbox to come up with conventions that could become part of future revisions of this API.
## Pin metadata
String keys and values passed in `Pin.meta` are persisted with the pin object.
This is an opt-in feature:It is OK for a client to omit or ignore these optional attributes, and doing so should not impact the basic pinning functionality.
Potential uses:
- `Pin.meta[app_id]`:Attaching a unique identifier to pins created by an app enables meta-filtering pins per app
- `Pin.meta[vendor_policy]`: Vendor-specific policy (for example:which region to use, how many copies to keep)
### Filtering based on metadata
The contents of `Pin.meta` can be used as an advanced search filter for situations where searching by `name` and `cid` is not enough.
Metadata key matching rule is `AND`:
- lookup returns pins that have `meta` with all key-value pairs matching the passed values
- pin metadata may have more keys, but only ones passed in the query are used for filtering
The wire format for the `meta` when used as a query parameter is a [URL-escaped](https://en.wikipedia.org/wiki/Percent-encoding) stringified JSON object.
A lookup example for pins that have a `meta` key-value pair `{\"app_id\":\"UUID\"}` is:
description:Replace an existing pin object (shortcut for executing remove and add operations in one step to avoid unnecessary garbage collection of blocks present in both recursive pins)
app_id:"99986338-1113-4706-8302-4420da6158aa"# Pin.meta[app_id], useful for filtering pins per app
StatusInfo:
description:Optional info for PinStatus response
type:object
additionalProperties:
type:string
minProperties:0
maxProperties:1000
example:
status_details:"Queue position: 7 of 9"# PinStatus.info[status_details], when status=queued
TextMatchingStrategy:
description:Alternative text matching strategy
type:string
default:exact
enum:
- exact # full match, case-sensitive (the implicit default)
- iexact # full match, case-insensitive
- partial # partial match, case-sensitive
- ipartial# partial match, case-insensitive
Failure:
description:Response for a failed request
type:object
required:
- error
properties:
error:
type:object
required:
- reason
properties:
reason:
type:string
description:Mandatory string identifying the type of error
example:"ERROR_CODE_FOR_MACHINES"
details:
type:string
description:Optional, longer description of the error; may include UUID of transaction for support, links to documentation etc
example:"Optional explanation for humans with more details"
parameters:
before:
description:Return results created (queued) before provided timestamp
name:before
in:query
required:false
schema:
type:string
format:date-time # RFC 3339, section 5.6
example:"2020-07-27T17:32:28.276Z"
after:
description:Return results created (queued) after provided timestamp
name:after
in:query
required:false
schema:
type:string
format:date-time # RFC 3339, section 5.6
example:"2020-07-27T17:32:28.276Z"
limit:
description:Max records to return
name:limit
in:query
required:false
schema:
type:integer
format:int32
minimum:1
maximum:1000
default:10
cid:
description:Return pin objects responsible for pinning the specified CID(s); be aware that using longer hash functions introduces further constraints on the number of CIDs that will fit under the limit of 2000 characters per URL in browser contexts
name:cid
in:query
required:false
schema:
type:array
items:
type:string
uniqueItems:true
minItems:1
maxItems:10
style:form# ?cid=Qm1,Qm2,bafy3
explode:false
example:["Qm1","Qm2","bafy3"]
name:
description:Return pin objects with specified name (by default a case-sensitive, exact match)
name:name
in:query
required:false
schema:
type:string
maxLength:255
example:"PreciousData.pdf"
match:
description:Customize the text matching strategy applied when the name filter is present; exact (the default) is a case-sensitive exact match, partial matches anywhere in the name, iexact and ipartial are case-insensitive versions of the exact and partial strategies
name:match
in:query
required:false
schema:
$ref:'#/components/schemas/TextMatchingStrategy'
example:exact
status:
description:Return pin objects for pins with the specified status (when missing, service should default to pinned only)
name:status
in:query
required:false
schema:
type:array
items:
$ref:'#/components/schemas/Status'
uniqueItems:true
minItems:1
style:form# ?status=queued,pinning
explode:false
example:["queued","pinning"]
meta:
description:Return pin objects that match specified metadata keys passed as a string representation of a JSON object; when implementing a client library, make sure the parameter is URL-encoded to ensure safe transport
name:meta
in:query
required:false
content:
application/json:# ?meta={"foo":"bar"}
schema:
$ref:'#/components/schemas/PinMeta'
responses:
BadRequest:
description:Error response (Bad request)
content:
application/json:
schema:
$ref:'#/components/schemas/Failure'
examples:
BadRequestExample:
$ref:'#/components/examples/BadRequestExample'
Unauthorized:
description:Error response (Unauthorized; access token is missing or invalid)
content:
application/json:
schema:
$ref:'#/components/schemas/Failure'
examples:
UnauthorizedExample:
$ref:'#/components/examples/UnauthorizedExample'
NotFound:
description:Error response (The specified resource was not found)