  You're browsing the documentation for an old version of SupportPal. Consider upgrading to the [latest version](https://docs.supportpal.com/current/Rest+Api). 

# REST API

Learn the foundations for using the REST API, starting with authentication and some endpoint examples.

## Overview

 The easiest way to familiarise yourself with the API is through cURL. For most applications however, we recommend to use a wrapper library:

- **PHP** - [github://supportpal/api-client-php](https://github.com/supportpal/api-client-php)

## Authentication

The SupportPal API uses Basic Authentication via [API tokens](API+Tokens).

 Use the `-u` flag to provide the API token. Note, the password field is ignored, so you can use a value of your choice, in this case we're using `X`. Replace `$token` with the value of your API token.

```

    $ curl -i -u '$token:X' -X GET https://www.example.com/api/selfservice/type

```

### Authentication Errors

#### Failed to authenticate because of bad credentials or an invalid authorization header.

##### Apache

HTTP Authorisation should work out of the box on Apache using the predefined `.htaccess`. If you're having problems, please check the following:

- `mod_rewrite` is enabled on Apache.
- [AllowOverride](https://httpd.apache.org/docs/2.4/mod/core.html#allowoverride) directive is set to `All` in your Apache configuration to permit user defined `.htaccess` files.
- Switch away from the `cgi` Apache handler to `SuPHP` or `FPM`.

##### Other Web Servers

Please consult the web server documentation on how to enable HTTP Authorization headers.

## Endpoints

To view all supported endpoints, please browse to <https://api.supportpal.com>.

## Changing Locale

 If you use [Multilingual Content](Multilingual+Content) the API will return the default value of content and translations will be accessible as a relation in the results. You can force the API to replace default content with a specific translation (if available) by appending a `lang` parameter to the request.

Below is an example of fetching the Open status with and without the language param (set to French).

`http://www.mydomain.com/api/ticket/status/1`

```

    {
        "status": "success",
        "message": null,
        "data": {
            "id": 1,
            "name": "Open",
            "colour": "#35a600",
            "auto_close": 1,
            "order": 1,
            "created_at": 1486732738,
            "updated_at": 1486732738,
            "translations": [
                {
                    "status_id": 1,
                    "name": "Ouvrir",
                    "locale": "fr"
                }
            ]
        }
    }

```

`http://www.mydomain.com/api/ticket/status/1?lang=fr`

```

    {
        "status": "success",
        "message": null,
        "data": {
            "id": 1,
            "name": "Ouvrir",
            "colour": "#35a600",
            "auto_close": 1,
            "order": 1,
            "created_at": 1486732738,
            "updated_at": 1486732738,
            "translations": [
                {
                    "status_id": 1,
                    "name": "Ouvrir",
                    "locale": "fr"
                }
            ]
        }
    }

```