Edit in GitHubLog an issue

Import API

The Adobe Commerce Reporting Import API allows you to push arbitrary data into your data warehouse using REST.

Before using the import API, make sure you authenticate your connection.

Return Codes

The Data Import API uses standard HTTP return codes to indicate the status of a request. Your application should handle each of the following return statuses.

Codes in the 2xx range indicate a successful transaction, codes in the 4xx range indicate a bad request, and codes in the 5xx range indicate an error with Adobe Commerce Reporting. If errors in the 5xx range persist, please contact support.

  • 200 OK - request was successful.
  • 201 Created - new data was added as a result of the request.
  • 400 Bad request - Your request was missing a required parameter.
  • 401 Unauthorized - Authorization failed. Double check your API key.
  • 404 Not Found - The resource you are looking for does not exist.
  • 500 Server Error - There is an error in Adobe Commerce Reporting.

Versioning

The current version of the Import API is v2.

v1 is still available, but will be deprecated in the future.

Test environment

The Data Import API has a full test (sandbox) environment.

The sandbox environment uses the same keys and return codes as the production API, but does not persist incoming data. You can use this environment to test your integration.

Copied to your clipboard
curl -v https://sandbox-connect.rjmetrics.com/v2/client/:cid/:endpoint?apikey=:apikey

Methods

Status

You can always check the status of the Data Import API. This is called when you instantiate the client. This will return a 200-Success response if the API is operational.

Copied to your clipboard
curl -v https://connect.rjmetrics.com

Upsert

The upsert method allows you to push data into your RJMetrics data warehouse. You can push entire arrays of data or single data points. This endpoint will only accept data that have the following properties:

  • The data must be valid JSON.
  • Each data point must contain a keys field. The keys field should specify which fields in the records represent the primary key(s).
  • An array of data must contain no more than 100 individual data points.

Tables in the Data Import API are schemaless. There is no command to create or destroy a table - you can push data to any table name and it will be dynamically generated.

Here are some guidelines for managing tables:

  • Create one table for each type of data point you are pushing.
  • Generally speaking, each data point pushed into a table should have the same schema.
  • Typically, one type of 'thing' will correspond to one table. For example, a typical eCommerce company might have a 'customer', 'order', 'order_item', and 'product' table.
  • Table names must be alphanumeric (plus underscores). Bad table names will result in a 400 Bad Request return code.

Here's an example of an Upsert call:

Copied to your clipboard
curl -X POST -d @filename https://connect.rjmetrics.com/v2/client/:cid/table/:table/data?apikey=:apikey --header "Content-type: application/json"

The above call contains the following variables:

@filename - name of the file you are uploading :cid - your client Id :table - table name :apikey - your API key

Response:

Copied to your clipboard
"status": "complete",
"created_at": "2019-08-05 04:51:02"
client.push_data(
"table_name",
test_data
)

Upsert single data point example

Copied to your clipboard
{
"keys": ["id"],
"id": 1,
"email": "joe@schmo.com",
"status": "pending",
"created_at": "2019-08-01 14:22:32"
}

Upsert array of data points example

Copied to your clipboard
[{
"keys": ["id"],
"id": 1,
"email": "joe@schmo.com",
"status": "pending",
"created_at": "2019-08-01 14:22:32"
},{
"keys": ["id"],
"id": 2,
"email": "anne@schmo.com",
"status": "pending",
"created_at": "2019-08-03 23:12:30"
},{
"keys": ["id"],
"id": 1,
"email": "joe@schmo.com",
"status": "complete",
"created_at": "2019-08-05 04:51:02"
}]

Additional Examples

The following section describes how you can call the import API through various libraries to perform the following tasks:

  • Create a Users Table
  • Create an Orders Table

Create a users table

Your most important table in Adobe Commerce Reporting is your Users table. In your application, you probably have a user object with some data like id, email, and acquisition_source.

This examples describes how to push this data to the Import API.

First, define a template to push the data. Ensure the client is authenticated <api-authentication> and prepare to push the data to the Import API.

Copied to your clipboard
var rjmetrics = require("rjmetrics");
client = new rjmetrics.Client(your-client-id, "your-api-key");
// make sure the client is authenticated before we do anything
client.authenticate().then( function(data) {
// this is where we'll push the data
}).fail(function(err) {
console.error("Failed to authenticate!");
});

Next, create a new function to sync the new data.

Copied to your clipboard
function syncUser(client, user) {
return client.pushData(
// table named "users"
"users",
{
// user_id is the unique key here, since each user should only
// have one record in this table
"keys": ["id"],
"id": user.id,
"email": user.email,
"acquisition_source": user.acquisition_source
});
}

Finally, incorporate the syncUser function into the original script.

Copied to your clipboard
var rjmetrics = require("rjmetrics");
var client = new rjmetrics.Client(your-client-id, "your-api-key");
function syncUser(client, user) {
return client.pushData(
// table named "users"
"users",
{
// user_id is the unique key here, since each user should only
// have one record in this table
"keys": ["id"],
"id": user.id,
"email": user.email,
"acquisition_source": user.acquisition_source
});
}
// let's define some fake users
var users = [
{id: 1, email: "joe@schmo.com", acquisition_source: "PPC"},
{id: 2, email: "mike@smith.com", acquisition_source: "PPC"},
{id: 3, email: "lorem@ipsum.com", acquisition_source: "Referral"},
{id: 4, email: "george@vandelay.com", acquisition_source: "Organic"},
{id: 5, email: "larry@google.com", acquisition_source: "Organic"},
];
// make sure the client is authenticated before we do anything
client.authenticate().then( function(data) {
// iterate through users and push data
users.forEach( function(user) {
syncUser(client, user).then( function(data) {
console.log("Synced user with id " + user.id);
}, function(error) {
console.error("Failed to sync user with id " + user.id);
})
});
}).fail(function(err) {
console.error("Failed to authenticate!");
});

This example is included with the client libraries or can be downloaded from github.

Copied to your clipboard
npm install
node users-table.js

Create an orders table

Now, create an orders table with the following fields: id, user_id, value and sku.

Create a new function to push the order object:

Copied to your clipboard
function syncOrder(client, order) {
return client.pushData(
"orders",
{
"keys": ["id"],
"id": order.id,
"user_id": order.user_id,
"value": order.value,
"sku": order.sku
});
}

Now, plug this into the same template from the users table:

Copied to your clipboard
var rjmetrics = require("rjmetrics");
var client = new rjmetrics.Client(your-client-id, "your-api-key");
function syncOrder(client, order) {
return client.pushData(
"orders",
{
"keys": ["id"],
"id": order.id,
"user_id": order.user_id,
"value": order.value,
"sku": order.sku
});
}
var orders = [
{"id": 1, "user_id": 1, "value": 58.40, "sku": "milky-white-suede-shoes"},
{"id": 2, "user_id": 1, "value": 23.99, "sku": "red-button-down-fleece"},
{"id": 3, "user_id": 2, "value": 5.00, "sku": "bottle-o-bubbles"},
{"id": 4, "user_id": 3, "value": 120.01, "sku": "zebra-striped-game-boy"},
{"id": 5, "user_id": 5, "value": 9.90 , "sku": "kitten-mittons"}
];
client.authenticate().then( function(data) {
orders.forEach( function(order) {
syncOrder(client, order).then( function(data) {
console.log("Synced order with id " + order.id);
}, function(error) {
console.error("Failed to sync order with id " + order.id);
})
});
}).fail(function(err) {
console.error("Failed to authenticate!");
});
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.