Export

You can create data exports through the admin UI or directly through the API. Creating exports through the API is helpful when needing to automate an export process.

Export object instances define export jobs to run including details such as type of export, query and aggregation criteria, export paths to include, and more. Each export instance represents one specific export job. Export jobs are queued in the background and each org can run one job at a time. Although you can create as many export jobs as you'd like, they will run sequentially in the order they were created.

Exported data is archived in zip format and stored securely in an encrypted file store within Cortex. When the export job is complete, a secure download link will be provided in the export's dataFile property. This link can only be accessed by an authenticated user with administrator privileges. Exports are available for download for seven days, after which the export and archive are deleted.

Export archive sizes count against file storage limits in your org.

Export Object Properties

Name

Type

Description

label

String

The label for your export. This appears in the export jobs UI

description

String

The description of your export. If present, this appears in the export jobs UI

state

String

The current state of the export job. Can be pending, running, ready, error

exportFiles

Boolean

When selected, if the export contains files, they will be included along-side the exported data. Note, this can cause exports to take a long time to complete if there are many large files.

zipFiles

Boolean

Applies with exporting files. If true, files are archived together in a zip archive within the exported archive.

format

MIME-type

The format of the exported data. Valid types are: application/x-ndjson: New-line delimited JSON application/json: JSON format * text/csv: CSV format

objects

String

The plural name of the Cortex object being exported.

paths

String Array

Optional array of property names to include in the export. When no paths are provided, all non-optional paths are included.

include

String Array

An array of optional property names to be included in the export.

expand

String Array

An array of reference property names to be expanded in the export.

where

String

Optional query argument to filter the export. See the Where query argument for more details.

afterScript

String

A stringified custom script that will execute after export job completion. This is helpful for logging the completion of exports or sending notifications, etc.

principal

ObjectId

When set, the export runs as this principal. This is helpful when exports need to be limited by acl and when used in conjunction with a path prefix.

prefix

String

When a prefix is present the export can be limited to documents available in a write-through list or nested document array.

List

GET https://api.dev.medable.com/your_org_name/v2/exports

Path Parameters

Name
Type
Description

your_org_name

string

{
    "data": [
        {
            "_id": "595d68f40e74ad01008c52df",
            "access": 7,
            "created": "2017-07-05T22:32:20.753Z",
            "creator": {
                "_id": "5532e499540b0183799b4ee5",
                "object": "account",
                "path": "/accounts/5532e499540b0183799b4ee5"
            },
            "dataFile": {
                "ETag": "6d3ccfae24f5128b62525f33999525e0",
                "creator": "5532e499540b0183799b4ee5",
                "filename": "export-2017-07-05T22:32:21.228Z.json",
                "location": 4,
                "mime": "application/zip",
                "name": "content",
                "path": "/exports/595d68f40e74ad01008c52df/dataFile/content",
                "size": 353,
                "state": 2
            },
            "expiresAt": "2017-07-12T22:32:20.771Z",
            "format": "application/json",
            "label": "My Export",
            "object": "export",
            "objects": "c_goals",
            "owner": {
                "_id": "5532e499540b0183799b4ee5",
                "object": "account",
                "path": "/accounts/5532e499540b0183799b4ee5"
            },
            "state": "ready",
            "stats": {
                "docs": {
                    "count": 2
                },
                "files": {
                    "count": 0,
                    "size": 0
                }
            }
        },
        {
            "_id": "595d6b5a0e74ad01008c537a",
            "access": 7,
            "created": "2017-07-05T22:42:34.614Z",
            "creator": {
                "_id": "5532e499540b0183799b4ee5",
                "object": "account",
                "path": "/accounts/5532e499540b0183799b4ee5"
            },
            "dataFile": {
                "ETag": "7afba9849047dc37047c609b48c1020a",
                "creator": "5532e499540b0183799b4ee5",
                "filename": "export-2017-07-05T22:42:35.030Z.csv",
                "location": 4,
                "mime": "application/zip",
                "name": "content",
                "path": "/exports/595d6b5a0e74ad01008c537a/dataFile/content",
                "size": 910,
                "state": 2
            },
            "expiresAt": "2017-07-12T22:42:34.624Z",
            "format": "text/csv",
            "label": "My Export 2",
            "object": "export",
            "objects": "c_patients",
            "owner": {
                "_id": "5532e499540b0183799b4ee5",
                "object": "account",
                "path": "/accounts/5532e499540b0183799b4ee5"
            },
            "paths": [
                "_id",
                "created",
                "c_birthdate",
                "c_gender",
                "c_name"
            ],
            "state": "ready",
            "stats": {
                "docs": {
                    "count": 26
                },
                "files": {
                    "count": 0,
                    "size": 0
                }
            }
        }
    ],
    "hasMore": false,
    "object": "list"
}
$.ajax({
    url: "https://api.dev.medable.com/example/v2/exports",
    method: "GET",
    dataType : "json",
    xhrFields: {
        withCredentials: true
    },
    headers: {
        "Medable-Client-Key": "GsAqlhnIMzrDeD8V2MBQWq"
    }
}).done(function(data) {
    // ...
});

