Knowledge Base

API Reference Documentation for Testing & Creating a Mapping

Below is a guide on how to test and create mappings using Narrative’s Mapping API. Mappings are written in NQL (Narrative Query Language). Note that some identifiers such as "value" and "type" are reserved keywords and must be wrapped in quotes in your NQL expressions.

For more information on Narrative APIs, visit the official documentation at api.narrative.io.


1. Testing a Mapping

This step allows you to verify how your NQL expressions will transform specific sample records before committing the mapping.

Endpoint

POST https://app.narrative.io/mappings/test

Request Body

{
    "attribute_id": 1,
    "dataset_id": 11035,
    "mapping": {
        "type": "object_mapping",
        "property_mappings": [
            {
                "path": "type",
                "expression": "'sha256_email'"
            },
            {
                "path": "value",
                "expression": "lower(trim(email))"
            }
        ]
    }
}
FieldTypeRequiredDescription
attribute_idnumberYesNumeric identifier for the attribute you’re mapping.
dataset_idnumberYesNumeric identifier for the dataset in Narrative.
mappingobjectYesThe core definition of the mapping, written in NQL.
typestringYesFor object-type mappings, use "object_mapping".
property_mappingsarrayYesA list of mappings from source fields (e.g., email) to output.
pathstringYesThe target output field (e.g., "type", "value") which are reserved words and must be in quotes.
expressionstringYesThe NQL expression used to transform data (e.g., "lower(trim(email))").

Note: In the above mapping, "type" is set to a constant 'sha256_email', and "value" is transformed with lower(trim(email)).

Example Response

Status Code: 200 OK
{
    "records": [
        {
            "input": {
                "email": "someone@example.com"
            },
            "output": {
                "unique_id": {
                    "type": "sha256_email",
                    "value": "someone@example.com"
                }
            }
        },
        {
            "input": {
                "email": "anotherperson@example.net"
            },
            "output": {
                "unique_id": {
                    "type": "sha256_email",
                    "value": "anotherperson@example.net"
                }
            }
        }
    ]
}
  • input: Shows the original record values (e.g., "someone@example.com").
  • output: Demonstrates how the mapping transforms each record (i.e., setting "type" to "sha256_email" and "value" to the lowercased version of the email).

2. Creating a Mapping

Once your mapping is tested and verified, you can create (or update) a mapping for your company so that Narrative will process your dataset using these rules.

Endpoint

POST https://app.narrative.io/mappings/companies/{{attribute_id}}

Replace {{attribute_id}} with the numeric attribute_id you’re configuring.

Request Body

{
    "attribute_id": 1,
    "dataset_id": 11035,
    "mapping": {
        "type": "object_mapping",
        "property_mappings": [
            {
                "path": "type",
                "expression": "'sha256_email'"
            },
            {
                "path": "value",
                "expression": "lower(trim(email))"
            }
        ]
    }
}

This request is nearly identical to the test request, except it targets the company-specific endpoint and permanently saves the mapping.

Example Response

Status Code: 200 OK
{
    "id": "dd7941b8-89c3-422c-aae2-e6ca15e894b8",
    "attribute_id": 1,
    "company_id": 1,
    "created_at": "2025-02-21T23:39:11.603803Z",
    "created_by": 321,
    "dataset_id": 11035,
    "derived_from": null,
    "mapping": {
        "type": "object_mapping",
        "property_mappings": [
            {
                "path": "type",
                "expression": "'sha256_email'"
            },
            {
                "path": "value",
                "expression": "lower(trim(email))"
            }
        ]
    },
    "scope": "private",
    "source": "company",
    "status": "active",
    "tags": [],
    "updated_at": "2025-02-21T23:39:11.603803Z",
    "updated_by": 321
}
FieldDescription
idThe unique identifier for the newly created mapping.
company_idThe numeric identifier for your company in Narrative.
scopeIndicates whether this mapping is private (only accessible to your company) or shared.
statusactive indicates the mapping is ready and will be applied to the dataset’s records.
mappingReturns the full mapping definition, confirming your transformation rules.

Additional Tips

  1. Reserved Terms: Wrap "type" and "value" in quotes if you use them as output fields in your mapping expressions.
  2. NQL Functions: Examples include lower(), trim(), concat(), etc. For more details, see api.narrative.io.
  3. Testing First: Always use the /mappings/test endpoint to validate transformations before creating or updating a production mapping.
  4. Case Sensitivity: Functions like lower() ensure consistent formatting, especially helpful for emails.
< Back
Rosetta

Hi! I’m Rosetta, your big data assistant. Ask me anything! If you want to talk to one of our wonderful human team members, let me know! I can schedule a call for you.