Skip to content

Basic import request

James Williamson edited this page Aug 10, 2018 · 10 revisions

It is best to start with a basic payload

How to call the async endpoint

Properties

  • meta: Contains information to be logged when the import has started.
  • settings: Used to control behaviour during Import.
  • data: Payload such as Companies, People, Users etc are placed in here.
{
  "meta": {
    "created_at": "2018-02-15T17:33:56+0000",
    "feed_name": "The corporation"
  },
  "settings": {
    "version": "0.0.1"
  },
  "data": {
    "people": [],
    "companies": [],
    "users": []
    }
  }
}

People, Companies and Users can contain objects that are imported. You can read more about this here

The Curl request for the API looks like this. You will have to authenticate beforehand. Instructions on how to get an Auth Token can be found here (https://dev.bookingbug.com/docs/rest-api/authentication).

curl -X POST \
  https://the-corporation.bookingbug.com/api/v1/admin/37000/imports \
  -H 'App-Id: XXXXXXX' \
  -H 'App-key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
  -H 'Auth-Token: xxxxxxxxxxxxxxxxxxxxxx' \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: application/json' \
  -d '{
  "meta": {
    "created_at": "2018-06-27T09:40:15+01:00",
    "feed_name": "The corporation"
  },
  "settings": {
    "version": "0.0.1"
  },
  "data": {
    "companies": [
      {
        "name": "West Lake Country Club",
        "external_id": "34335",
        "object_type": "company",
        "last_modified": "2018-06-24T22:22:28+01:00",
        "status": "live"
      }
    ]
  }
}'

The above request git ad will return you a response describing what happened during the Import Process. An example is shown below. There is also an Asynchronous version of the endpoint available for long running jobs.

{
    "internal_reference": "ec671f68-ed15-407d-8971-a919efab635d",
    "feed_name": "The corporation",
    "created_at": "2018-06-27T09:40:15+01:00",
    "started_at": "2018-06-27T09:40:17+01:00",
    "completed_at": "2018-06-27T09:40:30+01:00",
    "status": "completed",
    "objects_to_import": 1,
    "objects_imported": 1,
    "objects": [
        {
            "status": "created",
            "object_type": "company",
            "object_external_id": "an_id"
        }
    ]
}

Asynchronous endpoint

Payload can get large and take time to process and that can result in a timeout because of a web server limit. That is why this is an Asynchronous version of the endpoint.

When http request hits this endpoint with a POST it takes the payload and queues it up to be processed. The http endpoint will respond instantly with a response with information about where to get a progress up on the import you just started. The ID that was given to that Import when it was started will also be returned.

To use the async simply do the same request as above with and appended async added to the Url.

POST /api/v1/admin/37000/import/async

This is the recommended approach for Production processing of large data. However, while learning and debugging its recommend to use the Standard endpoint to get fast feedback.