getFileById
Retrieve detailed information about a specific file stored on Pinata's IPFS network using its unique identifier. Access file metadata and content from public or private IPFS storage.
Instructions
Retrieve detailed information about a specific file stored on Pinata by its ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| network | No | Whether the file is in public or private IPFS | public |
| id | Yes | The unique ID of the file to retrieve |
Implementation Reference
- src/index.ts:216-247 (handler)The getFileById tool handler that retrieves detailed information about a specific file stored on Pinata by its ID. It takes network (public/private) and id parameters, makes a GET request to the Pinata API endpoint, and returns the response data.
server.tool( "getFileById", "Retrieve detailed information about a specific file stored on Pinata by its ID", { network: z .enum(["public", "private"]) .default("public") .describe("Whether the file is in public or private IPFS"), id: z.string().describe("The unique ID of the file to retrieve"), }, async ({ network, id }) => { try { const url = `https://api.pinata.cloud/v3/files/${network}/${id}`; const response = await fetch(url, { method: "GET", headers: getHeaders(), }); if (!response.ok) { throw new Error( `Failed to get file: ${response.status} ${response.statusText}` ); } const data = await response.json(); return successResponse(data); } catch (error) { return errorResponse(error); } } ); - src/index.ts:219-225 (schema)The input schema for getFileById tool using Zod validation. Defines two parameters: network (enum: public/private, defaults to public) and id (required string).
{ network: z .enum(["public", "private"]) .default("public") .describe("Whether the file is in public or private IPFS"), id: z.string().describe("The unique ID of the file to retrieve"), }, - src/index.ts:100-108 (helper)The getHeaders helper function that returns authorization headers with the PINATA_JWT bearer token, used by the getFileById tool for API requests.
const getHeaders = () => { if (!PINATA_JWT) { throw new Error("PINATA_JWT environment variable is not set"); } return { Authorization: `Bearer ${PINATA_JWT}`, "Content-Type": "application/json", }; }; - src/index.ts:111-124 (helper)Helper functions for consistent API responses - errorResponse for errors and successResponse for successful data returns, used by getFileById.
const errorResponse = (error: unknown) => ({ content: [ { type: "text" as const, text: `Error: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }); // Helper for consistent success responses const successResponse = (data: unknown) => ({ content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }], });