# Retrieve the App Data Model

It is sometimes necessary to know the structure of the data that will be returned by the JourneyApps API. For example, knowing which fields to expect for certain objects.

This API function allows you to retrieve a structured representation of your app's [Data Model](https://docs.journeyapps.com/reference/get-started/journeyapps-fundamentals/what-is-the-data-model), exactly as defined in **schema.xml** within OXIDE.

<table><thead><tr><th width="546">Relative URL</th><th>HTTP Request Method</th></tr></thead><tbody><tr><td><code>/api/v4/</code><em><code>backend-deployment-id</code></em><code>/datamodel.json</code></td><td>GET</td></tr></tbody></table>

### Parameters

This API function does not take any parameters (except for standard ETag functionality — please see below).

### Response

The response will contain a list of the object types in the particular app's Data Model, with a list of fields of each object type. Relationships of the object types are also included.

{% hint style="info" %}
The Data Model is a representation of the fields defined by the developer of the app in the app's Data Model. The JourneyApps API will also return some metadata in addition to these fields.

For example `updated_at` and `id` will be returned in JourneyApps API responses (see [Retrieving all Objects](https://docs.journeyapps.com/reference/backend-api/api-reference/retrieve-all-objects)).
{% endhint %}

The HTTP headers for the response also include an [ETag header](http://en.wikipedia.org/wiki/HTTP_ETag) which allows you to keep track of versions of the Data Model. Whenever changes are made to the app's Data Model, the hash in the ETag header will change. You can include this ETag hash value with the `If-None-Match` header in subsequent calls to the `datamodel` API function. If the Data Model for the app hasn't changed, a "304 Not Modified" response code will be returned.

The response also contains a field called `datamodel_hash`, identifying the current version of the data model. This matches the value in the `oplog.json` call.

### Example

{% hint style="info" %}
**BASE-URL**

The below examples contain a `BASE-URL` placeholder. Please refer to the [HTTP Endpoints](https://docs.journeyapps.com/reference/introduction#http-endpoints) section to get the base URL relevant to your deployment.
{% endhint %}

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

```http
GET BASE-URL/api/v4/533bda53027894f69b001055/datamodel.json
```

{% endtab %}

{% tab title="curl" %}

```shell
curl "BASE-URL/api/v4/533bda53027894f69b001055/datamodel.json" \
    -u "533bda53027894f69b001055:7Ajj5htRY1uzw7b4w23V"
```

{% endtab %}

{% tab title="ruby" %}

```ruby
require 'rest-client'
journey = RestClient::Resource.new "BASE-URL/api/v4", "533bda53027894f69b001055", "7Ajj5htRY1uzw7b4w23V"
journey["533bda53027894f69b001055/datamodel.json"].get
```

{% endtab %}
{% endtabs %}

Response:

{% code title="json" %}

```json
{
  "models": {
    "user": {
      "name": "user",
        "label": "User",
        "display": "{name}",
        "fields": {
        "name": {
          "name": "name",
            "label": "Name",
            "type": "text",
            "subtype": "name"
        }
      },
      "belongs_to": {
      },
      "has_many": {
      }
    },
    "category": {
      "name": "category",
        "label": "Category",
        "display": "{name}",
        "fields": {
        "name": {
          "name": "name",
            "label": "Name",
            "type": "text"
        }
      },
      "belongs_to": {
      },
      "has_many": {
        "tasks": {
          "model": "task",
            "name": "tasks",
            "inverse_of": "category"
        }
      }
    },
    "task": {
      "name": "task",
        "label": "Task",
        "display": "{name}",
        "fields": {
        "name": {
          "name": "name",
            "label": "Name",
            "type": "text"
        },
        "instructions": {
          "name": "instructions",
            "label": "Instructions",
            "type": "text"
        },
        "status": {
          "name": "status",
            "label": "Status",
            "type": "single-choice-integer",
            "options": [
            {
              "key": 0,
              "display": "Open"
            },
            {
              "key": 1,
              "display": "Closed"
            }
          ]
        }
      },
      "belongs_to": {
        "category": {
          "model": "category",
            "name": "category",
            "inverse_of": "tasks"
        }
      },
      "has_many": {
      }
    }
  },
  "app_user": "user",
  "datamodel_hash": "{sha}"
}
```

{% endcode %}
