POST reference-data/{dataset}/records/file-import

Overview

The Reference Data API permits interaction with custom data tables associated with your company.  You can use the API's POST reference-data/{dataset}/records/file-import call to add multiple records to your table from a flat file.

This requests supports importing of data to a dataset, mapping of that data to the dataset structure, and setting a user defined error threshold before the import is aborted. To determine which data values and types are supported use GET /v2/reference-data/{dataset}?view=schema

This is an asynchronous call and the response is a ticket with the status of the request. Once the request has been completed the response location will contain the resource for the invidiual record results. This is provided by the Async Results API.

The Async Results response payload contains the following summary information about the results of the call:

  • Counts - Requested, completed, failed, ignored and total.
  • Completed - Index value and timestamp
  • Failed - Index, timestamp and error message
  • Ignored - Index

Resource URI

 https://api.yesmail.com/v2/reference-data/{dataset}/records/file-import

Call Description

In addition to the standard response headers, this API call will also provide a header Content-Location: https://api.yesmail.com/v2/tickets/{id}, which provides the location of the ticket resource where status information is updated. See Tickets API documenation for more details.

URI Parameters

Parameter Required Description
responseUri 

 Optional

A customer-specified URI where Yesmail’s service can post the final status of the request.  See Tickets API documentation for more details.

responseRef 

 Optional

A customer-specified value that the customer may wish to use to track the ticket internally.  See Tickets API documentation for more details.

 

Parameters

Parameter

Required

Description

errorThreshold

Optional

Optional property specifying when to stop the import process due to failures. Default is 0 or no check.

  • integer – An integer value specifying an exact error count to trigger the stop. Set to 0 (zero) to attempt import of the entire source file.
  • percent – A percentage value between > 0% and < 100% indicating when to stop processing. Percentage values must be quoted. 

importType

Optional

Optional property indicating how existing records are treated during the import, default value is update. New records are always added.

  • ignore – Skip source records if the destination list load table already has the same email address, inserts the source record if no match is found. Think of this as a PUT with a "If-None-Match" header.
  • update – Will update existing records with the data available, or insert new records if no match is found. Think of this as a PUT when there is no match and as a POST (partial) for a match.
  • replace – Will replace existing records and insert new records with no match. Think of this as a straight PUT request.

source

Required headers – Optional property, defaults to false if not present. Indicates whether there is a header row in the source files.
  • key – The key must match a column name in the destination list load table. The request will fail if the name in the map does not exists in the list load table.
    •  "," – Comma is the default value, matching a standard CSV format.
    • "\t" - Tab is used to separate column values in the source file.
    •  "|" – A pipe symbol is used to separate column values in the source file.
    • ";" – A semi-colon is used to separate column values in the source file.
  • uri – Required URI for where the source data file is located. Allowed protocols are HTTP, HTTPS and FTP. Basic authentication embedded in the URI is supported. Examples:​
    • http://my.host.com/path/data.csv
    • https://username:password@my.host.com/path/data.txt
    • ftp://username:password@ftp.host.com/path/data.csv

HTTP Return Codes

 

Code

Description

202 Accepted

The request has been accepted.

400 Bad Request

The request could not be understood by the server due to malformed syntax at the request level.  Verify all emails are in lower case. If there are errors at the level of the individual member, but the syntax for one or more members can be understood, they will be processed correctly with a 200 OK return code, with the errors provided in the response payload as described above.

If number of failed requests exceeds the error threshold, then no records will be updated or added.

401 Unauthorized

The request requires user authentication.  Invalid Api-User and/or Api-Key header value.

Request Payload: 
{
  "errorThreshold": 100,
  "importType": "replace",
  "source": {
    "headers": false,
    "mappings": [
      { "payloadid": 0 },
      { "carproductname": 1 },
      { "cartproductimage": 2 }
    ],
    "separator": ",",
    "uri": "http://my.host.com/path/file.txt"
  }
}
Response Payload: 
{
  "id": "654321",
  "state": "completed",
  "message": "File imported successfully.",
  "lastUpdate": "2014-03-03T17:33:52Z",
  "events": [
    {
      "state": "accepted",
      "message": "File import to target list accepted.",
      "time": "2014-03-03T17:33:12Z"
    },
    {
      "state": "processing",
      "message": "File downloaded.",
      "time": "2014-03-03T17:33:22Z"
    },
    {
      "state": "processing",
      "message": "File pre-parsed, importing 1240 records.",
      "time": "2014-03-03T17:33:22Z"
    },
    {
      "state": "completed",
      "message": "File imported successfully.",
      "time": "2014-03-03T17:33:52Z"
    }
  ],
  "request" : {
    "id": "1234-4321-567890-098765",
    "user": "db-username",
    "time": "2014-03-03T17:33:01Z",
    "uri": "https://api.yesmail.com/v2/target-lists/my-list/members/file-import"
  },
  "response": {
    "uri": "http://callers.domain.com/path",
    "ref": "callers-ref-value",
    "location": "https://api.yesmail.com/v2/async-results/987654"
  }
}
{
  "id": "987654",
  "lastUpdate": "2014-03-03T17:33:52Z",
  "counts": {
    "completed": 1238,
    "failed": 1,
    "ignored": 1,
    "total": 1240,
    "requested": 1240
  },
  "completed ": [
    {
      "index": 0,
      "time": "2014-03-03T17:33:22Z"
    },
    {
      "index": 2,
      "time": "2014-03-03T17:33:42Z"
    },
    {
      "index": 3,
      "time": "2014-03-03T17:33:52Z"
    },
    ...
    ...
    ...
  ],
  "failed": [
    {
      "index": 1,
      "time": "2014-03-03T17:33:32Z",
      "error": {
        "status": 400,
        "message": "Invalid data type."
      }
    }
  ],
  "ignored": [
    {
      "index": 4
    }
  ]
}