Integration with your own API

In this guide, you will learn how to integrate your own Bot dispatch API with the network.

Prerequisites

  • A domain name
  • A web server
  • Intermediate software knowledge

Step 1: Create a new API V2

You need to create a new API V2 to integrate your own API with the network. Below is an example code in Node.js.

const express = require('express');
const app = express();
const port = 80;
const bodyParser = require('body-parser');
const multer = require('multer');

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(multer().none());

app.post('/api/v2', async (req, res) => {
    const { key, action } = req.body;
    if (key !== 'YOUR_API_KEY') return res.status(401).json({ error: 'Invalid API key' });

    switch (action) {
        case 'services':
             // Return your services list  
             res.json([
                    {
                        "service": 1,
                        "name": "Followers",
                        "category": "First Category",
                        "type": "Default",
                        "rate": "0.73",
                        "min": "100",
                        "max": "10000",
                        "dripfeed": false,
                        "refill": false,
                        "cancel": false,
                        "description": "-"
                    },
                    {
                        "service": 2,
                        "name": "Comments",
                        "type": "Custom Comments",
                        "category": "Second Category",
                        "rate": "12",
                        "min": "10",
                        "max": "2500",
                        "refill": false,
                        "cancel": true,
                        "description": "-"
                    }
                ]);
            break;
        case 'status':
            // Return order status
            let { order, orders } = req.body; // order => single order (123), orders => multiple orders (123,124,125) max 100 orders

            // Your status logic here

            res.json({
                "charge": "0.65788",
                "start_count": "12",
                "status": "Pending", // Pending, Processing, In Progress, Completed, Canceled, Partial, Failed, Refunded
                "remains": "200",
                "currency": "EUR"
            });
            
            /*
                res.json({ error: 'Incorrect order ID' }); // If order not found

                Multiple orders status:
                res.json({
                    "123456": {
                        "charge": "1.03841045",
                        "start_count": "1",
                        "status": "In progress",
                        "remains": "287",
                        "currency": "EUR"
                    },
                    "123457": {
                        "charge": "0.657880205",
                        "start_count": "12",
                        "status": "Pending",
                        "remains": "23",
                        "currency": "EUR"
                    },
                    "123458": {
                        "error": "Incorrect order ID"
                    }
                });
            */
            break;
        case "refill":
            // Refill order
            let { order, orders } = req.body; // order => single order (123), orders => multiple orders (123,124,125) max 100 orders

            // Your refill logic here

            res.json({
                "order": "123456",
                "refill": "1", // Return refill id
                "message": "Your refill request has been received, please wait."
            });
            /*
            Multiple orders refill:
            res.json([
                {
                    "order": 123456,
                    "refill": 1, // Refill ID
                    "message": "Your refill request has been received, please wait."
                },
                {
                    "order": 123457,
                    "refill": 2, // Refill ID
                    "message": "Your refill request has been received, please wait."
                },
                {
                    "order": 123458,
                    "refill": {
                        "error": "Order cannot be refilled"
                    },
                    "message": "Order cannot be refilled"
                }
            ])
            */
            break;
        case 'refill_status':
            // Return refill status
            let { refill, refills } = req.body; // refill => single refill (123), refills => multiple refills (123,124,125) max 100 refills

            // Your refill status logic here

            res.json({
                "refill": 123456,
                "status": "Completed" // Pending, In Progress, Completed, Rejected, Failed
            });
            /*
            Multiple refills status:
            res.json([
                {
                    "refill": 123456,
                    "status": "Completed"
                },
                {
                    "refill": 123457,
                    "status": "Rejected"
                },
                {
                    "refill": 123458,
                    "status": {
                        "error": "Refill not found"
                    }
                }
            ])
            */
            break;
        case 'cancel':
            // Cancel order
            let { order, orders } = req.body; // order => single order (123), orders => multiple orders (123,124,125) max 100 orders

            // Your cancel logic here

            res.json({
                "order": 123456,
                "cancel": "Your cancellation request has been received."
            });
            /*
            Multiple orders cancel:
            res.json([
                {
                    "order": 123456,
                    "cancel": {
                        "error": "Incorrect order ID"
                    }
                },
                {
                    "order": 123457,
                    "cancel": "Your cancellation request has been received."
                },
                {
                    "order": 123458,
                    "cancel": "Your cancellation request has been received."
                }
            ])
            */
            break;
        case 'balance':
            // Return balance and currency
            res.json({
                "balance": "10000", // Keep it with a fixed maximum balance amount.
                "currency": "USD"
            });
            break;
        default:
            return res.status(400).json({ error: 'Invalid action' });
    }
});

app.listen(port, () => {
  console.log(`Server is running on http://localhost:${port}`);
});

Step 2: Expose your API to the internet

You need to expose your API to the internet. You can use Cloudflare to do this.

Step 3: Add your API to the network

You need to add your API to the network. You can do this by going to the SpeedSMM admin dashboard and adding your API.

Was this page helpful?