# REST API

## Get Prefill

Retrieves code and prefill information in a single request.

Base URL: `https://astralis24.com`

Endpoint: `GET /rest.php/get-prefill`

{% hint style="info" %}
Authentication: All requests must include an `API-Key` header with a valid API key.
{% endhint %}

Header Format:

{% code title="Header" %}

```
API-Key: your-api-key-here
```

{% endcode %}

Query Parameters:

* `lang` (optional, default: `DE`) - Language code: `DE`, `FR`, or `IT`
* `page_id` (optional) - Source identifier (e.g., `page2`, `page1`)
* `tracking_code` (optional) - Tracking code for analytics

Example Request:

{% code title="cURL" %}

```bash
curl -X GET "https://astralis24.com/rest.php/get-prefill?lang=DE&page_id=lp3&tracking_code=abc123" \
  -H "API-Key: your-api-key-here"
```

{% endcode %}

Example Response:

{% code title="Response (200)" %}

```json
{
  "status": true,
  "message": "Success",
  "data": {
    "prefill": "...",
    "wa_number": "...",
    "sim_no": "...",
    "code_data": {
      "KW_ABO": "...",
      "short_code": "...",
      "generated_code": "..."
    }
  }
}
```

{% endcode %}

Error Response (401 Unauthorized):

{% code title="Response (401)" %}

```json
{
  "status": false,
  "message": "Unauthorized: Invalid or missing API key",
  "data": []
}
```

{% endcode %}

Notes:

* Facebook cookies (`_fbc`, `_fbp`) are automatically used if available.
* Client IP address and user agent are automatically captured from the request.
* The response includes both `wa_number` and `sim_no` fields.

{% hint style="warning" %}
If your client needs cookies sent with the request (for example to include Facebook cookies), ensure cross-origin requests are configured to allow credentials.
{% endhint %}

JavaScript/jQuery Example:

{% code title="fetchPrefillCombined (JavaScript/jQuery)" %}

```javascript
function fetchPrefillCombined(lang, pageId, trackingCode) {
    $.ajax({
        cache: false,
        async: false,
        type: 'GET',
        url: `https://astralis24.com/rest.php/get-prefill?lang=${lang.toUpperCase()}&page_id=${pageId}&tracking_code=${trackingCode}`,
        dataType: 'json',
        headers: {
            'API-Key': 'your-api-key-here'
        },
        xhrFields: {
            withCredentials: true  // ✅ ensures cookies are sent
        },
        crossDomain: true,
        success: function (data) {
            if (data.status) {
                let url = `sms:${data.data.sim_no}?body=${data.data.prefill}`;
                // let url = `https://wa.me/${data.data.wa_number}?text=${data.data.prefill}`;
                $('#smsClick').attr('href', url);
            }
        }
    });
}
```

{% endcode %}
