# Migrating to the new API

## Summary of breaking changes

{% hint style="danger" %}
The new Microreact API only accepts authenticated requests. Calls without an `Acccess-Token` header will fail with 401 Unauthorized error.
{% endhint %}

|                       | New API                                                                               | Old API                                                                        |
| --------------------- | ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ |
| API Endpoint          | <https://microreact.org/api/**projects/create/>\*\*                                   | <https://microreact.org/api/**project/>\*\*                                    |
| Documentation         | <https://docs.microreact.org/api/>                                                    | <https://old.microreact.org/api-docs>                                          |
| Request body          | A valid `.microreact` JSON file                                                       | Old API request payload as documented in <https://old.microreact.org/api-docs> |
| `Access-Token` header | Required (Obtain your access token from <https://microreact.org/my-account/settings>) | Optional                                                                       |

## Converting old API request payload

You can convert an old API request payload to a new .microreact JSON file using the schema convertor endpoint:

{% tabs %}
{% tab title="cURL + Bash" %}

```
curl \
  --header "Content-type: application/json; charset=UTF-8" \
  --request POST \
  --data '{ "name": "hayu110x2c0smcm", "data": "https://raw.githubusercontent.com/microreact/data/main/data.csv" }' \
  https://microreact.org/api/schema/convert
```

{% endtab %}
{% endtabs %}

The response is a valid `.microreact` JSON file

```
{
  "datasets": {
    "dataset-1": {
      "file": "data-file-1",
      "idFieldName": "id"
    }
  },
  "files": {
    "data-file-1": {
      "id": "data-file-1",
      "format": "text/csv",
      "name": "data.csv",
      "url": "https://raw.githubusercontent.com/microreact/data/main/data.csv"
    }
  },
  "maps": {
    "map-1": {
      "title": "Map",
      "latitudeField": "__latitude",
      "longitudeField": "__longitude"
    }
  },
  "meta": {
    "name": "hayu110x2c0smcm"
  },
  "tables": {
    "table-1": {
      "dataset": "dataset-1",
      "title": "Metadata",
      "columns": [
        {
          "field": "id"
        },
        {
          "field": "__latitude"
        },
        {
          "field": "__longitude"
        },
        {
          "field": "country"
        },
        {
          "field": "__year"
        },
        {
          "field": "__month"
        },
        {
          "field": "__day"
        }
      ]
    }
  },
  "timelines": {
    "timeline-1": {
      "title": "Timeline",
      "dataType": "year-month-day",
      "yearField": "__year",
      "monthField": "__month",
      "dayField": "__day"
    }
  },
  "schema": "https://microreact.org/schema/v1.json"
}
```

You can also pipe the response into the create project endpoint as in the following example:

```
curl \
  --header "Content-type: application/json; charset=UTF-8" \
  --request POST \
  --data '{ "name": "hayu110x2c0smcm", "data": "https://raw.githubusercontent.com/microreact/data/main/data.csv" }' \ # Old API request payload as documented in https://old.microreact.org/api-docs 
  https://microreact.org/api/schema/convert \
| \
curl \
  --header "Content-type: application/json; charset=UTF-8" \
  --header "Access-Token: eyJhbGciOiJIUzUxMiJ9..." \ # Obtain your access token from https://microreact.org/my-account/settings
  --data @- \
  https://microreact.org/api/projects/create
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.microreact.org/api/migrating-to-the-new-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
