Using the Import API

Hi Alex!

Could you please tell more about the import records job? I’ve read through the documentation, but I didn’t quite understand how to send the prepared import file and what the importId in the request example refers to. Do I need to send the data first and retrieve this id before starting the job?

If Lilla could update the article, it would be helpful to see:
— Wheter the job returns the imported record ids or anything else as a result (the result field in the example is empty).
— The same for the Duplicate Scan Job — the example result doesn’t match what I actuallly get
— What other possible statuses there are besides “COMPLETED”

Thanks a lot!

Hi Mitya,

This is indeed way under-documented. I’ve added it our documentation backlog, but in the meantime here is a quick overview of the process:

Step 1. Obtain the staging URL

Post to https://www.activityinfo.org/resources/imports/stage.
No body required.

You’ll get a response back that looks like this:

{ 
"uploadUrl": "https://storage.googleapis.com/....?xyzsecretxyz",
"importId": "cxy123"
}

Step 2. Upload your data to import

POST the data to import, in the line-delimited JSON format that you’ve linked to above to the URL in the upload URL.

Step 3. Start the ImportJob

Start the ImportJob according to the documentation, providing the importId that you received in Step 1.

If you’re not sure about the format of the requests at any stage, I would recommend using importer in the web application and following along with Chrome Dev tools. Our Javascript application uses this API as well. You can also look at the source code for import.R in our R package which provides a wrapper for this API.

Now for sure, this is a lot of work, especially compared to the user interface which does a lot of the matching and parsing for you. It’s a very generic API that doesn’t make it easy to say, just import the same Excel file every Friday.

We’re excited about the saved import configurations because we think it will open the possibility for a better developer experience as well. You will be able to define your import configuration in the user interface, and then just post a new Excel sheet or CSV file through the API. But we’re not quite there yet!

1 Like

Thanks for the explanation, Alex!

I do look at DevTools from time to time — that’s actually how I managed to do Duplicate Scan. And now the import process is clear too :slight_smile: