# API

## Get your API key

Your API requests are authenticated using API keys. Any request that doesn't include an API key will return an error.

You can generate an API key from your Dashboard at any time.

## Make your first request

To make your first request, send an authenticated request to the pets endpoint. This will create a `pet`, which is nice.

## Service list

<mark style="color:green;">`POST`</mark> `https://smm.sec-nine.com/api/v2`

Retrieves the current service list.

#### Request Body

| Name                                     | Type   | Description  |
| ---------------------------------------- | ------ | ------------ |
| key<mark style="color:red;">\*</mark>    | string | Your API Key |
| action<mark style="color:red;">\*</mark> | string | services     |

{% tabs %}
{% tab title="200 successful" %}

```json
[
    {
        "service": 1,
        "name": "Followers",
        "type": "Default",
        "category": "First Category",
        "rate": "0.90",
        "min": "50",
        "max": "10000",
        "refill": true,
        "cancel": true
    },
    {
        "service": 2,
        "name": "Comments",
        "type": "Custom Comments",
        "category": "Second Category",
        "rate": "8",
        "min": "10",
        "max": "1500",
        "refill": false,
        "cancel": true
    }
]
```

{% endtab %}
{% endtabs %}

## Add order

<mark style="color:green;">`POST`</mark> `https://smm.sec-nine.com/api/v2`

#### Request Body

| Name                                       | Type   | Description         |
| ------------------------------------------ | ------ | ------------------- |
| key<mark style="color:red;">\*</mark>      | string | Your API Key        |
| action<mark style="color:red;">\*</mark>   | string | add                 |
| service<mark style="color:red;">\*</mark>  | int    | Service ID          |
| link<mark style="color:red;">\*</mark>     | string | Link to page        |
| quantity<mark style="color:red;">\*</mark> | int    | Needed quantity     |
| runs                                       | string | Runs to deliver     |
| interval                                   | string | Interval in minutes |

{% tabs %}
{% tab title="200 successful" %}

```json
{
    "order": 23501
}
```

{% endtab %}
{% endtabs %}

## Order status

<mark style="color:green;">`POST`</mark> `https://smm.sec-nine.com/api/v2`

#### Request Body

| Name                                     | Type   | Description  |
| ---------------------------------------- | ------ | ------------ |
| key<mark style="color:red;">\*</mark>    | string | Your API Key |
| action<mark style="color:red;">\*</mark> | string | status       |
| order<mark style="color:red;">\*</mark>  | int    | Order ID     |

{% tabs %}
{% tab title="200 successful" %}

```json
{
    "charge": "0.27819",
    "start_count": "3572",
    "status": "Partial",
    "remains": "157",
    "currency": "TRY"
}
```

{% endtab %}
{% endtabs %}

## Multiple orders status

<mark style="color:green;">`POST`</mark> `https://smm.sec-nine.com/api/v2`

#### Request Body

| Name                                     | Type   | Description                           |
| ---------------------------------------- | ------ | ------------------------------------- |
| key<mark style="color:red;">\*</mark>    | string | Your API Key                          |
| action<mark style="color:red;">\*</mark> | string | status                                |
| orders<mark style="color:red;">\*</mark> | string | (separated by a comma, up to 100 IDs) |

{% tabs %}
{% tab title="200 successful" %}

```json
{
    "1": {
        "charge": "0.27819",
        "start_count": "3572",
        "status": "Partial",
        "remains": "157",
        "currency": "USD"
    },
    "10": {
        "error": "Incorrect order ID"
    },
    "100": {
        "charge": "1.44219",
        "start_count": "234",
        "status": "In progress",
        "remains": "10",
        "currency": "USD"
    }
}
```

{% endtab %}
{% endtabs %}

## Create refill

<mark style="color:green;">`POST`</mark> `https://smm.sec-nine.com/api/v2`

#### Request Body

| Name                                     | Type   | Description  |
| ---------------------------------------- | ------ | ------------ |
| key<mark style="color:red;">\*</mark>    | string | Your API Key |
| action<mark style="color:red;">\*</mark> | string | refill       |
| order<mark style="color:red;">\*</mark>  | int    | Order ID     |

{% tabs %}
{% tab title="200 successful" %}

```json
{
    "refill": "1"
}
```

{% endtab %}
{% endtabs %}

