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

# Upload Customers in Bulk via CSV

> Update an existing customer



## OpenAPI

````yaml POST /api/v1/customers/csv-upload
openapi: 3.0.1
info:
  title: Metrifox API Documentation
  version: v1
  description: >-
    Welcome to Metrifox Platform's API documentation. This comprehensive API
    suite enables seamless integration with our platform, providing secure and
    efficient access to our services.
servers:
  - url: https://{defaultHost}
    variables:
      defaultHost:
        default: api.metrifox.com
security:
  - api_key: []
paths:
  /api/v1/customers/csv-upload:
    post:
      tags:
        - Customers
      summary: Upload customers from CSV
      description: >
        Creates multiple customers from a CSV file upload. The endpoint supports
        only CSV file format in multipart form data.


        **Required Fields:**

        - `file`: Must be a CSV file containing customer data


        **Response Format:**

        - Returns detailed statistics about the upload process

        - Includes counts of successful and failed uploads

        - Lists all successfully created customers

        - Provides detailed error information for failed customers
      operationId: uploadCustomersCsv
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: '#/components/schemas/CustomerCsvRequest'
            examples:
              csv_upload:
                summary: CSV File Upload
                value:
                  file: customers.csv
      responses:
        '200':
          description: CSV upload processed successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CustomerCSVResponse'
              examples:
                all_success:
                  summary: All Customers Created Successfully
                  value:
                    total_customers: 3
                    successful_upload_count: 3
                    failed_upload_count: 0
                    customers_added:
                      - id: 550e8400-e29b-41d4-a716-446655440000
                        customer_key: acme-corp-001
                        primary_email: contact@acme.com
                        customer_type: BUSINESS
                      - id: 550e8400-e29b-41d4-a716-446655440001
                        customer_key: tech-solutions-002
                        primary_email: info@techsolutions.com
                        customer_type: BUSINESS
                      - id: 550e8400-e29b-41d4-a716-446655440002
                        customer_key: jane-doe-003
                        primary_email: jane.doe@example.com
                        customer_type: INDIVIDUAL
                    customers_failed: []
                partial_success:
                  summary: Partial Success
                  value:
                    total_customers: 5
                    successful_upload_count: 3
                    failed_upload_count: 2
                    customers_added:
                      - id: 550e8400-e29b-41d4-a716-446655440000
                        customer_key: acme-corp-001
                        primary_email: contact@acme.com
                        customer_type: BUSINESS
                      - id: 550e8400-e29b-41d4-a716-446655440001
                        customer_key: tech-solutions-002
                        primary_email: info@techsolutions.com
                        customer_type: BUSINESS
                      - id: 550e8400-e29b-41d4-a716-446655440002
                        customer_key: jane-doe-003
                        primary_email: jane.doe@example.com
                        customer_type: INDIVIDUAL
                    customers_failed:
                      - row: 4
                        customer_key: invalid-customer-004
                        errors:
                          - customer_type is required
                          - primary_email format is invalid
                      - row: 5
                        customer_key: duplicate-customer-005
                        errors:
                          - customer_key already exists
                all_failed:
                  summary: All Customers Failed
                  value:
                    total_customers: 2
                    successful_upload_count: 0
                    failed_upload_count: 2
                    customers_added: []
                    customers_failed:
                      - row: 1
                        customer_key: missing-fields-001
                        errors:
                          - customer_type is required
                          - primary_email is required
                      - row: 2
                        customer_key: invalid-email-002
                        errors:
                          - primary_email format is invalid
        '401':
          description: Unauthorized - Invalid or missing API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      x-codeSamples:
        - lang: python
          label: Python SDK
          source: |
            from metrifox_sdk import MetrifoxClient

            client = MetrifoxClient(api_key="your_api_key")

            # Upload customers via CSV
            result = client.customers.upload_csv("/path/to/customers.csv")

            print(f"Total customers: {result['data']['total_customers']}")
            print(f"Successful: {result['data']['successful_upload_count']}")
            print(f"Failed: {result['data']['failed_upload_count']}")

            # Handle failed uploads
            if result['data']['failed_upload_count'] > 0:
                for failure in result['data']['customers_failed']:
                    print(f"Row {failure['row']}: {failure['errors']}")
        - lang: javascript
          label: Javascript SDK
          source: |
            import { init } from "metrifox-js";

            const metrifoxClient = init({
              apiKey: process.env.METRIFOX_API_KEY
            });

            // Example: File input handler
            const handleFileUpload = async (event) => {
              const file = event.target.files[0];
              if (file && file.type === 'text/csv') {
                await metrifoxClient.customers.uploadCsv(file);
              } else {
                alert('Please select a valid CSV file');
              }
            };
        - lang: ruby
          label: Ruby SDK
          source: >
            require 'metrifox-sdk'


            # Initialize with configuration

            METRIFOX_SDK = MetrifoxSDK.init({ api_key: "your-api-key" })


            # Upload customers via CSV

            response =
            METRIFOX_SDK.customers.upload_csv("/path/to/customers.csv")


            puts response["data"]["total_customers"]

            puts response["data"]["successful_upload_count"]
components:
  schemas:
    CustomerCsvRequest:
      type: object
      properties:
        file:
          type: string
          format: binary
          description: CSV file containing customer data
      required:
        - file
    CustomerCSVResponse:
      type: object
      properties:
        total_customers:
          type: integer
          description: Total number of customers in the CSV file
        successful_upload_count:
          type: integer
          description: Number of customers successfully created
        failed_upload_count:
          type: integer
          description: Number of customers that failed to be created
        customers_added:
          type: array
          items:
            type: object
            additionalProperties: true
          description: Array of successfully created customers
        customers_failed:
          type: array
          items:
            type: object
            properties:
              row:
                type: integer
                description: Row number in the CSV file
              customer_key:
                type: string
                description: Customer key that failed
              errors:
                type: array
                items:
                  type: string
                description: List of validation errors for this row
          description: Array of customers that failed to be created with error details
      required:
        - total_customers
        - successful_upload_count
        - failed_upload_count
        - customers_added
        - customers_failed
    ErrorResponse:
      type: object
      properties:
        message:
          type: string
          description: Error message
        errors:
          type: object
          additionalProperties: true
          description: Detailed error information
  securitySchemes:
    api_key:
      type: apiKey
      name: x-api-key
      in: header

````