Read

GET https://api.dev.medable.com/your_org_name/v2/exports/export_id

Path Parameters

Name
Type
Description

your_org_name

string

export_id

string

{
  "_id": "595d68f40e74ad01008c52df",
  "access": 7,
  "created": "2017-07-05T22:32:20.753Z",
  "creator": {
    "_id": "5532e499540b0183799b4ee5",
    "object": "account",
    "path": "/accounts/5532e499540b0183799b4ee5"
  },
  "dataFile": {
    "ETag": "6d3ccfae24f5128b62525f33999525e0",
    "creator": "5532e499540b0183799b4ee5",
    "filename": "export-2017-07-05T22:32:21.228Z.json",
    "location": 4,
    "mime": "application/zip",
    "name": "content",
    "path": "/exports/595d68f40e74ad01008c52df/dataFile/content",
    "size": 353,
    "state": 2
  },
  "expiresAt": "2017-07-12T22:32:20.771Z",
  "format": "application/json",
  "label": "My Export",
  "object": "export",
  "objects": "c_goals",
  "owner": {
    "_id": "5532e499540b0183799b4ee5",
    "object": "account",
    "path": "/accounts/5532e499540b0183799b4ee5"
  },
  "state": "ready",
  "stats": {
    "docs": {
      "count": 2
    },
    "files": {
      "count": 0,
      "size": 0
    }
  }
}
$.ajax({
    url: "https://api.dev.medable.com/example/v2/exports/595d68f40e74ad01008c52df",
    method: "GET",
    dataType : "json",
    xhrFields: {
        withCredentials: true
    },
    headers: {
        "Medable-Client-Key": "GsAqlhnIMzrDeD8V2MBQWq"
    }
}).done(function(data) {
    // ...
});

Create

POST https://api.dev.medable.com/your_org_name/v2/exports

Path Parameters

Name
Type
Description

your_org_name

string

Request Body

Name
Type
Description

label

string

objects

string

format

string

exportFiles

boolean

zipFiles

boolean

{
  "_id": "595d6b5a0e74ad01008c537a",
  "object": "export",
  "created": "2017-07-05T22:42:34.614Z",
  "creator": {
    "_id": "5532e499540b0183799b4ee5",
    "object": "account",
    "path": "/accounts/5532e499540b0183799b4ee5"
  },
  "owner": {
    "_id": "5532e499540b0183799b4ee5",
    "object": "account",
    "path": "/accounts/5532e499540b0183799b4ee5"
  },
  "access": 7,
  "label": "test 3",
  "state": "pending",
  "exportFiles": false,
  "zipFiles": false,
  "format": "text/csv",
  "objects": "c_patients",
  "paths": [
    "_id", "created", "c_birthdate", "c_gender", "c_name"
  ],
  "afterScript": "import logger from 'logger';\nlogger.info(script.arguments.err || script.arguments.export);\n",
  "stats": {
    "docs": {
      "count": 0
    },
    "files": {
      "count": 0,
      "size": 0
    }
  },
  "expiresAt": "2017-07-12T22:42:34.624Z"
}
$.ajax({
    url: "https://api.dev.medable.com/example/v2/exports",
    method: "POST",
    dataType : "json",
    xhrFields: {
        withCredentials: true
    },
    headers: {
        "Medable-Client-Key": "GsAqlhnIMzrDeD8V2MBQWq"
    },
    data: {
      {
        "label": "My Export",
        "format": "text/csv",
        "objects": "c_patients",
        "paths": ["_id", "created", "c_birthdate", "c_gender", "c_name"],
        "afterScript": "import logger from 'logger';\nlogger.info(script.arguments.err || script.arguments.export);\n"
      }
		}
}).done(function(data) {
    // ...
});

Delete

DELETE https://api.dev.medable.com/your_org_name/v2/exports/export_id

Path Parameters

Name
Type
Description

your_org_name

string

export_id

string

{
    "object": "result",
    "data": true
}
$.ajax({
    url: "https://api.dev.medable.com/example/v2/connections/595d6b5a0e74ad01008c537a",
    method: "DELETE",
    dataType : "json",
    xhrFields: {
        withCredentials: true
    },
    headers: {
        "Medable-Client-Key": "GsAqlhnIMzrDeD8V2MBQWq"
    }
}).done(function(data) {
    // ...
});

Last updated