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

# Get ads hierarchy

> Get complete campaign/ad set/ad hierarchy in one optimized request. Use `datePreset=maximum` to pull lifetime insights for paused/historical campaigns (the `last_30d` default returns null insights for entities with no recent spend).



## OpenAPI

````yaml https://api.sapt.ai/openapi.json get /socials/ads/hierarchy/{projectId}/{accountId}/{adAccountId}
openapi: 3.1.0
info:
  title: Sapt Platform API
  version: 1.0.0
  description: >-
    API for Sapt platform - project management, authentication, and email
    services
servers:
  - url: https://api.sapt.ai
    description: Production
  - url: http://localhost:8787
    description: Local development
security: []
tags:
  - name: Accounts
    description: >-
      The social accounts connected to a project. Start here — the `id` of an
      account is the `socialAccountId` that every posting, scheduling and
      analytics call takes.
  - name: Actions
  - name: Ads
  - name: Agents
  - name: Analytics
    description: >-
      Account- and post-level organic performance for connected Instagram and
      Facebook accounts.
  - name: Assets
  - name: Auth
  - name: CMS
  - name: CRM
  - name: Calendar
  - name: Comments
    description: >-
      Read, reply to, hide and delete comments on published Instagram and
      Facebook posts.
  - name: Content Calendar
    description: >-
      Create, schedule, update and publish organic posts, and stage the media
      they carry. Publishing a post whose status is `failed` retries it.
  - name: Contracts
  - name: Conversions
    description: >-
      Meta server-side Conversions API (CAPI): discover pixels, connect a pixel
      + CAPI token, and send deduped server-side conversions.
  - name: Dashboard Sidebar
  - name: Emails
  - name: Engagement
    description: >-
      Act as the Page or account on published posts: comment, like, unlike, and
      delete a published post.
  - name: Geo
  - name: Google Ads
  - name: Google Analytics
  - name: Google Business
  - name: Integrations
    description: >-
      Connect third-party providers (Meta, Gmail, Google Business Profile, …).
      List providers, mint OAuth connect links, and poll connection status.
  - name: Invitations
  - name: Memory
  - name: OAuth Clients
  - name: Project Roles
  - name: Project Templates
  - name: Projects
  - name: Schedules
  - name: Service Accounts
  - name: Socials
    description: >-
      Organic social: the connected accounts, the content calendar, media
      staging, publishing, comments and engagement across Instagram, Facebook,
      TikTok, YouTube and Google Business Profile.
  - name: Team
  - name: Users
  - name: Web Analytics
  - name: Workflows
