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

# Bulk upsert metafields for a shopper

> Creates or updates metafields for the specified shopper. Metafields are matched by namespace and key.



## OpenAPI

````yaml /api-reference/platform_v1.json put /api/platform/v1/shoppers/{shopper_ref}/metafields
openapi: 3.0.3
info:
  title: PLATFORM API V1
  version: 1.0.0
  contact:
    name: BSPK API Support
    email: bspk-support@bspk.com
  description: >-

    # Introduction


    The BSPK RESTful JSON API gives you access to your company's BSPK data.

    For all BSPK API related questions please email: *bspk-support@bspk.com*



    ### Authentication


    BSPK uses Token-Based API Authentication. API keys can be managed from the
    API Keys section in your admin interface. All unauthenticated requests will
    return an HTTP 401 response.


    **Important:**  Developers with BSPK API keys will be granted full access to
    the data in each endpoint. Access to this data is binary: everything or
    nothing.


    **Authorization header**

    Your  `Authorization`  header should be in the following format:

    ```

    Authorization: Bearer [API_KEY]

    ```


    ### Throttling


    API requests are limited to the amount specified in the returned
    `X-RateLimit-Limit` header (per 10 seconds). Exceeding that limit will cause
    BSPK to return an `HTTP 429` response. Check the `X-RateLimit-Limit` and
    `X-RateLimit-Remaining` headers to see how many more requests you are
    allowed until throttling kicks in.



    ### Error Codes


    - 400 - Bad Request.

    - 401 - Unauthorized – Invalid BSPK API key.

    - 404 - Not Found – Resource not found.

    - 422 - Unprocessable entity.

    - 429 - Throttle Limit reached.

    - 500 - BSPK Internal Server Error


    ### Validation


    Methods that take input will validate all parameters. Any parameter that
    fails validation will trigger an error response with status HTTP 422. The
    response body will be a JSON object like the example below which includes a
    list of fields that failed validation.


    `{'errors':[{'title': 'No clients found with IDs: [NON_EXISTING_ID,
    OTHER_NON_EXISTING_ID]','code':'not_found'}]}`



    ### Additional Information


    - Fields without a value will return null

    - Timestamps are rendered in ISO-8601 format (e.g. 2018-07-21T17:32:28Z)

    - BSPK reserves the right to add more properties to objects, but will never
    change or remove them. Any breaking changes will result in a major API
    version update.
         
servers:
  - url: https://api.bspk.com
    description: Production
security:
  - BearerAuth: []
paths:
  /api/platform/v1/shoppers/{shopper_ref}/metafields:
    put:
      tags:
        - Shopper Metafields
      summary: Bulk upsert metafields for a shopper
      description: >-
        Creates or updates metafields for the specified shopper. Metafields are
        matched by namespace and key.
      operationId: upsertShopperMetafields
      parameters:
        - name: shopper_ref
          in: path
          description: Shopper external ID
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                metafields:
                  type: array
                  items:
                    type: object
                    properties:
                      namespace:
                        type: string
                        example: custom
                      key:
                        type: string
                        example: loyalty_tier
                      value:
                        type: string
                        example: gold
                      value_type:
                        type: string
                        enum:
                          - single_line_text_field
                          - boolean
                          - date
                          - json
                        example: single_line_text_field
                      is_list:
                        type: boolean
                        example: false
                    required:
                      - namespace
                      - key
                      - value
                      - value_type
              required:
                - metafields
      responses:
        '200':
          description: Successful upsert, returns all metafields
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/metafield_array'
        '404':
          description: Shopper not found
          content:
            application/json:
              schema: {}
        '422':
          description: Validation errors
          content:
            application/json:
              schema: {}
      security:
        - BearerAuth: []
components:
  schemas:
    metafield_array:
      type: array
      items:
        $ref: '#/components/schemas/metafield'
    metafield:
      type: object
      properties:
        id:
          type: integer
        namespace:
          type: string
        key:
          type: string
        value:
          type: string
        value_type:
          type: string
        is_list:
          type: boolean
        json_value:
          nullable: true
        created_at:
          type: string
        updated_at:
          type: string
      required:
        - id
        - namespace
        - key
        - value
        - value_type
        - is_list
        - created_at
        - updated_at
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer

````