# DrugNet API Documentation

Welcome to the DrugNet  API documentation. This API allows you to communicate with the DrugNet System.

### Authentication

All requests to the API must include the `x-api-key` header with a valid API key.

## Get your API keys

[Your API requests are authenticated using API keys. Any request that doesn't include an API key will return an error. You can request for the API key from the DrugNet Portal Administrators](#user-content-fn-1)[^1].

## Want to jump right in?

Feeling like an eager beaver? Jump in to the create user docs and get making your first request:

{% content-ref url="/pages/KTUiiElBr2GhWJJeOdK4" %}
[Create User](/create-user)
{% endcontent-ref %}

## Want to deep dive?

Dive a little deeper and start exploring our API reference to get an idea of everything that's possible with the API:

{% content-ref url="/pages/7e4EuACgBnO7fjLM5j3A" %}
[API Reference](/reference/api-reference)
{% endcontent-ref %}

[^1]:


# Create User

Create a new user in the DrugNet system.

{% hint style="info" %}
**Good to know:** A quick start guide can be good to help folks get up and running with your API in a few steps. Some people prefer diving in with the basics rather than meticulously reading every page of documentation!
{% endhint %}

## Make your first request

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

## Create user.

<mark style="color:green;">`POST`</mark> `/create_user`

This endpoint allows you to create a new user in the DrugNet System.

#### Request Body

| Name                                    | Type   | Description           |
| --------------------------------------- | ------ | --------------------- |
| name<mark style="color:red;">\*</mark>  | string | The name of the user  |
| email<mark style="color:red;">\*</mark> | string | The email of the user |
| phone<mark style="color:red;">\*</mark> | string | The phone of the user |
| country                                 | string | Source country        |

{% tabs %}
{% tab title="200 User created sucessfully" %}

```javascript
{
  "status": "success",
  "message": "User created successfully",
  "user": {
    "id": 123,
    "name": "John Doe",
    "phone": "+233 xx xxx xxxx",
    "email": "john.doe@doe.com"
  }
}

```

{% endtab %}

{% tab title="400: Bad Request Invalid Request" %}
{ "status": "error", "message": "Invalid API key" }
{% endtab %}

{% tab title="204: No Content Empty field" %}

{% endtab %}

{% tab title="500: Internal Server Error Internal Server Error" %}

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Good to know:** You can use the API Method block to fully document an API method. You can also sync your API blocks with an OpenAPI file or URL to auto-populate them.
{% endhint %}

Take a look at how you might call this method using our official libraries, or via `curl`:

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

```
curl --location '/create_user' \
--header 'x-api-key: YOUR API KEY' \
--form 'name="YOUR NAME"' \
--form 'phone="YOUR PHONE"' \
--form 'email="YOUR EMAIL"' 
```

{% endtab %}

{% tab title="Node" %}

```javascript
var request = require('request');
var options = {
  'method': 'POST',
  'url': '/create_user',
  'headers': {
    'x-api-key': 'YOUR API KEY'
  },
  formData: {
    'name': 'YOUR NAME',
    'phone': 'YOUR PHONE',
    'email': 'YOUR EMAIL'
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});


```

{% endtab %}

{% tab title="PHP" %}

```python
<?php
$client = new http\Client;
$request = new http\Client\Request;
$request->setRequestUrl('/create_user');
$request->setRequestMethod('POST');
$body = new http\Message\Body;
$body->addForm(array(
  'name' => 'your name',
  'phone' => 'your phone',
  'email' => 'your email'
), array(

));
$request->setBody($body);
$request->setOptions(array());
$request->setHeaders(array(
  'x-api-key' => 'your api key'
));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();


```

{% endtab %}
{% endtabs %}

## Example

```
{
    "code": 200,
    "success": true,
    "message": "User created sucessfully"
}
```


# Login User

Authenticate a web user by providing their username and password.

**Endpoint:** `POST /login_web_user`

**Request:**

```
POST /login_web_user
Host: portal.drugnet.com.gh
x-api-key: YOUR_API_KEY
Content-Type: application/x-www-form-urlencoded

username=your_username&password=your_password

```

## Login Web User

<mark style="color:green;">`POST`</mark> `/login_web_user`

Authenticate a web user by providing their username and password.

#### Request Body

| Name                                       | Type   | Description            |
| ------------------------------------------ | ------ | ---------------------- |
| username<mark style="color:red;">\*</mark> | String | Provided  username     |
| password<mark style="color:red;">\*</mark> | String | Provided user password |

{% tabs %}
{% tab title="200: OK Success" %}

{% endtab %}

{% tab title="204: No Content Request Empty" %}

{% endtab %}
{% endtabs %}

Take a look at how you might call this method using our official libraries, or via `curl`:

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

```
curl --location --request POST '/login_web_user' \
--header 'x-api-key: YOUR API KEY' \

```

{% endtab %}

{% tab title="PHP" %}

```
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => '/login_web_user',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => array(
    'x-api-key: YOUR API KEY',
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

```

{% endtab %}

{% tab title="Python" %}

```
import requests

url = "/login_web_user"

payload = {}
files={}
headers = {
  'x-api-key': 'YOUR API KEY',
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)

```

{% endtab %}
{% endtabs %}

## Example

```
{
  "success": true,
  "user": {
    "id": 123,
    "name": "John Doe",
    "email": "john.doe@example.com"
  }
}

```

> In case of errors, the API will return a JSON object with a `success` field indicating whether the request was successful, and a corresponding error message in the `message` field.


# Reset password

This endpoint is used to initiate the password reset process for a user in the DrugNet System.

**Endpoint:** `POST /reset_password`

**Headers**

| Name          | Value              |
| ------------- | ------------------ |
| Content-Type  | `application/json` |
| Authorization | x-api-key          |

**Request Body**

| Name  | Type   | Description       |
| ----- | ------ | ----------------- |
| email | string | Email of the user |

**Response**

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

```json
{
    "success": true,
    "code": "200",
    "message": "Password Sent Successfully. Please check your email or sms for Password"
}
```

{% endtab %}

{% tab title="204" %}

```json
{
    "success": false,
    "code": "204",
    "message": "Account not Available"
}

```

{% endtab %}

{% tab title="400" %}

<pre class="language-json"><code class="lang-json"><strong>{
</strong>    "success": false,
    "code": "400",
    "message": "Email is required"
}
</code></pre>

{% endtab %}

{% tab title="402" %}

```json
{
    "success": false,
    "code": "402",
    "message": "Invalid Email"
}
```

{% endtab %}

{% tab title="403" %}

```json
{
    "success": false,
    "code": "403",
    "message": "Invalid Request"
}
```

{% endtab %}
{% endtabs %}


# Send Order Request

This API is used to send a medication request from a client to the DrugNet portal.

**Endpoint:** `POST /send_request_web`

## Send Request Web

<mark style="color:green;">`POST`</mark> `/send_request_web`

&#x20;Send a medication request from a client to the DrugNet portal..

#### Request Body

<table><thead><tr><th width="223">Name</th><th width="192">Type</th><th>Description</th></tr></thead><tbody><tr><td>client_id<mark style="color:red;">*</mark></td><td>integer</td><td>The ID of the client submitting the request</td></tr><tr><td>prescription</td><td>String</td><td>The prescription or reason for the request.</td></tr><tr><td>order_items</td><td>JSON array</td><td>An array of objects specifying the items in the order. Each object should have <code>name</code> (string) and <code>quantity</code> (integer) properties.</td></tr><tr><td>insurance</td><td>String</td><td>Insurance company</td></tr><tr><td>insurance_card</td><td>String</td><td>The insurance card id</td></tr><tr><td>recipient</td><td>String</td><td>Recipient phone number</td></tr><tr><td>location</td><td>String</td><td>Location to deliver drugs</td></tr><tr><td>file</td><td>file </td><td>The file to be uploaded, representing additional information or images related to the request.</td></tr></tbody></table>

{% tabs %}
{% tab title="200: OK Success" %}

```json
{
    "code": 200,
    "success": true,
    "message": "Order sent successfully"
}

```

{% endtab %}

{% tab title="204: No Content Request Empty" %}

```json
{
    "code": 204,
    "success": false,
    "message": "Error message"
}
```

{% endtab %}
{% endtabs %}

Take a look at how you might call this method using our official libraries, or via `curl`:

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

```
curl --location '/send_request_web' \
--header 'x-api-key: YOUR API KEY' \
--form 'client_id="YOUR CLIENT ID"' \
--form 'prescription="YOUR PRESCRIPTION"' \
--form 'order_items="[{\"name\": \"drug 1\", \"quantity\": 2}, {\"name\": \"drug 2\", \"quantity\": 3}]"' \
--form 'file=@"YOUR FILE"'
```

{% endtab %}

{% tab title="PHP" %}

```
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => '/send_request_web',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => array('client_id' => 'YOUR CLIENT ID','prescription' => 'YOUR PRESCRIPTION','order_items' => '[{"name": "drug 1", "quantity": 2}, {"name": "drug 2", "quantity": 3}]','file'=> new CURLFILE('YOUR FILE')),
  CURLOPT_HTTPHEADER => array(
    'x-api-key: YOUR API KEY',

  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

```

{% endtab %}

{% tab title="Python" %}

```
import requests

url = "/send_request_web"

payload = {'client_id': 'YOUR CLIENT ID',
'prescription': 'YOUR PRESCRIPTION',
'order_items': '[{"name": "drug 1", "quantity": 2}, {"name": "drug 2", "quantity": 3}]'}
files=[
  ('file',('toda.png',open('YOUR FILE','rb'),'image/png'))
]
headers = {
  'x-api-key': 'YOUR API KEY',

}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)

```

{% endtab %}
{% endtabs %}

## Example

```
{
  "client_id": 28378,
  "prescription": "Headache",
  "order_items": [
    {"name": "drug 1", "quantity": 2},
    {"name": "drug 2", "quantity": 3}
  ],
  "file": [file content]
}

```

> In case of errors, the API will return a JSON object with a `success` field indicating whether the request was successful, and a corresponding error message in the `message` field.


# Get Insurance Information

Retrieves insurance information from the DrugNet portal . The response is a JSON object containing a success boolean field, a message string field, and a data array field.

The data array contains objects with `name` and `image` string fields.

**Endpoint:** GET `/`get\_insurance

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

```
curl --location '/get_insurance' \
--header 'x-api-key: YOUR KEY' \

```

{% endtab %}

{% tab title="PHP" %}

```
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => '/get_insurance',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'x-api-key: YOUR KEY',
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

```

{% endtab %}
{% endtabs %}

**Successful Response**

```
{
    "success": true,
    "message": "successful",
    "data": [
        {
            "name": "METROPOLITAN HEALTH INSURANCE GHANA LTD.",
            "image": "7tuyhzmq3ws68gb.jpg"
        },
        {
            "name": "COSMOPOLITAN HEALTH INSURANCE",
            "image": "61rukyp9z_ihlfb.png"
        },
       
    ]
}
```


# Create mCredit Case

Creates a new MCredit case by submitting patient and institution details together with a prescription file.

<mark style="color:green;">`POST`</mark> `/`create\_mcredit\_case

Creates a mcredit endpoint

**Headers**

| Name          | Value              |
| ------------- | ------------------ |
| Content-Type  | `application/json` |
| Authorization | x-api-key          |

**Body**

| Name               | Type       | Description         |
| ------------------ | ---------- | ------------------- |
| institution\_name  | string[^1] | Name of institution |
| full\_name         | string[^1] | Full name           |
| phone              | string[^1] | Phone number        |
| prescription\_file | file       | Prescription file   |
| agent\_code        | string[^2] | Agent Code          |

**Response**

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

```json
{
    "code": 200,
    "success": true,
    "message": "M-CrediT case created successfully",
    "data": {
        "id": 6,
        "case_number": "MCW23062026D55CF9",
        "status": "Prescription Received - Awaiting Pharmacist Review",
        "pre_screen_result": "passed_prescreening",
        "review_flags": []
    }
}
```

{% endtab %}

{% tab title="409" %}

```json
{
    "code": 409,
    "success": false,
    "message": "M-CrediT case already exists for this phone and full name",
    "data": {
        "id": 3,
        "case_number": "MCW230620265AEF7D",
        "status": "Prescription Received - Awaiting Pharmacist Review",
        "pre_screen_result": "passed_prescreening"
    }
}
```

{% endtab %}

{% tab title="400" %}

```json
{
    "code": 400,
    "success": false,
    "message": "Invalid Request"
}
```

{% endtab %}
{% endtabs %}

[^1]: required

[^2]: optional


# Mcredit Institutions

Retrieves Mcredit Institutions information from the DrugNet portal

<mark style="color:green;">`GET`</mark> `/`mcredit\_institutions

Get a mcredit institutions endpoint

**Headers**

| Name          | Value              |
| ------------- | ------------------ |
| Content-Type  | `application/json` |
| Authorization | x-api-key          |
|               |                    |

**Params**

| Name   | Type       | Description        |
| ------ | ---------- | ------------------ |
| search | string[^1] | Search institution |
| status | string[^1] | Institution status |

**Response**

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

```json
{
    "code": 200,
    "success": true,
    "message": "M-CrediT institutions retrieved successfully",
    "count": 1,
    "data": [
        {
            "institution_id": "XXX-XXX-XX",
            "canonical_name": "XXX-XXX-XXX",
            "active_status": "active"
        },
       
    ]
}
```

{% endtab %}

{% tab title="400" %}

```json
{
    "code": 400,
    "success": false,
    "message": "Invalid Request"
}
```

{% endtab %}
{% endtabs %}

[^1]: required


# API Rate Limit

Our API imposes rate limits to ensure fair usage and maintain service availability for all users.

Rate limiting restricts the number of requests clients can make to the API within a specific time window. This helps prevent abuse and ensures a consistent experience for all users.

#### Rate Limiting Parameters

* **Maximum Requests**: 100 requests per minute.
* **Time Window**: Requests are counted over a 1-minute sliding window.

Rate Limit Exceeded

If a client exceeds the rate limit, the API will respond with an HTTP status code 901 `Too Many Requests`, along with the following error message:

```
{
  "error": {
    "success": false
    "code": 901,
    "message": "Rate limit exceeded. Please try again later."
  }
}

```


# API Reference

Dive into the specifics of each API endpoint by checking out our complete documentation.

All the methods associated with `CRUD`ing some users. Which isn't as weird as it sounds:

## Users

Everything related to users:

{% content-ref url="/pages/KTUiiElBr2GhWJJeOdK4" %}
[Create User](/create-user)
{% endcontent-ref %}

{% content-ref url="/pages/MeMH3KEBCRFIOcbYY2wg" %}
[Login User](/login-user)
{% endcontent-ref %}

{% content-ref url="/pages/GTbe7Dfnxzne9YazO9Mp" %}
[Reset password](/reset-password)
{% endcontent-ref %}

##

## Orders

{% content-ref url="/pages/lSL7tWFKAggmqaFaSSop" %}
[Send Order Request](/send-order-request)
{% endcontent-ref %}

{% hint style="info" %}
**Good to know:** Using the 'Page Link' block lets you link directly to a page. If this page's name, URL or parent location changes, the reference will be kept up to date.&#x20;

{% endhint %}

{% content-ref url="/pages/SyDFfsRsqGR6v4u1wkKv" %}
[Get Insurance Information](/get-insurance-information)
{% endcontent-ref %}


# Codes

A list of possible codes and what they mean to you

```
100: Request not found.

200: Request Sucessful.

204: Request empty.

350: Already exist.

400: Invalid Request.

402: Invalid Email.

900: Invalid API key.

901: Rate limit exceeded.

902: API Key Missing.





```