## Create multiple refill

<mark style="color:green;">`POST`</mark> `https://smm.sec-nine.com/api/v2`

#### Request Body

| Name                                     | Type   | Description                                     |
| ---------------------------------------- | ------ | ----------------------------------------------- |
| key<mark style="color:red;">\*</mark>    | string | Your API Key                                    |
| action<mark style="color:red;">\*</mark> | string | refill                                          |
| orders<mark style="color:red;">\*</mark> | string | Order IDs (separated by a comma, up to 100 IDs) |

{% tabs %}
{% tab title="200 successful" %}

```json
[
    {
        "order": 1,
        "refill": 1
    },
    {
        "order": 2,
        "refill": 2
    },
    {
        "order": 3,
        "refill": {
            "error": "Incorrect order ID"
        }
    }
]
```

{% endtab %}
{% endtabs %}

## Get refill status

<mark style="color:green;">`POST`</mark> `https://smm.sec-nine.com/api/v2`

#### Request Body

| Name                                     | Type   | Description    |
| ---------------------------------------- | ------ | -------------- |
| key<mark style="color:red;">\*</mark>    | string | Your API Key   |
| action<mark style="color:red;">\*</mark> | string | refill\_status |
| refill<mark style="color:red;">\*</mark> | int    | Refill ID      |

{% tabs %}
{% tab title="200 successful" %}

```json
{
    "status": "Completed"
}
```

{% endtab %}
{% endtabs %}

## Get multiple refill status

<mark style="color:green;">`POST`</mark> `https://smm.sec-nine.com/api/v2`

#### Request Body

| Name                                      | Type   | Description                                      |
| ----------------------------------------- | ------ | ------------------------------------------------ |
| key<mark style="color:red;">\*</mark>     | string | Your API Key                                     |
| action<mark style="color:red;">\*</mark>  | string | refill\_status                                   |
| refills<mark style="color:red;">\*</mark> | string | Refill IDs (separated by a comma, up to 100 IDs) |

{% tabs %}
{% tab title="200 successful" %}

```json
[
    {
        "order": 1,
        "refill": 1
    },
    {
        "order": 2,
        "refill": 2
    },
    {
        "order": 3,
        "refill": {
            "error": "Incorrect order ID"
        }
    }
]
```

{% endtab %}
{% endtabs %}

## Create cancel

<mark style="color:green;">`POST`</mark> `https://smm.sec-nine.com/api/v2`

#### Request Body

| Name                                     | Type   | Description                                     |
| ---------------------------------------- | ------ | ----------------------------------------------- |
| key<mark style="color:red;">\*</mark>    | string | Your API Key                                    |
| action<mark style="color:red;">\*</mark> | string | cancel                                          |
| orders<mark style="color:red;">\*</mark> | string | Order IDs (separated by a comma, up to 100 IDs) |

{% tabs %}
{% tab title="200 successful" %}

```json
[
    {
        "order": 9,
        "cancel": {
            "error": "Incorrect order ID"
        }
    },
    {
        "order": 2,
        "cancel": 1
    }
]
```

{% endtab %}
{% endtabs %}

## User balance

<mark style="color:green;">`POST`</mark> `https://smm.sec-nine.com/api/v2`

#### Request Body

| Name                                     | Type   | Description  |
| ---------------------------------------- | ------ | ------------ |
| key<mark style="color:red;">\*</mark>    | string | Your API Key |
| action<mark style="color:red;">\*</mark> | string | balance      |

{% tabs %}
{% tab title="200 successful" %}

```json
{
    "balance": "100.84292",
    "currency": "TRY"
}
```

{% endtab %}
{% endtabs %}

## Example of Codes

{% tabs %}
{% tab title="PHP" %}

