๐Ÿ“ฆ Refill Inventory API

Note: Your userid and apikey will be provided privately. Do not share them publicly.

๐Ÿ” Authentication

Include your API key in the query string:

POST /api.php?apikey=YOUR_API_KEY

๐Ÿ“ฅ Request Method

POST a JSON array of drug records to the endpoint:

https://apirefill.careposting.com/api.php?apikey=YOUR_API_KEY

๐Ÿ“ฆ Payload Format

Send an array of JSON objects. Each object must include:

๐Ÿงช Example Payload
[
  {
    "drugname": "Paracetamol",
    "userid": 1,
    "nooftablets": 100,
    "type": "Tablet",
    "purchasecost": 50,
    "salescost": 80,
    "discount": 5,
    "expirydate": "2025-08-01",
    "category": "Laxitive"
  },
  {
    "drugname": "Ibuprofen",
    "userid": 1,
    "nooftablets": 50,
    "type": "Capsule",
    "purchasecost": 30,
    "salescost": 60,
    "discount": 3,
     "expirydate": "2025-08-01",
    "category": "Laxitive"
  }
]

โœ… Response

The API returns a summary like this:

{
  "API Response": [
    { "index":Ibuprofen, "status": "updated" },
    { "index": Paracetamol, "status": "inserted" }
  ]
}

โš ๏ธ Error Responses

{ "error": "Unauthorized" }
{ "error": "Invalid input format. Expected an array of records." }

๐Ÿ”„ AutoSync Script to Refill API

Note: This script automatically connects to an external database, checks for updated drug records, and pushes them to our Refill API.

๐Ÿงฉ Purpose

This script connects to a specified database table, checks for updated rows (based on an updated_at column), converts the data into a structured JSON array, and sends it via POST to the Refill API.

โš™๏ธ Configuration

๐Ÿ•’ Sync Interval

The script checks for records updated in the last 10 minutes. This interval is adjustable with the $checkWindowMinutes variable inside the script.

๐Ÿงช Expected Table Structure

The source table should contain the following fields:

๐Ÿ“ค Example Payload Sent to Refill API

[
  {
    "drugname": "Paracetamol",
    "userid": 1,
    "nooftablets": 100,
    "type": "Tablet",
    "purchasecost": 50,
    "salescost": 80,
    "discount": 5,
    "expirydate": "2025-08-01",
    "category": "Laxitive"
  },
  {
    "drugname": "Ibuprofen",
    "userid": 1,
    "nooftablets": 50,
    "type": "Capsule",
    "purchasecost": 30,
    "salescost": 60,
    "discount": 3,
    "expirydate": "2025-08-01",
    "category": "Laxitive"
  }
]

๐Ÿ” Refill API Endpoint

The script posts the data to:

https://apirefill.careposting.com/api.php?apikey=SECRET_API_KEY_123
Your apikey and Userid will be shared with authorized systems only.

๐Ÿ“ˆ Use Case

Perfect for syncing pharmacy data from third-party inventory systems into your central Refill system automatically.

โฑ๏ธ Recommended Automation

Run this script via a cron job every 5โ€“10 minutes to keep records in sync:

*/10 * * * * /usr/bin/php /path/to/post_to_apidb.php