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

# Create or update contact

> Create a new contact or update existing (upsert by email)



## OpenAPI

````yaml openapi.json POST /contacts
openapi: 3.0.3
info:
  title: MailGlyph API
  description: >-
    Email platform API for transactional emails, campaigns, and marketing
    automation
  version: 1.0.0
  contact:
    name: MailGlyph Support
    url: https://mailglyph.com
servers:
  - url: https://api.mailglyph.com
    description: Production server
security:
  - ApiKeyAuth: []
tags:
  - name: Public API
    description: Public API endpoints for sending emails and tracking events
  - name: Events
    description: Event ingestion and querying
  - name: Contacts
    description: Contact management operations
  - name: Templates
    description: Email template management
  - name: Campaigns
    description: Email campaign management
  - name: Segments
    description: Audience segmentation
  - name: Workflows
    description: Workflow automation
paths:
  /contacts:
    post:
      tags:
        - Contacts
      summary: Create or update contact
      description: Create a new contact or update existing (upsert by email)
      operationId: createContact
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - email
              properties:
                email:
                  type: string
                  format: email
                subscribed:
                  type: boolean
                  default: true
                data:
                  description: >-
                    Optional custom contact data fields. Choose `Empty object`
                    if you do not want to send any example preset keys.
                  oneOf:
                    - type: object
                      title: Example object
                      description: >-
                        Optional common keys. You can still add additional
                        custom key/value pairs.
                      properties:
                        firstName:
                          type: string
                          description: Contact first name
                          example: John
                        lastName:
                          type: string
                          description: Contact last name
                          example: Doe
                        plan:
                          type: string
                          description: Plan or customer segment label
                          example: premium
                      example:
                        firstName: John
                        lastName: Doe
                        plan: premium
                      additionalProperties: true
                    - type: object
                      title: Empty object
                      description: >-
                        No preset keys. Add any custom key/value pairs as
                        needed.
                      additionalProperties: true
            examples:
              Contact with custom data:
                summary: Contact with custom data
                value:
                  email: user@example.com
                  subscribed: true
                  data:
                    firstName: John
                    lastName: Doe
                    plan: premium
              Simple contact:
                summary: Simple contact
                value:
                  email: user@example.com
                  subscribed: true
      responses:
        '200':
          description: Contact updated
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Contact'
                  - type: object
                    properties:
                      _meta:
                        type: object
                        properties:
                          isNew:
                            type: boolean
                          isUpdate:
                            type: boolean
        '201':
          description: Contact created
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Contact'
                  - type: object
                    properties:
                      _meta:
                        type: object
                        properties:
                          isNew:
                            type: boolean
                          isUpdate:
                            type: boolean
components:
  schemas:
    Contact:
      type: object
      properties:
        id:
          type: string
          description: Unique contact identifier
        email:
          type: string
          format: email
          description: Contact email address
        subscribed:
          type: boolean
          description: Subscription status
        data:
          type: object
          description: Custom contact data fields
          nullable: true
          additionalProperties: true
        status:
          type: string
          enum:
            - ACTIVE
            - PENDING
        expiresAt:
          type: string
          format: date-time
          nullable: true
        projectId:
          type: string
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: >-
        API Key authentication. **Secret keys (sk_*)** are required for all
        endpoints except `/v1/track`. **Public keys (pk_*)** only work with the
        `/v1/track` endpoint for client-side event tracking. Workspaces can have
        multiple active keys, and sender-domain operations enforce per-key
        domain scope when configured.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.