All Collections
APSIS One API
Guides & Best practice
Import Profiles with the APSIS One API
Import Profiles with the APSIS One API
Rikke Søndergaard avatar
Written by Rikke Søndergaard
Updated over a week ago

How to Import Profiles

This article will guide you through performing a Profile Import in your APSIS One Account with the APSIS One API.

Profile Imports are performed by first creating an import specification, and then uploading a file matching the specification.

We allow three simultaneous imports per account

Profile Imports can be configured to handle Profile Attribute, Tag, Level of Consent, Folder, Subscription, Channel, and Keyspace mappings.

There are three essential parts to this guide:


Initialize Profile Import

Start by requesting a Profile Import.

When requesting an import, we need to define the import's mappings. These are the following parameters we need to know:

  • Section

  • Keyspace(s)

  • Merge Profiles (When true, Profiles belonging to the Keyspace will be merged with Profiles in other Keyspaces that are also set to true)

  • Consent(s)

  • Address

  • Channel(s)

  • Folder(s)

  • Subscription(s)

  • Level of Consent

  • Tags

  • Attributes

Options:

  • Update existing Profiles. (If your file contains Attributes, Tags or any other data that differs from what is currently in a Profile, replace existing Profile data to match your file.)

  • Clear existing Attributes. (If your file contains an empty field that matches current Profile data, erase existing Profile data to match your file.)

  • Type of file (text/csv)

  • Field selector. (The value of this property is strictly connected to the column name in the CSV file.)

Not all parameters are required. Check the API Reference for more details

Per region host names

APSIS One API is provided under different hostnames depending on your region. For EU use https://api.apsis.one/, for APAC call https://api-apac.apsis.one/.

Let's initialize a Profile Import. In this case we'll import Profiles to the Email Keyspace:

curl --request POST \
--url https://api.apsis.one/v2/audience/sections/section_discriminator/imports \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '
{
"keyspace_mapping": {
"keyspace_discriminator": "com.apsis1.keyspaces.email",
"field_selector": "email-address"
},
"options": {
"update_existing_profiles": true,
"clear_existing_attributes": true
},
"consent_mappings": [
{
"consents": [
{
"resubscribe_if_opted_out": false,
"field_selector": "mens-clothing-shoes",
"channel_discriminator": "com.apsis1.channels.email",
"topic_discriminator": "usercreated.topics.shoes-bcjvwfknxd",
"type": "opt-in"
}
]
}
],
"tag_mappings": [
{
"tag_discriminator": "usercreated.attributes.vip-npqjeo3mbb"
}
],
"attribute_mappings": [
{
"field_selector": "address",
"attribute_version_id": "1234"
}
]
}

A successful call will return the following JSON object.

{
"import_id": "234345345-c862-4a48-45455-7da1ac0e31ew",
"file_upload_url": "https://s3.eu-west-1.amazonaws.com/file-import-uploads",
"file_upload_body": {
"key": "string",
"success_action_status": "string",
"policy": "string",
"content-type": "string",
"x-amz-meta-id": "string",
"x-amz-algorithm": "string",
"x-amz-credential": "string",
"x-amz-date": "string",
"x-amz-signature": "string"
},
"file_upload_url_expires_at": "2017-07-21T17:32:28.761Z"
}

Upload Import File

Let's continue with the second part of the guide, where we upload a file for the Profile Import to process.

Let's take a look at our example CSV file.

email-address

mens-clothing-shoes

address

1

Malmo

0

Copenhagen

0

Stockholm

When the Profile Import was initialized, we were given a URL to upload the file. This parameter can be found in the response data named file_upload_url.

A successful call will return a HTTP 200 OK status code.

Let's upload our CSV file with a simple script.

Python

