Bybit REST V5 p2p JavaScript example for the Siebly Bybit SDK, covering exchange REST API and WebSocket integration, setup, and production SDK docs.
We use environment variables in our examples for API keys. It is your responsibility to manage and secure your keys appropriately.
bybit-api instead of hand-written HTTP request plumbing.Bybit/Rest/rest-v5-p2p.ts.RestClientV5.getP2POrders(), uploadP2PChatFile().import { RestClientV5 } from 'bybit-api';import fs from 'fs';import path from 'path'; // ENDPOINT: /v5/p2p/oss/upload_file// METHOD: POST// PUBLIC: NO// NOTE: Node.js only (Buffer required) const key = process.env.API_KEY_COM;const secret = process.env.API_SECRET_COM; const client = new RestClientV5({ key: key, secret: secret,}); async function uploadP2PChatFile() { try { // You must read the file yourself and pass the Buffer + filename const filePath = './docs/images/logo1.png'; const fileBuffer = fs.readFileSync(filePath); /** * * * * * * */ // Test basic P2P API connectivity const result0 = await client.getP2POrders({ page: 1, size: 1, }); console.log('Get P2P orders result:', result0); // Example 1: Upload from file path const result1 = await client.uploadP2PChatFile({ fileBuffer: fileBuffer, fileName: path.basename(filePath), // Extract filename from path }); console.log( 'Upload from file path result:', JSON.stringify(result1, null, 2), ); // Example 2: Upload with custom filename // You control the filename sent to Bybit const result2 = await client.uploadP2PChatFile({ fileBuffer: fileBuffer, fileName: 'custom-name.png', // Use any filename you want }); console.log('Upload with custom filename result:', result2); // Example 3: Upload different file const pdfBuffer = fs.readFileSync('./document.pdf'); const result3 = await client.uploadP2PChatFile({ fileBuffer: pdfBuffer, fileName: 'document.pdf', }); console.log('Upload PDF result:', result3); // Supported file types (determined by filename extension): // - Images: jpg, jpeg, png // - Documents: pdf // - Videos: mp4 } catch (e) { console.error('Error uploading file:', e); }} uploadP2PChatFile(); We use essential cookies and optional analytics. Read the Privacy Policy.
Essential cookies stay on. Toggle analytics if you want to share anonymous usage insights. You can revisit this anytime via Cookie Settings in the footer.