```php
<?php
class Api
{
    /** API URL */
    public $api_url = 'https://smm.sec-nine.com/api/v2';

    /** Your API key */
    public $api_key = '';

    /** Add order */
    public function order($data)
    {
        $post = array_merge(['key' => $this->api_key, 'action' => 'add'], $data);
        return json_decode($this->connect($post));
    }

    /** Get order status  */
    public function status($order_id)
    {
        return json_decode(
            $this->connect([
                'key' => $this->api_key,
                'action' => 'status',
                'order' => $order_id
            ])
        );
    }

    /** Get orders status */
    public function multiStatus($order_ids)
    {
        return json_decode(
            $this->connect([
                'key' => $this->api_key,
                'action' => 'status',
                'orders' => implode(",", (array)$order_ids)
            ])
        );
    }

    /** Get services */
    public function services()
    {
        return json_decode(
            $this->connect([
                'key' => $this->api_key,
                'action' => 'services',
            ])
        );
    }

    /** Refill order */
    public function refill(int $orderId)
    {
        return json_decode(
            $this->connect([
                'key' => $this->api_key,
                'action' => 'refill',
                'order' => $orderId,
            ])
        );
    }

    /** Refill orders */
    public function multiRefill(array $orderIds)
    {
        return json_decode(
            $this->connect([
                'key' => $this->api_key,
                'action' => 'refill',
                'orders' => implode(',', $orderIds),
            ]),
            true,
        );
    }

    /** Get refill status */
    public function refillStatus(int $refillId)
    {
         return json_decode(
            $this->connect([
                'key' => $this->api_key,
                'action' => 'refill_status',
                'refill' => $refillId,
            ])
        );
    }

    /** Get refill statuses */
    public function multiRefillStatus(array $refillIds)
    {
         return json_decode(
            $this->connect([
                'key' => $this->api_key,
                'action' => 'refill_status',
                'refills' => implode(',', $refillIds),
            ]),
            true,
        );
    }

    /** Cancel orders */
    public function cancel(array $orderIds)
    {
        return json_decode(
            $this->connect([
                'key' => $this->api_key,
                'action' => 'cancel',
                'orders' => implode(',', $orderIds),
            ]),
            true,
        );
    }

    /** Get balance */
    public function balance()
    {
        return json_decode(
            $this->connect([
                'key' => $this->api_key,
                'action' => 'balance',
            ])
        );
    }

    private function connect($post)
    {
        $_post = [];
        if (is_array($post)) {
            foreach ($post as $name => $value) {
                $_post[] = $name . '=' . urlencode($value);
            }
        }

        $ch = curl_init($this->api_url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

        if (is_array($post)) {
            curl_setopt($ch, CURLOPT_POSTFIELDS, join('&', $_post));
        }
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
        $result = curl_exec($ch);
        if (curl_errno($ch) != 0 && empty($result)) {
            $result = false;
        }
        curl_close($ch);
        return $result;
    }
}

// Examples

$api = new Api();

$services = $api->services(); # Return all services

$balance = $api->balance(); # Return user balance

// Add order

$order = $api->order(['service' => 1, 'link' => 'http://example.com/test', 'quantity' => 100, 'runs' => 2, 'interval' => 5]); # Default

$order = $api->order(['service' => 1, 'link' => 'http://example.com/test', 'comments' => "good pic\ngreat photo\n:)\n;)"]); # Custom Comments

$order = $api->order(['service' => 1, 'link' => 'http://example.com/test']); # Package

$order = $api->order(['service' => 1, 'link' => 'http://example.com/test', 'quantity' => 100, 'runs' => 10, 'interval' => 60]); # Drip-feed

// Old posts only
$order = $api->order(['service' => 1, 'username' => 'username', 'min' => 100, 'max' => 110, 'posts' => 0, 'delay' => 30, 'expiry' => '11/11/2022']); # Subscriptions

// Unlimited new posts and 5 old posts
$order = $api->order(['service' => 1, 'username' => 'username', 'min' => 100, 'max' => 110, 'old_posts' => 5, 'delay' => 30, 'expiry' => '11/11/2022']); # Subscriptions

$order = $api->order(['service' => 1, 'link' => 'http://example.com/test', 'quantity' => 100, 'username' => "test"]); # Comment Likes

$order = $api->order(['service' => 1, 'link' => 'http://example.com/test', 'quantity' => 100, 'answer_number' => '7']); # Poll


$status = $api->status($order->order); # Return status, charge, remains, start count, currency

$statuses = $api->multiStatus([1, 2, 3]); # Return orders status, charge, remains, start count, currency
$refill = (array) $api->multiRefill([1, 2]);
$refillIds = array_column($refill, 'refill');
if ($refillIds) {
    $refillStatuses = $api->multiRefillStatus($refillIds);
}
```

{% endtab %}
{% endtabs %}
