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

# Set Post-Call Outcome

> Set custom call outcome fields for a call using the public frontend API.

## Overview

This API allows you to set post call outcome fields for calls by either:

1. **Call ID:** `PATCH /api/calls/{agent_id}/{call_id}`
2. **Phone Number:** `PATCH /api/calls/{agent_id}/{e164_number}?preference=first|last`

## Authentication

* **API Key**: `X-Authorization` header (for batch jobs)

## Example 1: Update by Call ID

### Using API Key

```bash theme={null}
curl -X PATCH "https://app.phonely.ai/api/calls/agent123/call456" \
  -H "X-Authorization: your-api-key-here" \
  -H "Content-Type: application/json" \
  -d '{
    "custom_call_outcome": "Sold",
    "custom_call_outcome_value": 299,
    "custom_call_metadata": {
      "campaign": "spring_2026",
      "rep_id": "12345",
      "notes": "Customer was very interested"
    }
  }'
```

## Example 2: Update by Phone Number (Last Touch - Default)

```bash theme={null}
curl -X PATCH "https://app.phonely.ai/api/calls/agent123/+14155551234" \
  -H "X-Authorization: your-api-key-here" \
  -H "Content-Type: application/json" \
  -d '{
    "custom_call_outcome": "No Sale",
    "custom_call_outcome_value": 0,
    "custom_call_metadata": {
      "reason": "Price too high",
      "follow_up": true
    }
  }'
```

## Example 3: Update by Phone Number (First Touch)

```bash theme={null}
curl -X PATCH "https://app.phonely.ai/api/calls/agent123/+14155551234?preference=first" \
  -H "X-Authorization: your-api-key-here" \
  -H "Content-Type: application/json" \
  -d '{
    "custom_call_outcome": "Sold",
    "custom_call_outcome_value": 499,
    "custom_call_metadata": {
      "attribution": "first_touch",
      "campaign": "spring_2026"
    }
  }'
```

## Example 4: Partial Update (Only Outcome)

```bash theme={null}
curl -X PATCH "https://app.phonely.ai/api/calls/agent123/call456" \
  -H "X-Authorization: your-api-key-here" \
  -H "Content-Type: application/json" \
  -d '{
    "custom_call_outcome": "Follow Up Required"
  }'
```

## Notes

1. **Phone Number Format**: Phone numbers must be in E.164 format (e.g., `+14155551234`). The `+` sign can be included directly in the URL path.
2. **Preference Parameter**:
   * `first`: Updates the earliest call with the given phone number
   * `last`: Updates the most recent call (default)
3. **Partial Updates**: You can provide any combination of the three fields:
   * `custom_call_outcome` (string)
   * `custom_call_outcome_value` (number)
   * `custom_call_metadata` (object)


## OpenAPI

````yaml PATCH /calls/{agentId}/{callIdOrPhone}
openapi: 3.0.1
info:
  title: Phonely API
  description: API for Phonely services including agent management and call summaries
  version: 1.0.0
servers:
  - url: https://app.phonely.ai/api
security: []
paths:
  /calls/{agentId}/{callIdOrPhone}:
    patch:
      summary: Set post call outcome
      description: >-
        Set post call outcome fields for a call identified by either call ID or
        phone number.
      parameters:
        - name: agentId
          in: path
          required: true
          schema:
            type: string
          description: The ID of the agent
        - name: callIdOrPhone
          in: path
          required: true
          schema:
            type: string
          description: The ID of the call or the E.164 phone number
        - name: preference
          in: query
          required: false
          schema:
            type: string
            enum:
              - first
              - last
            default: last
          description: >-
            first: first time that someone called in, last: latest call from
            someone
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateCallOutcomeRequest'
      responses:
        '200':
          description: Call outcome updated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UpdateCallOutcomeResponse'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    UpdateCallOutcomeRequest:
      type: object
      properties:
        custom_call_outcome:
          type: string
          description: The outcome label (e.g., Sold, No Sale)
        custom_call_outcome_value:
          type: number
          description: The monetary value associated with the outcome
        custom_call_metadata:
          type: object
          description: Additional custom metadata for the call
    UpdateCallOutcomeResponse:
      type: object
      properties:
        success:
          type: boolean
        call_id:
          type: string
        agent_id:
          type: string
        phone:
          type: string
        preference:
          type: string
        updated_fields:
          type: array
          items:
            type: string
    Error:
      type: object
      properties:
        error:
          type: string
          description: Error code or identifier
        message:
          type: string
          description: Detailed error message
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-Authorization

````