# Instance API

## Enabling the Instance API

To enable the Instance API, you will need to provide an authentication token via an environment variable:

```bash
UI_BAKERY_INSTANCE_API_TOKEN=YOUR_TOKEN
```

## Making Requests to the UI Bakery SCIM API

The UI Bakery Instance API available on the following URL, where `UI_BAKERY_INSTANCE` is your domain.

```
http(s)://UI_BAKERY_INSTANCE/api/instance/**
```

To authenticate your requests, include the `Authorization: Bearer TOKEN` header with the value provided in the `UI_BAKERY_INSTANCE_API_TOKEN` environment variable

## Reference

### App methods:

### Pull branch in app

<mark style="color:green;">`POST`</mark> `https://UI_BAKERY_INSTANCE/api/instance/app/{app_id}/pull`

Pull latest commits for specified app/branch

#### Path Parameters

| Name                                    | Type   | Description      |
| --------------------------------------- | ------ | ---------------- |
| appId<mark style="color:red;">\*</mark> | String | UI Bakery app id |

#### Query Parameters

| Name                                          | Type   | Description |
| --------------------------------------------- | ------ | ----------- |
| uib\_branch<mark style="color:red;">\*</mark> | String | Branch name |

{% tabs %}
{% tab title="200: OK Returns the last pulled commit" %}

```
{
    "status": "OK",
    "message": "Branch pulled",
    "result": {
        "lastCommit": {
            "hash": "359ad61432a481497b96c3c8hb4ad751f68bfd19",
            "message": "feat(home): update user table"
        }
    }
}
```

{% endtab %}
{% endtabs %}

### Relese app

<mark style="color:green;">`POST`</mark> `https://UI_BAKERY_INSTANCE/api/instance/app/{app_id}/release`

Releasing the app to specified environments: If both "prod" and "staging" are false, the release becomes a "Draft"; if no "branch" parameter is provided, the main branch is used by default.

If version is not specified, the last valid version will be patched.

#### Path Parameters

| Name                                    | Type   | Description      |
| --------------------------------------- | ------ | ---------------- |
| appId<mark style="color:red;">\*</mark> | String | UI Bakery app id |

#### Request Body

| Name                                      | Type    | Description                                       |
| ----------------------------------------- | ------- | ------------------------------------------------- |
| version                                   | String  | Release version                                   |
| description                               | String  | Release description                               |
| prod<mark style="color:red;">\*</mark>    | Boolean | Should release be created for Prod environment    |
| staging<mark style="color:red;">\*</mark> | Boolean | Should release be created for Staging environment |
| branch                                    | String  | From what branch release should be created        |

{% tabs %}
{% tab title="200: OK Returns the last 10 releases" %}

```
{
    "status": "CREATED",
    "message": "App released",
    "result": {
        "releases": [
            {
                "id": "4UMYn3VOnm",
                "version": "0.11.1",
                "description": "",
                "createdBy": "Organization Admin",
                "createdAt": "2024-01-01T15:07:50.000+00:00",
                "prod": true,
                "staging": false,
                "dev": null,
                "branch": "main",
                "commitHash": "363ae61431a481497v96c3c87b4ad751f68bfd19",
                "commitMessage": "Update main.yml"
          }
        ]
}     
```

{% endtab %}
{% endtabs %}

## Example integrations

{% content-ref url="../git-source-control/automate-github-releases" %}
[automate-github-releases](https://docs.uibakery.io/on-premise/git-source-control/automate-github-releases)
{% endcontent-ref %}

{% content-ref url="../git-source-control/automate-gitlab-releases" %}
[automate-gitlab-releases](https://docs.uibakery.io/on-premise/git-source-control/automate-gitlab-releases)
{% endcontent-ref %}

{% content-ref url="../git-source-control/automate-bitbucket-releases" %}
[automate-bitbucket-releases](https://docs.uibakery.io/on-premise/git-source-control/automate-bitbucket-releases)
{% endcontent-ref %}