import requests
fileToImport = open('profiles.csv', 'rb')
files = {
  'file': fileToImport
}
try:
    response = requests.post('https://s3.eu-west-1.amazonaws.com/file-import-uploads-038131127654-stage',
        data = {
        "key": "48916/9d192ca9-bd91-4962-a53e-0f9c055666cc.csv",
        "success_action_status": "200",
        "content-type": "text/csv",
        "policy": "eyJleHBpcmF0aW9uIjoiMjAyMC0wMi0xNFQxMDo0MzozMloiLCJjb25kaXRpb25zIjpbeyJrZXkiOiI0ODkxNi85ZDE5MmNhOS1iZDkxLTQ5NjItYTUzZS0wZjljMDU1NjY2Y2MuY3N2In0seyJzdWNjZXNzX2FjdGlvbl9zdGF0dXMiOiIyMDAifSx7IkNvbnRlbnQtVHlwZSI6InRleHQvY3N2In0seyJYLUFtei1NZXRhLUlkIjoiNGEraDRLR0I1SWFzNFlTVzFwRGh0cURpdUtUa29LVG1pS0hqb2Fqa2hhem1nWTNrZ2JyRWp1T0dyT0d1b09hZHBPS0FvK0tFb09LWG11S3dwT2VMZ09HR3BlU0JyT0Nqb2VPaG9PR0hpdUN1bHVTSW9PS3hqTU80NWJTcDVJQ2w0NENtNDRTRTRZQ2c1b0NtNDRhQnk0N2l1b1p1YUFnIn0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsMSw1MjQyODgwMDBdLHsiaWiJ9XX0=",
        "x-amz-algorithm": "AWS4-HMAC-SHA256",
        "x-amz-credential": "AKIAQRYGK2VTEOFC6HRW/20200214/eu-west-1/s3/aws4_request",
        "x-amz-date": "20200214T094332Z",
        "x-amz-meta-id": "4a+h4KGB5Ias4YSW1pDhtqDiuKTkoKTmiKHjoajkhazmgY3kgbrEjuOGrOGuoOadpOKAo+KEoOKXmuKwpOeLgOGGpeSBrOCjoeOhoOGHiuCuluSIoOKxjMO45bSp5ICl44Cm44SE4YCg5oCm44aBy47iuoTlu4jhgKHjuaAg",
        "x-amz-signature": "d46767995586e37ffed0d1a0f0a65cfb928ee2d99ab9e32995c2a80c7e7d7363"
  },
  files = files)
    print(response.status_code)
    print(response.text)
finally:
    fileToImport.close()

cURL

curl --location --request POST 'https://s3.eu-west-1.amazonaws.com/file-import-uploads-038131127654-stage' \
--header 'Content-Type: multipart/form-data' \
--form 'key=48916/9d192ca9-bd91-4962-a53e-0f9c055666cc.csv' \
--form 'success_action_status=200' \
--form 'content-type=text/csv' \
--form 'policy=eyJleHBpcmF0aW9uIjoiMjAyMC0wMi0xNFQxMDo0MzozMloiLCJjb25kaXRpb25zIjpbeyJrZXkiOiI0ODkxNi85ZDE5MmNhOS1iZDkxLTQ5NjItYTUzZS0wZjljMDU1NjY2Y2MuY3N2In0seyJzdWNjZXNzX2FjdGlvbl9zdGF0dXMiOiIyMDAifSx7IkNvbnRlbnQtVHlwZSI6InRleHQvY3N2In0seyJYLUFtei1NZXRhLUlkIjoiNGEraDRLR0I1SWFzNFlTVzFwRGh0cURpdUtUa29LVG1pS0hqb2Fqa2hhem1nWTNrZ2JyRWp1T0dyT0d1b09hZHBPS0FvK0tFb09LWG11S3dwT2VMZ09HR3BlU0JyT0Nqb2VPaG9PR0hpdUN1bHVTSW9PS3hqTU80NWJTcDVJQ2w0NENtNDRTRTRZQ2c1b0NtNDRhQnk0N2l1b1p1YUFnIn0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsMSw1MjQyODgwMDBdLHsiaWiJ9XX0=' \
--form 'x-amz-algorithm=AWS4-HMAC-SHA256' \
--form 'x-amz-credential=AKIAQRYGK2VTEOFC6HRW/20200214/eu-west-1/s3/aws4_request' \
--form 'x-amz-date=20200214T094332Z' \
--form 'x-amz-meta-id=4a+h4KGB5Ias4YSW1pDhtqDiuKTkoKTmiKHjoajkhazmgY3kgbrEjuOGrOGuoOadpOKAo+KEoOKXmuKwpOeLgOGGpeSBrOCjoeOhoOGHiuCuluSIoOKxjMO45bSp5ICl44Cm44SE4YCg5oCm44aBy47iuoTlu4jhgKHjuaAg' \
--form 'x-amz-signature=d46767995586e37ffed0d1a0f0a65cfb928ee2d99ab9e32995c2a80c7e7d7363' \
--form 'file=@/Users/username/Desktop/profiles.csv'

Fetch Import Status

When we initialised the Profile Import, we were given an Import ID that will allow us to get the status of an Import.

The status of an Import can give valuable information, like whether the job is completed, in progress, waiting for a file, or queued. When the Import is completed, we can see how many Profiles were found, processed, and how many failed.

curl --request GET \
  --url https://api.apsis.one/audience/sections/{section_discriminator}/imports/{import_id} \
  --header 'authorization: Bearer '

A successful call will return the following JSON object.

{
  "import_id": "234345345-c862-4a48-45455-7da1ac0e31ew",
  "result": {
    "status": "completed",
    "profiles_found": 3,
    "profiles_processed": 3,
    "profiles_failed": 0
  }
}

What's Next?

Did this answer your question?