Retrieve private file
curl --request GET \
--url https://402.pinata.cloud/v1/retrieve/private/{cid} \
--header 'X-PAYMENT: <api-key>'import requests
url = "https://402.pinata.cloud/v1/retrieve/private/{cid}"
headers = {"X-PAYMENT": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'X-PAYMENT': '<api-key>'}};
fetch('https://402.pinata.cloud/v1/retrieve/private/{cid}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://402.pinata.cloud/v1/retrieve/private/{cid}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"X-PAYMENT: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://402.pinata.cloud/v1/retrieve/private/{cid}"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("X-PAYMENT", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://402.pinata.cloud/v1/retrieve/private/{cid}")
.header("X-PAYMENT", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://402.pinata.cloud/v1/retrieve/private/{cid}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["X-PAYMENT"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"url": "<string>"
}x402 Services
Retrieve a Private File
Retrieves a private file from IPFS by its CID
GET
/
retrieve
/
private
/
{cid}
Retrieve private file
curl --request GET \
--url https://402.pinata.cloud/v1/retrieve/private/{cid} \
--header 'X-PAYMENT: <api-key>'import requests
url = "https://402.pinata.cloud/v1/retrieve/private/{cid}"
headers = {"X-PAYMENT": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'X-PAYMENT': '<api-key>'}};
fetch('https://402.pinata.cloud/v1/retrieve/private/{cid}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://402.pinata.cloud/v1/retrieve/private/{cid}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"X-PAYMENT: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://402.pinata.cloud/v1/retrieve/private/{cid}"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("X-PAYMENT", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://402.pinata.cloud/v1/retrieve/private/{cid}")
.header("X-PAYMENT", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://402.pinata.cloud/v1/retrieve/private/{cid}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["X-PAYMENT"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"url": "<string>"
}Cost
| Price | Duration |
|---|---|
| $0.0001 | Per request |
Example Usage
If you upload a file asprivate then it will not be accessible on public IPFS, so in order to access it you need to create a temporary access URL. This flow is similar to the previous one, except you would provide the CID that you uploded previously that you would like to access. After a successful payment the server will return a URL you can access the file with.
import { wrapFetchWithPayment, decodeXPaymentResponse } from "@x402/fetch";
import { account } from "./viem";
const fetchWithPayment = wrapFetchWithPayment(fetch, account);
const url =
"https://402.pinata.cloud/v1/retrieve/private/bafkreih5aznjvttude6c3wbvqeebb6rlx5wkbzyppv7garjiubll2ceym4";
fetchWithPayment(url, {
method: "GET",
})
.then(async (response) => {
const body = (await response.json()) as { url: string };
console.log(body);
})
.catch((error) => {
console.error(error.response?.data?.error);
});