paths:
  /socials/ads/hierarchy/{projectId}/{accountId}/{adAccountId}:
    get:
      tags:
        - Ads
      summary: Get ads hierarchy
      description: >-
        Get complete campaign/ad set/ad hierarchy in one optimized request. Use
        `datePreset=maximum` to pull lifetime insights for paused/historical
        campaigns (the `last_30d` default returns null insights for entities
        with no recent spend).
      operationId: getAdsHierarchy
      parameters:
        - schema:
            type: string
            format: uuid
          required: true
          name: projectId
          in: path
        - schema:
            type: string
            format: uuid
          required: true
          name: accountId
          in: path
        - schema:
            type: string
          required: true
          name: adAccountId
          in: path
        - schema:
            type: string
            enum:
              - today
              - yesterday
              - last_3d
              - last_7d
              - last_14d
              - last_28d
              - last_30d
              - last_90d
              - this_month
              - last_month
              - this_quarter
              - last_quarter
              - this_year
              - last_year
              - maximum
          required: false
          name: datePreset
          in: query
      responses:
        '200':
          description: Hierarchy fetched
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  data:
                    type: object
                    properties:
                      campaigns:
                        type: array
                        items:
                          type: object
                          properties:
                            id:
                              type: string
                            name:
                              type: string
                            status:
                              type: string
                            effectiveStatus:
                              type: string
                            objective:
                              type: string
                            dailyBudget:
                              type:
                                - string
                                - 'null'
                            lifetimeBudget:
                              type:
                                - string
                                - 'null'
                            adSets:
                              type: array
                              items:
                                type: object
                                properties:
                                  id:
                                    type: string
                                  name:
                                    type: string
                                  status:
                                    type: string
                                  effectiveStatus:
                                    type: string
                                  destinationType:
                                    type:
                                      - string
                                      - 'null'
                                  dailyBudget:
                                    type:
                                      - string
                                      - 'null'
                                  lifetimeBudget:
                                    type:
                                      - string
                                      - 'null'
                                  optimizationGoal:
                                    type: string
                                  billingEvent:
                                    type: string
                                  startTime:
                                    type:
                                      - string
                                      - 'null'
                                  endTime:
                                    type:
                                      - string
                                      - 'null'
                                  ads:
                                    type: array
                                    items:
                                      type: object
                                      properties:
                                        id:
                                          type: string
                                        name:
                                          type: string
                                        status:
                                          type: string
                                        effectiveStatus:
                                          type: string
                                        creative:
                                          type:
                                            - object
                                            - 'null'
                                          properties:
                                            id:
                                              type: string
                                            imageUrl:
                                              type:
                                                - string
                                                - 'null'
                                            thumbnailUrl:
                                              type:
                                                - string
                                                - 'null'
                                            message:
                                              type:
                                                - string
                                                - 'null'
                                            linkUrl:
                                              type:
                                                - string
                                                - 'null'
                                            videoId:
                                              type:
                                                - string
                                                - 'null'
                                            headline:
                                              type:
                                                - string
                                                - 'null'
                                            description:
                                              type:
                                                - string
                                                - 'null'
                                            messageOptions:
                                              type: array
                                              items:
                                                type: string
                                            headlineOptions:
                                              type: array
                                              items:
                                                type: string
                                            descriptionOptions:
                                              type: array
                                              items:
                                                type: string
                                            callToActionType:
                                              type:
                                                - string
                                                - 'null'
                                            leadForm:
                                              type:
                                                - object
                                                - 'null'
                                              properties:
                                                id:
                                                  type: string
                                                name:
                                                  type:
                                                    - string
                                                    - 'null'
                                              required:
                                                - id
                                                - name
                                          required:
                                            - id
                                            - imageUrl
                                            - thumbnailUrl
                                            - message
                                            - linkUrl
                                            - videoId
                                            - headline
                                            - description
                                            - callToActionType
                                            - leadForm
                                        insights:
                                          type:
                                            - object
                                            - 'null'
                                          properties:
                                            impressions:
                                              type: string
                                            reach:
                                              type: string
                                            clicks:
                                              type: string
                                            spend:
                                              type: string
                                            ctr:
                                              type:
                                                - string
                                                - 'null'
                                            cpc:
                                              type:
                                                - string
                                                - 'null'
                                            cpm:
                                              type:
                                                - string
                                                - 'null'
                                            frequency:
                                              type:
                                                - string
                                                - 'null'
                                          required:
                                            - impressions
                                            - reach
                                            - clicks
                                            - spend
                                            - ctr
                                            - cpc
                                            - cpm
                                            - frequency
                                      required:
                                        - id
                                        - name
                                        - status
                                        - effectiveStatus
                                        - creative
                                        - insights
                                  insights:
                                    type:
                                      - object
                                      - 'null'
                                    properties:
                                      impressions:
                                        type: string
                                      reach:
                                        type: string
                                      clicks:
                                        type: string
                                      spend:
                                        type: string
                                      ctr:
                                        type:
                                          - string
                                          - 'null'
                                      cpc:
                                        type:
                                          - string
                                          - 'null'
                                      cpm:
                                        type:
                                          - string
                                          - 'null'
                                      frequency:
                                        type:
                                          - string
                                          - 'null'
                                    required:
                                      - impressions
                                      - reach
                                      - clicks
                                      - spend
                                      - ctr
                                      - cpc
                                      - cpm
                                      - frequency
                                  targeting:
                                    type:
                                      - object
                                      - 'null'
                                    properties:
                                      geoLocations:
                                        type: object
                                        properties:
                                          countries:
                                            type: array
                                            items:
                                              type: string
                                          cities:
                                            type: array
                                            items:
                                              type: object
                                              properties:
                                                key:
                                                  type: string
                                                radius:
                                                  type: number
                                                distance_unit:
                                                  type: string
                                              required:
                                                - key
                                          regions:
                                            type: array
                                            items:
                                              type: object
                                              properties:
                                                key:
                                                  type: string
                                              required:
                                                - key
                                      ageMin:
                                        type: number
                                      ageMax:
                                        type: number
                                      genders:
                                        type: array
                                        items:
                                          type: number
                                      interests:
                                        type: array
                                        items:
                                          type: object
                                          properties:
                                            id:
                                              type: string
                                            name:
                                              type: string
                                          required:
                                            - id
                                      behaviors:
                                        type: array
                                        items:
                                          type: object
                                          properties:
                                            id:
                                              type: string
                                            name:
                                              type: string
                                          required:
                                            - id
                                      customAudiences:
                                        type: array
                                        items:
                                          type: object
                                          properties:
                                            id:
                                              type: string
                                          required:
                                            - id
                                      excludedCustomAudiences:
                                        type: array
                                        items:
                                          type: object
                                          properties:
                                            id:
                                              type: string
                                          required:
                                            - id
                                required:
                                  - id
                                  - name
                                  - status
                                  - effectiveStatus
                                  - destinationType
                                  - dailyBudget
                                  - lifetimeBudget
                                  - optimizationGoal
                                  - billingEvent
                                  - startTime
                                  - endTime
                                  - ads
                                  - insights
                                  - targeting
                            insights:
                              type:
                                - object
                                - 'null'
                              properties:
                                impressions:
                                  type: string
                                reach:
                                  type: string
                                clicks:
                                  type: string
                                spend:
                                  type: string
                                ctr:
                                  type:
                                    - string
                                    - 'null'
                                cpc:
                                  type:
                                    - string
                                    - 'null'
                                cpm:
                                  type:
                                    - string
                                    - 'null'
                                frequency:
                                  type:
                                    - string
                                    - 'null'
                              required:
                                - impressions
                                - reach
                                - clicks
                                - spend
                                - ctr
                                - cpc
                                - cpm
                                - frequency
                          required:
                            - id
                            - name
                            - status
                            - effectiveStatus
                            - objective
                            - dailyBudget
                            - lifetimeBudget
                            - adSets
                            - insights
                    required:
                      - campaigns
                required:
                  - success
                  - data
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: Error message
                  code:
                    type: string
                    description: Error code for programmatic handling
                required:
                  - message
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: Error message
                  code:
                    type: string
                    description: Error code for programmatic handling
                required:
                  - message
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: Error message
                  code:
                    type: string
                    description: Error code for programmatic handling
                required:
                  - message
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: Error message
                  code:
                    type: string
                    description: Error code for programmatic handling
                required:
                  - message
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: Error message
                  code:
                    type: string
                    description: Error code for programmatic handling
                required:
                  - message
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        JWT token obtained from /api/auth/token endpoint. Token is verified
        using JWKS and must include a valid user identifier.

````