# Create App

{% hint style="warning" %}
This request requires at least a space admin role.
{% endhint %}

## Create App&#x20;

<mark style="color:green;">`POST`</mark> `https://environment.monterosa.cloud/api/v2/apps`

#### Headers

| Name          | Type   | Description                             |
| ------------- | ------ | --------------------------------------- |
| Authorization | string | Bearer JmsmU5gZb6xNVUgQGoKcQLvQjRhKAUSb |
| Content-Type  | string | application/vnd.api+json                |

#### Request Body

| Name      | Type   | Description            |
| --------- | ------ | ---------------------- |
| spec\_url | string | App specification URL. |

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

```javascript
{
  "data": {
    "id": "8630c508-7d12-4e6d-85d5-5e507e97738e",
    "type": "apps",
    "attributes": {
      "name": "Elements",
      "app_id": "elements",
      "version": "24.0.0",
      "social_curation_enabled": false,
      "schedule_enabled": true,
      "analytics_enabled": true,
      "live_activity_enabled": true,
      "localisation_enabled": true,
      "created_at": 1598434373,
      "created_at_iso": "2020-08-26T09:32:53Z",
      "updated_at": 1598434373,
      "updated_at_iso": "2020-08-26T09:32:53Z",
      "spec_url": "https://environment.company.co.uk/specs/version/spec.json"
    }  
    "links": {
      "self": "https://environment.lvis.io/api/v2/apps/8630c508-7d12-4e6d-85d5-5e507e97738e"
    }
  }
}
```

{% endtab %}
{% endtabs %}

## Example

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

```javascript
// POST /api/v2/apps
// Host: environment.monterosa.cloud
// Authorization: Bearer JmsmU5gZb6xNVUgQGoKcQLvQjRhKAUSb
// Content-Type: application/vnd.api+json

{
  "data": {
    "type": "apps",
    "relationships": {
      "space": {
        "data": {
          "type": "spaces",
          "id": "8630c508-7d12-4e6d-85d5-5e507e97738e"
        }
      }
    },
    "attributes": {
      "spec_url": "https://environment.company.co.uk/specs/version/spec.json"
    }
  }
}
```

{% endtab %}

{% tab title="Response" %}

```javascript
// Status: 201 Created

{
  "data": {
    "id": "8630c508-7d12-4e6d-85d5-5e507e97738e",
    "type": "apps",
    "attributes": {
      "name": "Elements",
      "app_id": "elements",
      "version": "24.0.0",
      "social_curation_enabled": false,
      "schedule_enabled": true,
      "analytics_enabled": true,
      "live_activity_enabled": true,
      "localisation_enabled": true,
      "created_at": 1598434373,
      "created_at_iso": "2020-08-26T09:32:53Z",
      "updated_at": 1598434373,
      "updated_at_iso": "2020-08-26T09:32:53Z",
      "spec_url": "https://environment.company.co.uk/specs/version/spec.json"
    }  
    "links": {
      "self": "https://environment.monterosa.cloud/api/v2/apps/8630c508-7d12-4e6d-85d5-5e507e97738e"
    }
  }
}
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl --request POST \
  --url https://environment.monterosa.cloud/api/v2/apps \
  --header 'Authorization: Bearer JmsmU5gZb6xNVUgQGoKcQLvQjRhKAUSb' \
  --header 'Content-Type: application/vnd.api+json' \
  --data '{
    "data": {
      "type": "apps",
      "relationships": {
        "space": {
          "data": {
            "type": "spaces",
            "id": "8630c508-7d12-4e6d-85d5-5e507e97738e"
          }
        }
      },
      "attributes": {
        "spec_url": "https://environment.company.co.uk/specs/version/spec.json"
      }
    }
  }'
```

{% endtab %}
{% endtabs %}

The app is created within the space with id `8630c508-7d12-4e6d-85d5-5e507e97738e` as set by `/data/relationships/space/data/id`.

### Validation error on app creation

In this example, we are trying to create an app with an invalid spec URL.

The request fails with 422 (Unprocessable Entity) status and corresponding error message.

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

```javascript
// POST /api/v2/apps
// Host: environment.monterosa.cloud
// Authorization: Bearer JmsmU5gZb6xNVUgQGoKcQLvQjRhKAUSb
// Content-Type: application/vnd.api+json

{
  "data": {
    "type": "apps",
    "relationships": {
      "brand": {
        "data": {
          "type": "spaces",
          "id": "7a4c58d9-9e3b-4e63-8ea6-bb68785640e1"
        }
      }
    },
    "attributes": {
      "spec_url": "invalid-spec-url"
    }
  }
}
```

{% endtab %}

{% tab title="Response" %}

```javascript
// Status: 422 Unprocessable Entity

{
  "errors": [
    {
      "source": {
        "pointer": "/data/attributes/spec_url"
      },
      "detail": "Loading of the `App Spec` failed with the error(s): not a valid URL"
    }
  ]
}
```

{% endtab %}
{% endtabs %}
