Files

Import Files

Required scope: public-api:write

Description

The file import does both create and update files. The import remembers the externalId / systemName pair and if an import matches an existing pair, it will update (Hint: consider how to rebuild the externalId when you want to update files). The file import in Livingdocs is asynchronous. You post a batch of files that you want to import and get back an id with which you can query later to get your result.

Use Cases
Curl Example
ACCESS_TOKEN=ey1234
curl -k -X POST "https://server.livingdocs.io/api/v1/import/files" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json; charset=utf-8" \
  --data-binary @- << EOF
  {
    "systemName": "identifier-for-your-system",
    "webhook": "https://my-domain.com/webhooks/file-import",
    "files": [
      {
        "url": "https://placekitten.com/800/600",
        "id": "123abc",
        "fileName": "cat",
        "metadata": {
          "caption": "foo"
        }
      }
    ]
  }
EOF

Endpoint

POST api/v1/import/files

Parameters

NameTypeRequiredNotes
systemNamestringxIdentifier for the system you are importing from, e.g. an archive.
webhookuriEndpoint at the importing system that gets notified by POST when import job is done. Notification contains the id of the import job, the state and an overview.
contextobjectAn object that is passed as context in the body of the request to the webhook. Limited to 8192 Bytes.
filesarrayxAn array of files to import. Each entry is an object with the following keys, all of which are required:

url: a URL to a file
id: a unique id (stored as externalId in Livingdocs) that identifies the file on your end, must be unique within your project
fileName: the title that the file should get in livingdocs
metadata: An object of metadata according to your project config
mediaType the handle of one of the mediaTypes from your project configuration

Example Request

{
  "systemName": "identifier-for-your-system",
  "webhook": "https://my-domain.com/webhooks/file-import",
  "context": {
    "myIdentifier": "some-identifier-sent-to-the-webhook"
  },
  "files": [
    {
      "url": "https://placekitten.com/800/600",
      "id": "123abc",
      "fileName": "cat",
      "metadata": {
        "caption": "foo"
      }
    }
  ]
}

Response

200
OK
api/v1/import/files
{
  "id": "25bzj8j"
}

Check Import Status for Files

Required scope: public-api:write

Description

You can use this endpoint to check for the status and/or result of a file import.
Curl Example
ACCESS_TOKEN=ey1234
curl -k -X GET "https://server.livingdocs.io/api/v1/import/files/status" \
  -H "Authorization: Bearer $ACCESS_TOKEN"

Endpoint

GET api/v1/import/files/status

Parameters

NameTypeRequiredNotes
?idstringxThe id that Livingdocs provided you for your prior call to “/import/files”

Response

200
OK
api/v1/import/files/status?id=25bzj8j
{
  "finished": true,
  "state": "success",
  "id": "25bzj8j",
  "files": [
    {
      "status": "success",
      "mediaId": "jjiwhsf23kdk",
      "systemName": "identifier-for-your-system",
      "externalId": "external-unique-id-123"
    },
    {
      "status": "skipped",
      "reason": "already exists",
      "systemName": "identifier-for-your-system",
      "externalId": "external-unique-id-234"
    },
    {
      "status": "failed",
      "reason": "Could not upload file",
      "systemName": "identifier-for-your-system",
      "externalId": "external-unique-id-345"
    }
  ]
}
200
OK
api/v1/import/files/status?id=243kdc
{
  "finished": false,
  "state": "started",
  "id": "243kdc",
  "startedAt": "2020-01-01 13:45:12"
}
200
OK
api/v1/import/files/status?id=098shjhv9
{
  "finished": true,
  "state": "failed",
  "id": "098shjhv9"
}