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

# List contacts

> List all contacts in an audience with cursor-based pagination. The account is inferred from the audience.



## OpenAPI

````yaml GET /audiences/{audience_id}/contacts
openapi: 3.1.1
info:
  title: Surge
  version: '1.0'
servers:
  - url: https://api.surge.app
security:
  - authorization: []
paths:
  /audiences/{audience_id}/contacts:
    get:
      tags:
        - Audiences
      summary: List audience contacts
      description: >-
        List all contacts in an audience with cursor-based pagination. The
        account is inferred from the audience.
      operationId: ListAudienceContacts
      parameters:
        - in: path
          name: audience_id
          required: true
          schema:
            description: The audience ID to list contacts for.
            example: aud_01j9a43avnfqzbjfch6pygv1td
            type: string
        - in: query
          name: after
          required: false
          schema:
            description: >-
              Cursor for forward pagination. Use the next_cursor from a previous
              response.
            type: string
        - in: query
          name: before
          required: false
          schema:
            description: >-
              Cursor for backward pagination. Use the previous_cursor from a
              previous response.
            type: string
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContactList'
          description: List of contacts
        default:
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Error
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import Surge from '@surgeapi/node';


            const client = new Surge({
              apiKey: process.env['SURGE_API_KEY'], // This is the default and can be omitted
            });


            // Automatically fetches more pages as needed.

            for await (const contact of
            client.audiences.listContacts('aud_01j9a43avnfqzbjfch6pygv1td')) {
              console.log(contact.id);
            }
        - lang: Python
          source: |-
            import os
            from surge import Surge

            client = Surge(
                api_key=os.environ.get("SURGE_API_KEY"),  # This is the default and can be omitted
            )
            page = client.audiences.list_contacts(
                audience_id="aud_01j9a43avnfqzbjfch6pygv1td",
            )
            page = page.data[0]
            print(page.id)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/stainless-sdks/surge-go\"\n\t\"github.com/stainless-sdks/surge-go/option\"\n)\n\nfunc main() {\n\tclient := surge.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tpage, err := client.Audiences.ListContacts(\n\t\tcontext.TODO(),\n\t\t\"aud_01j9a43avnfqzbjfch6pygv1td\",\n\t\tsurge.AudienceListContactsParams{},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", page)\n}\n"
        - lang: Ruby
          source: >-
            require "surge_api"


            surge = SurgeAPI::Client.new(api_key: "My API Key")


            page =
            surge.audiences.list_contacts("aud_01j9a43avnfqzbjfch6pygv1td")


            puts(page)
        - lang: PHP
          source: >-
            <?php


            require_once dirname(__DIR__) . '/vendor/autoload.php';


            use Surge\Client;

            use Surge\Core\Exceptions\APIException;


            $client = new Client(apiKey: getenv('SURGE_API_KEY') ?: 'My API
            Key');


            try {
              $page = $client->audiences->listContacts(
                'aud_01j9a43avnfqzbjfch6pygv1td', after: 'after', before: 'before'
              );

              var_dump($page);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
components:
  schemas:
    ContactList:
      description: A paginated list of contacts
      example:
        data:
          - email: dom@toretto.family
            first_name: Dominic
            id: ctc_01j9dy8mdzfn3r0e8x1tbdrdrf
            last_name: Toretto
            metadata:
              car: 1970 Dodge Charger R/T
            phone_number: '+18015551234'
        pagination:
          next_cursor: null
          previous_cursor: null
      properties:
        data:
          description: The list of contacts
          items:
            $ref: '#/components/schemas/Contact'
          type: array
        pagination:
          $ref: '#/components/schemas/Pagination'
      required:
        - data
        - pagination
      title: ContactList
      type: object
    ErrorResponse:
      description: An error response
      example:
        error:
          message: The requested resource could not be found.
          type: not_found
      properties:
        error:
          $ref: '#/components/schemas/Error'
      required:
        - error
      title: ErrorResponse
      type: object
    Contact:
      description: A contact who has consented to receive messages
      example:
        email: dom@toretto.family
        first_name: Dominic
        id: ctc_01j9dy8mdzfn3r0e8x1tbdrdrf
        last_name: Toretto
        metadata:
          car: 1970 Dodge Charger R/T
        phone_number: '+18015551234'
      properties:
        email:
          description: The contact's email address.
          format: email
          type: string
        first_name:
          description: The contact's first name.
          type: string
        id:
          description: Unique identifier for the object.
          type: string
        last_name:
          description: The contact's last name.
          type: string
        metadata:
          $ref: '#/components/schemas/Metadata'
        phone_number:
          description: The contact's phone number in E.164 format.
          example: '+18015551234'
          format: phone-number
          pattern: ^\+[1-9]\d{6,14}$
          type: string
      required:
        - id
        - phone_number
      title: Contact
      type: object
    Pagination:
      description: Cursor-based pagination information
      example:
        next_cursor: g3QAAAABZAACaWRtAAAAGnBuXzAxamtzY2s5eDdkeW0wZnBxZjdjYmRyeQ==
        previous_cursor: null
      properties:
        next_cursor:
          description: Cursor for the next page of results. Null if there is no next page.
          type:
            - string
            - 'null'
        previous_cursor:
          description: >-
            Cursor for the previous page of results. Null if there is no
            previous page.
          type:
            - string
            - 'null'
      title: Pagination
      type: object
    Error:
      description: An error response
      example:
        message: The requested resource was not found.
        type: not_found
      properties:
        detail:
          additionalProperties: true
          description: Additional details about the error.
          type: object
        message:
          description: A human-readable error message.
          example: The requested resource was not found.
          type: string
        type:
          description: A unique error code.
          example: not_found
          type: string
      required:
        - type
        - message
      title: Error
      type: object
    Metadata:
      additionalProperties:
        maxLength: 500
        type: string
      description: Set of key-value pairs that will be stored with the object.
      maxProperties: 50
      properties: {}
      title: Metadata
      type: object
  securitySchemes:
    authorization:
      bearerFormat: Surge API token
      scheme: bearer
      type: http

````