> ## Documentation Index
> Fetch the complete documentation index at: https://docs.narrative.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Update a mapping

> Update the definition of a mapping between an attribute and a dataset.

Note: the attribute and dataset with which a mapping is associated cannot be updated.



## OpenAPI

````yaml https://docs-cdn.narrative.io/api-reference/main/openapi.json put /mappings/{mapping_id}
openapi: 3.1.1
info:
  contact:
    email: support@narrative.io
    name: Narrative Support
    url: https://www.narrative.io
  termsOfService: https://www.narrative.io/legal/terms-of-service
  x-logo:
    url: >-
      https://cdn.narrative.io/images/company-logos/prod/narrative-logo-text-white.svg
    backgroundColor: rgb(9, 34, 166)
    altText: Narrative Logo
  description: >-
    The [Narrative Data Collaboration Platform](https://app.narrative.io) API is
    organized around REST. Our API has predictable resource-oriented URLs,
    accepts form-encoded request bodies, returns JSON-encoded responses, and
    uses standard HTTP response codes, authentication, and verbs.



    The current version is a pre-release beta.  It may result in unexpected
    behavior and there may be breaking changes in future releases up to the 1.0
    release.
  title: Narrative Data Collaboration Platform API
  version: 2.4.x
servers:
  - url: https://api-dev.narrative.io
  - url: https://api.narrative.io
security: []
tags:
  - name: Access Rules
    description: >-
      Access rules let data providers control who can purchase their data and
      the terms of purchase.


      The `access-rules` API allows you to manage access rules for your
      datasets.


      Related guides:
        - [What is an access rule?](https://kb.narrative.io/access-rules)
  - name: Agent Conversations
    description: >-
      Build LLM-driven workflows that can call MCP tools, ask the caller for
      input, and return structured answers.


      A conversation pins a model, a system prompt, and a tool catalog. Each run
      sends the model a user message (or

      a batch of tool outputs from a previously-paused run); the model decides
      whether to answer directly, call a

      server-side tool (resolved by the platform via Model Context Protocol), or
      call a client-side tool (which pauses

      the run with `requires_action` and waits for the caller to reply).


      Related guides:
        - [Agent Conversations Reference](https://docs.narrative.io/reference/architecture/agent-conversations)
        - [Error catalog](https://docs.narrative.io/reference/architecture/agent-conversations/errors/conversation-not-found)
  - name: MCP Connections
    description: >-
      Connect external (non-Narrative) MCP servers so agent runs can call their
      tools with the

      calling user's own OAuth authorization.


      A connection is created interactively: `POST /mcp-connections` runs OAuth
      discovery and

      Dynamic Client Registration against the server and returns a consent URL;
      the user authorizes

      in a browser; the authorization server redirects to `GET
      /mcp-connections/callback`, which

      finishes the token exchange and marks the connection `connected`. Tokens
      are stored encrypted

      and used server-side — they are never returned by the API. Once connected,
      reference the

      connection by id from an agent run's `mcp_servers[].connection_id`.
  - name: App Invites
    description: >-
      App invites allow applications to create one-time, shareable links on
      behalf of their users. These links

      enable users to invite third parties who do not have a Narrative account
      to perform actions within the

      application.


      For example, a Narrative user can send an invite link to a third party who
      then completes a Pinterest

      OAuth flow and creates a connector profile in the inviter's account,
      allowing the inviter to deliver

      audience data to the third party's Pinterest account without the third
      party needing a Narrative account.


      This API is intended to be used by applications (via app client
      credentials) to create and manage invites

      on behalf of their users, which can then be shared with invitees.
  - name: Apps
    description: >-
      Apps are applications bundled with a UI that can perform various actions
      on behalf of a user utilizing the Narrative API.

      Related guides:
        - [Building a Narrative Native App](https://www.narrative.io/knowledge-base/how-to-guides/building-a-narrative-native-app)
  - name: Access Tokens
    description: API Access Token management
  - name: Attributes
    description: >-
      An attribute models a standardized data point available for sale on the
      Narrative marketplace.


      Narrative automatically turns data points from provider datasets into
      attributes so that buyers can purchase well-formed, standardized data from
      any supplier on the marketplace.
  - name: Auth
    description: >-
      API token is a crucial step for developers to securely authenticate
      requests to the Narrative API

      Related guides:
        - [How to Create an API Token](https://www.narrative.io/knowledge-base/how-to-guides/understanding-narratives-apis/create-an-api-token)
  - name: Authentication
    description: User login and registration
  - name: Billings
    description: Used by Narrative internally to bill customers
  - name: Companies
    description: A collection of employees
  - name: Company Marketing Information
    description: Useful information related to companies
  - name: Compute Pools
    description: >-
      Compute pools represent compute resources (e.g. Snowflake warehouses)
      provisioned within a data plane.

      Companies can manage and share compute pools, assign them to jobs, and set
      a default compute pool on data planes.
  - name: Connections
    description: Associations between connectors and datasets
  - name: Data Shops
    description: |-
      Self-hosted website to sell your data
      Related guides:
        - [Setting up your datashop](https://www.narrative.io/knowledge-base/how-to-guides/shop-builder/settting-up-your-data-shop)
  - name: Data Streams
    description: >-
      The `data-stream` API endpoints allows one to create and update
      data-streams. Additionally the endpoints allow

      finding data-streams using free text search. A few of the endpoints are
      behind authorization.


      Update endpoint allows a client to post an edited data-stream document as
      is, without having to change its shape.

      The API ensures that only certain fields are allowed to be modified.
      Attempts to modify fields not up for client

      modifications are ignored.


      Related guides:
        - [What is a data stream?](https://kb.narrative.io/what-is-a-data-stream)
  - name: Contracts
    description: Contracts related APIs
  - name: Datasets
    description: >-
      Any kind of data, in any schema, can be pushed into the Narrative Data
      Collaboration Platform as a dataset exactly as it is stored in your own
      system.


      The `datasets` API allows you to manage your datasets.
  - name: Destinations
    description: >-
      Destinations associate a subscription to a profile. Optionally, ad-hoc
      quick settings can be configured to a destination.

      Those quick settings have to match the format defined on the app manifest.
  - name: Installations
    description: Installations of Applications for a profile
  - name: Jobs
    description: >-
      Jobs represent an operation done on a given data plane. All jobs today are
      tied to a query that represents a forecast or a materialized view.


      The jobs API provides an interface for interacting with the jobs table,
      which stores various operations involving reading or writing data. This
      API allows users to retrieve detailed information about specific jobs,
      including cost forecasts, data forecasts, NQL forecasts and materialized
      views.
  - name: Mappings
    description: >-
      A mapping is a transformation from a dataset to an attribute. Defining a
      mapping between a dataset and an attribute makes the dataset eligible to
      participate in subscriptions where a buyer is purchasing the target
      attribute.
  - name: Model Inference
    description: Model Inference
  - name: Models
    description: >-
      Machine learning models for training and inference.


      Models can be stored in HuggingFace or Narrative repositories and have
      configurable

      collaborator permissions for training and inference access.


      The `models` API allows you to list, retrieve, and update models
      accessible to your company.
  - name: NQL
    description: >-
      Narrative Query Language (NQL) is a specialized, SQL-inspired language
      designed to query and manipulate data within the Narrative platform. While
      it looks and feels much like standard SQL, it offers extended
      functionality and syntax that let you leverage platform-specific
      features—such as referencing datasets by their IDs, creating materialized
      views, or generating forecasts—without having to manage the complexities
      of different query engines behind the scenes. NQL queries can ultimately
      compile down to multiple underlying engines (e.g., Snowflake, Spark) to
      execute your requests efficiently in the Narrative ecosystem.
  - name: Payment Methods
    description: Payment methods used to purchase data
  - name: Products
    description: Internal routes used to offer datastream as products
  - name: Profiles
    description: >-
      App profiles are associated with an installation. They represent a
      reference to a configuration that the app can use to save confidential
      information outside of Narrative's control.

      Profiles are currently used to configure settings for connector apps.
  - name: Resources
    description: >-
      Narrative gives you access to managed resources, like your own AWS S3
      bucket, so that you can effortlessly buy and sell data on the platform.


      The `resources` API allows you to manage your resources.
  - name: Schema Inference
    description: >-
      The `schema-inference` API analyzes submitted files to automatically infer
      and return their structure as a dataset schema.
  - name: Schema Presets
    description: >-
      The `schema-presets` API allows you to list the available schema presets,
      get detailed information about a specific one and manage its life cycle.


      You can create a schema preset from scratch or create one based on an
      existing one, administrators can create platform wide available (public)
      schema preset.
  - name: Subscriptions
    description: >-
      In the Narrative Data Collaboration Platform a subscription represents a
      set of rules dictating the commercial terms related to the licensing of
      data.


      The `subscriptions` API allows you to set and get information about
      `subscription` objects owned by the authenticated account.
  - name: Uploads
    description: >-
      The `uploads` API allows you to send files to Narrative and use them to
      perform tasks like creating a list or adding data to a dataset.
  - name: Usage
    description: >-
      The `usage` API enables the recording of usage events associated with a
      product.
  - name: Workflows
    description: >-
      The `workflows` API allows you to create, schedule, trigger, and archive
      workflows.

      Workflows are defined using a serverlessworkflow YAML specification.
paths:
  /mappings/{mapping_id}:
    put:
      tags:
        - Mappings
      summary: Update a mapping
      description: >-
        Update the definition of a mapping between an attribute and a dataset.


        Note: the attribute and dataset with which a mapping is associated
        cannot be updated.
      parameters:
        - $ref: '#/components/parameters/MappingId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MappingUpdateRequest'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MappingResponse'
      security:
        - BearerAuth: []
components:
  parameters:
    MappingId:
      in: path
      name: mapping_id
      required: true
      description: Unique identifier for a mapping.
      schema:
        type: string
        format: uuid
      example: ea9dddd2-e3ee-40b5-b03e-c3cd37c8a6f0
  schemas:
    MappingUpdateRequest:
      type: object
      properties:
        mapping:
          $ref: '#/components/schemas/RawMappingDefinition'
    MappingResponse:
      type: object
      properties:
        id:
          $ref: '#/components/schemas/MappingId'
        attribute_id:
          type: integer
          description: The target attribute's ID.
        created_at:
          type: string
          description: ISO-8601 timestamp indicating when the mapping was created.
          example: '2021-08-26T21:06:07.710357Z'
        dataset_id:
          type: integer
          description: The source dataset's ID.
        mapping:
          $ref: '#/components/schemas/MappingDefinition'
        status:
          $ref: '#/components/schemas/MappingStatus'
        updated_at:
          type: string
          description: ISO-8601 timestamp indicating when the mapping was last updated.
          example: '2021-08-26T21:06:07.710357Z'
        created_by:
          allOf:
            - $ref: '#/components/schemas/schemas_UserId'
            - description: Unique id from a user who created it.
        updated_by:
          allOf:
            - $ref: '#/components/schemas/schemas_UserId'
            - description: Unique id from a user who updated it.
        company_id:
          $ref: '#/components/schemas/CompanyId'
        scope:
          $ref: '#/components/schemas/MappingScope'
        source:
          $ref: '#/components/schemas/MappingSource'
        derived_from:
          $ref: '#/components/schemas/MappingId'
      required:
        - id
        - attribute_id
        - created_at
        - dataset_id
        - mapping
        - status
        - updated_at
        - created_by
        - updated_by
        - scope
        - source
      example:
        id: ea9dddd2-e3ee-40b5-b03e-c3cd37c8a7f0
        attribute_id: 1
        created_at: '2021-12-10T00:00:00Z'
        dataset_id: 3
        mapping:
          type: object_mapping
          property_mappings:
            - path: foo
              expression: upper(`US Kennel ID`)
              dependencies:
                properties:
                  - US Kennel ID
            - path: bar.baz.qux
              expression: weight * 10000
              dependencies:
                properties:
                  - weight
        status: active
        updated_at: '2021-12-10T00:00:01Z'
        created_by: 1
        updated_by: 1
        company_id: 100
        scope: global
        source: admin
        derived_from: ea9dddd2-e3ee-40b5-b03e-c3cd37c8a6f0
    RawMappingDefinition:
      description: >-
        Mapping definition for create/update requests. Dependencies are computed
        server-side and not provided by the client.
      oneOf:
        - $ref: '#/components/schemas/RawObjectMapping'
        - $ref: '#/components/schemas/RawValueMapping'
        - $ref: '#/components/schemas/RawCachedMapping'
    MappingId:
      description: Unique identifier for a mapping.
      type: string
      format: uuid
      example: ea9dddd2-e3ee-40b5-b03e-c3cd37c8a6f0
    MappingDefinition:
      oneOf:
        - $ref: '#/components/schemas/ObjectMapping'
        - $ref: '#/components/schemas/ValueMapping'
        - $ref: '#/components/schemas/CachedMapping'
    MappingStatus:
      type: string
      description: |
        The status of the mapping.
          * `active` - Active mappings can be used
          * `archived` - Archived/Deleted mappings - mapping no longer in use
          * `pending` - Pending mappings need to be accepted before they can be used
      enum:
        - active
        - archived
        - pending
    schemas_UserId:
      type: integer
      format: int64
      example: 20
    CompanyId:
      type: integer
      format: int64
      description: The id of an existing company
      example: 345
    MappingScope:
      type: string
      description: |
        The scope of the mapping.
          * `global` - Mappings available to all
          * `private` - Company private mappings
      enum:
        - global
        - private
    MappingSource:
      type: string
      description: |
        The source of the mapping.
          * `company` - Company private mapping
          * `admin` - Admin created/promoted mapping
          * `system` - System (Automated/ML) mappings
          * `lineage` - Lineage-derived mappings (editable without admin)
          * `rosetta_stone` - Rosetta Stone mappings (editable without admin)
      enum:
        - company
        - admin
        - system
        - lineage
        - rosetta_stone
    RawObjectMapping:
      type: object
      description: >-
        Object mapping definition for create/update requests (without
        dependencies).
      required:
        - type
        - property_mappings
      properties:
        type:
          type: string
          description: A mapping from a dataset to an attribute with a type of `object`.
          enum:
            - object_mapping
        property_mappings:
          type: array
          description: >-
            `property_mappings` define how a value for each property of the
            target attribute is constructed from a row of the source dataset.


            A mapping must be provided for each of the target attribute's
            _required_ properties.
          items:
            type: object
            properties:
              expression:
                $ref: '#/components/schemas/MappingExpression'
              path:
                $ref: '#/components/schemas/MappingPath'
    RawValueMapping:
      type: object
      description: >-
        Value mapping definition for create/update requests (without
        dependencies).
      required:
        - type
        - expression
      properties:
        type:
          type: string
          description: >-
            A mapping from a dataset to an attribute with a primitive type, i.e.
            one of `array`, `boolean`, `double`, `long`, `string`, or
            `timestamptz`.
          enum:
            - value_mapping
        expression:
          $ref: '#/components/schemas/MappingExpression'
    RawCachedMapping:
      type: object
      description: >-
        Cached mapping definition for create/update requests. The cache dataset
        is created automatically when the mapping is created and archived when
        the mapping is deleted or its `input_expressions` change, so no
        `cache_dataset_id` is supplied here. The assigned id is returned on the
        read shape (`CachedMapping`). Rows from the source dataset are joined to
        the cache at query time using `input_expressions` as the join key.


        cached_mapping is only valid in company-scoped create endpoints (e.g.
        `POST /mappings/companies/{company_id}`) and is not permitted on opt-out
        attributes (data_privacy_request_identifier, unique_id,
        identifier_relation).
      required:
        - type
        - input_expressions
      properties:
        type:
          type: string
          enum:
            - cached_mapping
        input_expressions:
          type: array
          minItems: 1
          description: >-
            One or more SQL expressions evaluated against the source dataset to
            build the join key. Multi-column keys are concatenated with a
            separator at query time, so the cache dataset must populate its
            `input` column with the equivalent encoding.
          items:
            $ref: '#/components/schemas/MappingExpression'
    ObjectMapping:
      type: object
      required:
        - type
        - property_mappings
      properties:
        type:
          type: string
          description: A mapping from a dataset to an attribute with a type of `object`.
          enum:
            - object_mapping
        property_mappings:
          type: array
          description: >-
            `property_mappings` define how a value for each property of the
            target attribute is constructed from a row of the source dataset.


            A mapping must be provided for each of the target attribute's
            _required_ properties.
          items:
            type: object
            properties:
              expression:
                $ref: '#/components/schemas/MappingExpression'
              path:
                $ref: '#/components/schemas/MappingPath'
              dependencies:
                $ref: '#/components/schemas/MappingExpressionDependencies'
    ValueMapping:
      type: object
      required:
        - type
        - expression
      properties:
        type:
          type: string
          description: >-
            A mapping from a dataset to an attribute with a primitive type, i.e.
            one of `array`, `boolean`, `double`, `long`, `string`, or
            `timestamptz`.
          enum:
            - value_mapping
        expression:
          $ref: '#/components/schemas/MappingExpression'
        dependencies:
          $ref: '#/components/schemas/MappingExpressionDependencies'
    CachedMapping:
      type: object
      description: >-
        Read shape for cached mappings. See `RawCachedMapping` for create/update
        requests and the surrounding constraints.
      required:
        - type
        - cache_dataset_id
        - input_expressions
      properties:
        type:
          type: string
          enum:
            - cached_mapping
        cache_dataset_id:
          type: integer
        input_expressions:
          type: array
          minItems: 1
          items:
            $ref: '#/components/schemas/MappingExpression'
        dependencies:
          $ref: '#/components/schemas/MappingExpressionDependencies'
    MappingExpression:
      type: string
      description: >-
        A raw SQL expression which produces a value from the source dataset for
        the target primitive attribute type.


        E.g. for a source dataset with the following type definition:


        ```

        {
          "type": "object",
          "properties": {
            "firstName": {
              "type": "string"
            },
            "lastName": {
              "type": "string"
            }
          },
          "required": [
            "lastName"
          ]
        }

        ```



        Valid expressions include:


        - Lower casing the first name:


        ```sql

        lower(firstName)

        ```


        - Constructing a "full name" from the first and last name:


        ```sql

        concat_ws(' ', coalesce(firstName, ''), lastName)

        ```


        - Taking the first initial of the first name if is not null:


        ```sql

        case when firstName is not null and char_length(firstName) > 0 then
        substr(firstName, 1) else null end

        ```
    MappingPath:
      type: string
      description: >-
        A string indicating which property of the target attribute the
        expression is producing a value for.


        E.g. for an attribute with the following type definition;


        ```

        {
          "type": "object",
          "properties": {
            "latitude": {
              "type": "double"
            },
            "longitude": {
              "type": "double"
            },
            "location_accuracy": {
              "type": "object",
              "properties": {
                "horizontal": {
                  "type": "double"
                },
                "vertical": {
                  "type": "double"
                }
              }
            }
          },
          "required": [
            "latitude",
            "longitude"
          ]
        }

        ```


        The possible paths are:


        - `latitude`

        - `longitude`

        - `location_accuracy.horizontal`

        - `location_accuracy.vertical`
    MappingExpressionDependencies:
      type: object
      description: Describes the dataset fields that a mapping expression depends on.
      properties:
        properties:
          type: array
          description: List of dataset field references that the mapping expression uses.
          items:
            type: string
          example:
            - firstName
            - lastName
      example:
        properties: []
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer

````