# API

{% hint style="warning" %}
*The API has been introduced in v3.4. Therefore, it is only available & supported on v3.4 and above.*
{% endhint %}

This page explains the ways to interact with the Abuse Manager Pro API.

### Generating your API ID For Authentication <a href="#generating_your_api_id_for_authentication" id="generating_your_api_id_for_authentication"></a>

* Login to your WHMCS installation (WHMCS Admin)
* Go to Setup > Staff Management > Manage API Credentials
* Click on API roles, click on Create API Role button, DO NOT give it any actions, press save
* Click on API credentials, click on Generate New API Credential button, select your admin user, select the API role created previously
* Copy the identifier only - we do not need the secret
* This identifier will be the API\_ID that needs to be passed in the header of your call to authenticate with the API

```
'API_ID: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
```

### API URL / Endpoint <a href="#api_url_endpoint" id="api_url_endpoint"></a>

The Abuse Manager Pro API can be consumed from:

```
https://URL-TO-YOUR-WHMCS/modules/addons/abusemanagerpro/includes/api.php
```

### Available Actions/Functions <a href="#available_actions_functions" id="available_actions_functions"></a>

| Action                                                              | Description                           |
| ------------------------------------------------------------------- | ------------------------------------- |
| [Create](https://labs.layer.ae/wiki/doku.php?id=amp:amp_api#create) | Creates an abuse report automatically |

### Actions Index <a href="#actions_index" id="actions_index"></a>

## Create

<mark style="color:green;">`POST`</mark> `https://URL-TO-YOUR-WHMCS/modules/addons/abusemanagerpro/includes/api.phpCreate`

Creates an abuse report automatically&#x20;

#### Headers

| Name                                      | Type | Description |
| ----------------------------------------- | ---- | ----------- |
| API\_ID<mark style="color:red;">\*</mark> |      |             |

#### Request Body

| Name | Type   | Description |
| ---- | ------ | ----------- |
|      | String |             |

{% tabs %}
{% tab title="200: OK "{"status":"success","report\_id":92}"" %}

```javascript
{
    // Response
}
```

{% endtab %}

{% tab title="500: Internal Server Error "{"status":"error","error\_code":"AMP009","error\_description":"Missing required parameters."}"" %}

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}

#### Create <a href="#create" id="create"></a>

<table data-header-hidden><thead><tr><th></th><th></th></tr></thead><tbody><tr><td>Action </td><td>create </td></tr><tr><td>HTTP Method </td><td>POST </td></tr><tr><td>Authentication Required </td><td>Yes </td></tr><tr><td>Variables </td><td>e3a4ef2ee71b4ac0947be41e76aa1f33</td></tr><tr><td>service_id </td><td>required - this is the WHMCS ID of the service that the abuse report will be created for </td></tr><tr><td>category </td><td>required - this is the category of abuse - can be any value e.g. 'Spam' or 'High I/O' or 'Hacking Attempts' etc. </td></tr><tr><td>service_ip </td><td>optional - if not passed, the main dedicated IP of the service will be used - if service doesn't have a dedicated IP it will default to (No Dedicated IP) </td></tr><tr><td>suspend_method </td><td>optional - defaults to nosuspend - available options are 'nosuspend', 'immediate', and 'timelimit' </td></tr><tr><td>allow_unsuspend </td><td>optional - defaults to false - if you want to give the customer the option to self unsuspend set to true </td></tr><tr><td>additional_info </td><td>optional - This is the additional information field - this is visible to the customer </td></tr><tr><td>admin_notes </td><td>optional - This is the admin notes field - this is only visible to the admins </td></tr><tr><td>Success JSON Output </td><td><pre><code>"{"status":"success","report_id":92}"
</code></pre></td></tr><tr><td>Error JSON Output </td><td><pre><code>"{"status":"error","error_code":"AMP009","error_description":"Missing required parameters."}"
</code></pre></td></tr></tbody></table>

| service\_id      | required - this is the WHMCS ID of the service that the abuse report will be created for                                                                  |
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| category         | required - this is the category of abuse - can be any value e.g. 'Spam' or 'High I/O' or 'Hacking Attempts' etc.                                          |
| service\_ip      | optional - if not passed, the main dedicated IP of the service will be used - if service doesn't have a dedicated IP it will default to (No Dedicated IP) |
| suspend\_method  | optional - defaults to nosuspend - available options are 'nosuspend', 'immediate', and 'timelimit'                                                        |
| allow\_unsuspend | optional - defaults to false - if you want to give the customer the option to self unsuspend set to true                                                  |
| additional\_info | optional - This is the additional information field - this is visible to the customer                                                                     |
| admin\_notes     | optional - This is the admin notes field - this is only visible to the admins                                                                             |

### Error Codes <a href="#error_codes" id="error_codes"></a>

| Code   | Description                                                                                    |
| ------ | ---------------------------------------------------------------------------------------------- |
| AMP001 | Unauthorized - make sure you are passing a valid API\_ID in the header                         |
| AMP002 | Missing or Invalid Action - make sure you are passing a valid action                           |
| AMP003 | Missing required parameters - make sure you are passing the required parameters for the action |

### Example PHP Curl Script <a href="#example_php_curl_script" id="example_php_curl_script"></a>

The example below shows how to create an abuse report programmatically using the API service.

```
<?php
 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://URL-TO-YOUR-WHMCS/modules/addons/abusemanagerpro/includes/api.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
    http_build_query(
        array(
            'action' => 'create',                                           // required - 'create' is to be used to create an abuse report
 
            'service_id' => '1',                                            // required - this is the WHMCS ID of the service that the abuse report will be created for
            'category' => 'Spam',                                           // required - this is the category of abuse - can be any value e.g. 'Spam' or 'High I/O' or 'Hacking Attempts' etc.
 
            'service_ip' => '1.2.3.4',                                      // optional - if not passed, the main dedicated IP of the service will be used - if service doesn't have a dedicated IP it will default to (No Dedicated IP)
            'suspend_method' => 'suspend',                                  // optional - defaults to nosuspend - available options are 'nosuspend', 'immediate', and 'timelimit'
            'allow_unsuspend' => true,                                      // optional - defaults to false - if you want to give the customer the option to self unsuspend set to true
            'additional_info' => 'This is the additional info field',       // optional - This is the additional information field - this is visible to the customer
            'admin_notes' => 'This is the admin notes field',               // optional - This is the admin notes field - this is only visible to the admins
        )
    )
);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'API_ID: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',                             // required - this header is required for authentication
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
 
?>
```

{% file src="/files/RwTF6uu2kXOmiEXL0xj6" %}
Downloadable example php script
{% endfile %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://layerlabs.gitbook.io/abuse-manager-pro/optional-and-advanced/api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
