Ahrefs GSC Insights API

Fetch data from GSC Insights reports

Operations 12

GET /gsc/performance-history Performance history #
GET /gsc/positions-history Positions history #
GET /gsc/pages-history Pages history #
GET /gsc/performance-by-device Performance by device #
GET /gsc/metrics-by-country Metrics by country #
GET /gsc/ctr-by-position CTR by position #
GET /gsc/performance-by-position Performance by position #
GET /gsc/keyword-history Keyword history #
GET /gsc/keywords Keywords #
GET /gsc/page-history Page history #
GET /gsc/pages Pages #
GET /gsc/anonymous-queries Anonymous queries #

Work with this as data

Every API here is available over the APIs.io API and to AI agents over MCP.

MCP server

One button, every client — Claude, Cursor, VS Code and the rest.

https://apis.io/mcp

Tools for apis

7 MCP tools reach this
  • find_apisBrowse and filter every API in the catalog.
  • get_api_artifactsOne API's artifacts, grouped by type.
  • get_openapiThe primary OpenAPI for this API.
  • find_similar_apisAPIs that look like this one.
  • apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.
  • resolveTurn a domain, URL or GitHub org into the provider it belongs to.
  • find_cohortsEvery scored population of providers in the catalog.
All 92 tools →

Call it yourself

curl for this page
This API
curl "https://apis.io/api/v1/apis/ahrefs-gsc-insights-api"
All apis
curl "https://apis.io/api/v1/apis?limit=25"

Discovery needs no key. Ratings and market analysis are Pro.

Get an API key

Free tier, no email required.

A second provider on the same verified email joins the account you already have.

OpenAPI Specification

ahrefs-gsc-insights-api-openapi.yml Raw ↑
openapi: 3.2.0
info:
  title: Ahrefs GSC Insights API
  description: Ahrefs API v3 gives programmatic access to Ahrefs' SEO, marketing, and AI-search data — backlinks, organic and paid traffic, keywords, SERPs, rank tracking, site audits, brand/AI-search visibility, web and social analytics, and account management. This is the full spec for every tool; each tool also has its own spec under /reference/.
  termsOfService: https://ahrefs.com/terms
  contact:
    name: Ahrefs
    url: https://ahrefs.com/
    email: support@ahrefs.com
  version: 3.0.0
servers:
- url: https://api.ahrefs.com/v3
  description: Ahrefs API v3
security:
- http:
  - read
tags:
- name: GSC Insights
  description: Fetch data from GSC Insights reports
paths:
  /gsc/performance-history:
    get:
      tags:
      - GSC Insights
      summary: Performance history
      description: '>Requests to this endpoint are free and do not consume any API units.'
      operationId: gsc.performance-history
      parameters:
      - description: Project ID. Required when portfolio_id is not provided.
        required: false
        explode: false
        schema:
          type: integer
        name: project_id
        in: query
      - description: Portfolio ID. When provided, aggregates data across all GSC-connected projects in the portfolio.
        required: false
        explode: false
        schema:
          type: integer
        name: portfolio_id
        in: query
      - description: The start date of the historical period in YYYY-MM-DD format.
        required: true
        explode: false
        schema:
          type: string
          format: date
        name: date_from
        in: query
      - description: The end date of the historical period in YYYY-MM-DD format.
        required: false
        explode: false
        schema:
          type: string
          format: date
        name: date_to
        in: query
      - description: The time interval used to group historical data.
        required: false
        explode: false
        schema:
          type: string
          enum:
          - daily
          - weekly
          - monthly
          default: monthly
        name: history_grouping
        in: query
      - description: The type of search results to return (web, image, video, news).
        required: false
        explode: false
        schema:
          type: string
          enum:
          - web
          - image
          - video
          - news
          default: web
        name: search_type
        in: query
      - description: A two-letter country code (ISO 3166-1 alpha-2).
        required: false
        explode: false
        schema:
          type: string
          enum:
          - ad
          - ae
          - af
          - ag
          - ai
          - al
          - am
          - ao
          - ar
          - as
          - at
          - au
          - aw
          - az
          - ba
          - bb
          - bd
          - be
          - bf
          - bg
          - bh
          - bi
          - bj
          - bn
          - bo
          - br
          - bs
          - bt
          - bw
          - by
          - bz
          - ca
          - cd
          - cf
          - cg
          - ch
          - ci
          - ck
          - cl
          - cm
          - cn
          - co
          - cr
          - cu
          - cv
          - cy
          - cz
          - de
          - dj
          - dk
          - dm
          - do
          - dz
          - ec
          - ee
          - eg
          - es
          - et
          - fi
          - fj
          - fm
          - fo
          - fr
          - ga
          - gb
          - gd
          - ge
          - gf
          - gg
          - gh
          - gi
          - gl
          - gm
          - gn
          - gp
          - gq
          - gr
          - gt
          - gu
          - gy
          - hk
          - hn
          - hr
          - ht
          - hu
          - id
          - ie
          - il
          - im
          - in
          - iq
          - is
          - it
          - je
          - jm
          - jo
          - jp
          - ke
          - kg
          - kh
          - ki
          - kn
          - kr
          - kw
          - ky
          - kz
          - la
          - lb
          - lc
          - li
          - lk
          - ls
          - lt
          - lu
          - lv
          - ly
          - ma
          - mc
          - md
          - me
          - mg
          - mk
          - ml
          - mm
          - mn
          - mq
          - mr
          - ms
          - mt
          - mu
          - mv
          - mw
          - mx
          - my
          - mz
          - na
          - nc
          - ne
          - ng
          - ni
          - nl
          - 'no'
          - np
          - nr
          - nu
          - nz
          - om
          - pa
          - pe
          - pf
          - pg
          - ph
          - pk
          - pl
          - pn
          - pr
          - ps
          - pt
          - py
          - qa
          - re
          - ro
          - rs
          - ru
          - rw
          - sa
          - sb
          - sc
          - se
          - sg
          - sh
          - si
          - sk
          - sl
          - sm
          - sn
          - so
          - sr
          - st
          - sv
          - td
          - tg
          - th
          - tj
          - tk
          - tl
          - tm
          - tn
          - to
          - tr
          - tt
          - tw
          - tz
          - ua
          - ug
          - us
          - uy
          - uz
          - vc
          - ve
          - vg
          - vi
          - vn
          - vu
          - ws
          - ye
          - yt
          - za
          - zm
          - zw
        name: country
        in: query
      - description: Filter by device type (DESKTOP, MOBILE, TABLET). If not specified, all devices are included.
        required: false
        explode: false
        schema:
          type: string
          enum:
          - desktop
          - mobile
          - tablet
        name: device
        in: query
      - description: "Supported fields:\n- url\n\nFilter is a JSON string that represents a boolean expression, it should follow the following structure:\n```\n<bool_filter> ::= { \"and\" : <bool_filter>+ }\n              |   { \"or\" : <bool_filter>+ }\n              |   { \"not\" : <bool_filter> }\n              |   <expr>\n\n<expr> ::= {\n             \"field\" : <dimension|metric>,\n             ? \"is\": <condition>,\n           }\n\n<condition> ::= [ \"eq\", <value> ]\n            |   [ \"neq\", <value> ]\n            |   [ \"gt\", <value> ]\n            |   [ \"gte\", <value> ]\n            |   [ \"lt\", <value> ]\n            |   [ \"lte\", <value> ]\n            |   [ \"substring\", <value> ]\n            |   [ \"isubstring\", <value> ]\n            |   [ \"phrase_match\", <value> ]\n            |   [ \"iphrase_match\", <value> ]\n            |   [ \"prefix\", <value> ]\n            |   [ \"suffix\", <value> ]\n```"
        required: false
        explode: false
        schema:
          type: string
        name: where
        in: query
      - $ref: '#/components/parameters/gsc.output'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/gsc.performance-history'
            application/xml:
              schema:
                $ref: '#/components/schemas/gsc.performance-history'
        '400':
          $ref: '#/components/responses/gsc.error_400'
        '401':
          $ref: '#/components/responses/gsc.error_401'
        '403':
          $ref: '#/components/responses/gsc.error_403'
        '429':
          $ref: '#/components/responses/gsc.error_429'
        '500':
          $ref: '#/components/responses/gsc.error_500'
  /gsc/positions-history:
    get:
      tags:
      - GSC Insights
      summary: Positions history
      description: '>Requests to this endpoint are free and do not consume any API units.'
      operationId: gsc.positions-history
      parameters:
      - description: Project ID. Required when portfolio_id is not provided.
        required: false
        explode: false
        schema:
          type: integer
        name: project_id
        in: query
      - description: Portfolio ID. When provided, aggregates data across all GSC-connected projects in the portfolio.
        required: false
        explode: false
        schema:
          type: integer
        name: portfolio_id
        in: query
      - description: The start date of the historical period in YYYY-MM-DD format.
        required: true
        explode: false
        schema:
          type: string
          format: date
        name: date_from
        in: query
      - description: The end date of the historical period in YYYY-MM-DD format.
        required: false
        explode: false
        schema:
          type: string
          format: date
        name: date_to
        in: query
      - description: The time interval used to group historical data.
        required: false
        explode: false
        schema:
          type: string
          enum:
          - daily
          - weekly
          - monthly
          default: monthly
        name: history_grouping
        in: query
      - description: The type of search results to return (web, image, video, news).
        required: false
        explode: false
        schema:
          type: string
          enum:
          - web
          - image
          - video
          - news
          default: web
        name: search_type
        in: query
      - description: A two-letter country code (ISO 3166-1 alpha-2).
        required: false
        explode: false
        schema:
          type: string
          enum:
          - ad
          - ae
          - af
          - ag
          - ai
          - al
          - am
          - ao
          - ar
          - as
          - at
          - au
          - aw
          - az
          - ba
          - bb
          - bd
          - be
          - bf
          - bg
          - bh
          - bi
          - bj
          - bn
          - bo
          - br
          - bs
          - bt
          - bw
          - by
          - bz
          - ca
          - cd
          - cf
          - cg
          - ch
          - ci
          - ck
          - cl
          - cm
          - cn
          - co
          - cr
          - cu
          - cv
          - cy
          - cz
          - de
          - dj
          - dk
          - dm
          - do
          - dz
          - ec
          - ee
          - eg
          - es
          - et
          - fi
          - fj
          - fm
          - fo
          - fr
          - ga
          - gb
          - gd
          - ge
          - gf
          - gg
          - gh
          - gi
          - gl
          - gm
          - gn
          - gp
          - gq
          - gr
          - gt
          - gu
          - gy
          - hk
          - hn
          - hr
          - ht
          - hu
          - id
          - ie
          - il
          - im
          - in
          - iq
          - is
          - it
          - je
          - jm
          - jo
          - jp
          - ke
          - kg
          - kh
          - ki
          - kn
          - kr
          - kw
          - ky
          - kz
          - la
          - lb
          - lc
          - li
          - lk
          - ls
          - lt
          - lu
          - lv
          - ly
          - ma
          - mc
          - md
          - me
          - mg
          - mk
          - ml
          - mm
          - mn
          - mq
          - mr
          - ms
          - mt
          - mu
          - mv
          - mw
          - mx
          - my
          - mz
          - na
          - nc
          - ne
          - ng
          - ni
          - nl
          - 'no'
          - np
          - nr
          - nu
          - nz
          - om
          - pa
          - pe
          - pf
          - pg
          - ph
          - pk
          - pl
          - pn
          - pr
          - ps
          - pt
          - py
          - qa
          - re
          - ro
          - rs
          - ru
          - rw
          - sa
          - sb
          - sc
          - se
          - sg
          - sh
          - si
          - sk
          - sl
          - sm
          - sn
          - so
          - sr
          - st
          - sv
          - td
          - tg
          - th
          - tj
          - tk
          - tl
          - tm
          - tn
          - to
          - tr
          - tt
          - tw
          - tz
          - ua
          - ug
          - us
          - uy
          - uz
          - vc
          - ve
          - vg
          - vi
          - vn
          - vu
          - ws
          - ye
          - yt
          - za
          - zm
          - zw
        name: country
        in: query
      - description: Filter by device type (DESKTOP, MOBILE, TABLET). If not specified, all devices are included.
        required: false
        explode: false
        schema:
          type: string
          enum:
          - desktop
          - mobile
          - tablet
        name: device
        in: query
      - description: "Supported fields:\n- url\n\nFilter is a JSON string that represents a boolean expression, it should follow the following structure:\n```\n<bool_filter> ::= { \"and\" : <bool_filter>+ }\n              |   { \"or\" : <bool_filter>+ }\n              |   { \"not\" : <bool_filter> }\n              |   <expr>\n\n<expr> ::= {\n             \"field\" : <dimension|metric>,\n             ? \"is\": <condition>,\n           }\n\n<condition> ::= [ \"eq\", <value> ]\n            |   [ \"neq\", <value> ]\n            |   [ \"gt\", <value> ]\n            |   [ \"gte\", <value> ]\n            |   [ \"lt\", <value> ]\n            |   [ \"lte\", <value> ]\n            |   [ \"substring\", <value> ]\n            |   [ \"isubstring\", <value> ]\n            |   [ \"phrase_match\", <value> ]\n            |   [ \"iphrase_match\", <value> ]\n            |   [ \"prefix\", <value> ]\n            |   [ \"suffix\", <value> ]\n```"
        required: false
        explode: false
        schema:
          type: string
        name: where
        in: query
      - $ref: '#/components/parameters/gsc.output'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/gsc.positions-history'
            application/xml:
              schema:
                $ref: '#/components/schemas/gsc.positions-history'
        '400':
          $ref: '#/components/responses/gsc.error_400'
        '401':
          $ref: '#/components/responses/gsc.error_401'
        '403':
          $ref: '#/components/responses/gsc.error_403'
        '429':
          $ref: '#/components/responses/gsc.error_429'
        '500':
          $ref: '#/components/responses/gsc.error_500'
  /gsc/pages-history:
    get:
      tags:
      - GSC Insights
      summary: Pages history
      description: '>Requests to this endpoint are free and do not consume any API units.'
      operationId: gsc.pages-history
      parameters:
      - description: Project ID. Required when portfolio_id is not provided.
        required: false
        explode: false
        schema:
          type: integer
        name: project_id
        in: query
      - description: Portfolio ID. When provided, aggregates data across all GSC-connected projects in the portfolio.
        required: false
        explode: false
        schema:
          type: integer
        name: portfolio_id
        in: query
      - description: The start date of the historical period in YYYY-MM-DD format.
        required: true
        explode: false
        schema:
          type: string
          format: date
        name: date_from
        in: query
      - description: The end date of the historical period in YYYY-MM-DD format.
        required: false
        explode: false
        schema:
          type: string
          format: date
        name: date_to
        in: query
      - description: The time interval used to group historical data.
        required: false
        explode: false
        schema:
          type: string
          enum:
          - daily
          - weekly
          - monthly
          default: monthly
        name: history_grouping
        in: query
      - description: The type of search results to return (web, image, video, news).
        required: false
        explode: false
        schema:
          type: string
          enum:
          - web
          - image
          - video
          - news
          default: web
        name: search_type
        in: query
      - description: A two-letter country code (ISO 3166-1 alpha-2).
        required: false
        explode: false
        schema:
          type: string
          enum:
          - ad
          - ae
          - af
          - ag
          - ai
          - al
          - am
          - ao
          - ar
          - as
          - at
          - au
          - aw
          - az
          - ba
          - bb
          - bd
          - be
          - bf
          - bg
          - bh
          - bi
          - bj
          - bn
          - bo
          - br
          - bs
          - bt
          - bw
          - by
          - bz
          - ca
          - cd
          - cf
          - cg
          - ch
          - ci
          - ck
          - cl
          - cm
          - cn
          - co
          - cr
          - cu
          - cv
          - cy
          - cz
          - de
          - dj
          - dk
          - dm
          - do
          - dz
          - ec
          - ee
          - eg
          - es
          - et
          - fi
          - fj
          - fm
          - fo
          - fr
          - ga
          - gb
          - gd
          - ge
          - gf
          - gg
          - gh
          - gi
          - gl
          - gm
          - gn
          - gp
          - gq
          - gr
          - gt
          - gu
          - gy
          - hk
          - hn
          - hr
          - ht
          - hu
          - id
          - ie
          - il
          - im
          - in
          - iq
          - is
          - it
          - je
          - jm
          - jo
          - jp
          - ke
          - kg
          - kh
          - ki
          - kn
          - kr
          - kw
          - ky
          - kz
          - la
          - lb
          - lc
          - li
          - lk
          - ls
          - lt
          - lu
          - lv
          - ly
          - ma
          - mc
          - md
          - me
          - mg
          - mk
          - ml
          - mm
          - mn
          - mq
          - mr
          - ms
          - mt
          - mu
          - mv
          - mw
          - mx
          - my
          - mz
          - na
          - nc
          - ne
          - ng
          - ni
          - nl
          - 'no'
          - np
          - nr
          - nu
          - nz
          - om
          - pa
          - pe
          - pf
          - pg
          - ph
          - pk
          - pl
          - pn
          - pr
          - ps
          - pt
          - py
          - qa
          - re
          - ro
          - rs
          - ru
          - rw
          - sa
          - sb
          - sc
          - se
          - sg
          - sh
          - si
          - sk
          - sl
          - sm
          - sn
          - so
          - sr
          - st
          - sv
          - td
          - tg
          - th
          - tj
          - tk
          - tl
          - tm
          - tn
          - to
          - tr
          - tt
          - tw
          - tz
          - ua
          - ug
          - us
          - uy
          - uz
          - vc
          - ve
          - vg
          - vi
          - vn
          - vu
          - ws
          - ye
          - yt
          - za
          - zm
          - zw
        name: country
        in: query
      - description: Filter by device type (DESKTOP, MOBILE, TABLET). If not specified, all devices are included.
        required: false
        explode: false
        schema:
          type: string
          enum:
          - desktop
          - mobile
          - tablet
        name: device
        in: query
      - description: "Supported fields:\n- url\n\nFilter is a JSON string that represents a boolean expression, it should follow the following structure:\n```\n<bool_filter> ::= { \"and\" : <bool_filter>+ }\n              |   { \"or\" : <bool_filter>+ }\n              |   { \"not\" : <bool_filter> }\n              |   <expr>\n\n<expr> ::= {\n             \"field\" : <dimension|metric>,\n             ? \"is\": <condition>,\n           }\n\n<condition> ::= [ \"eq\", <value> ]\n            |   [ \"neq\", <value> ]\n            |   [ \"gt\", <value> ]\n            |   [ \"gte\", <value> ]\n            |   [ \"lt\", <value> ]\n            |   [ \"lte\", <value> ]\n            |   [ \"substring\", <value> ]\n            |   [ \"isubstring\", <value> ]\n            |   [ \"phrase_match\", <value> ]\n            |   [ \"iphrase_match\", <value> ]\n            |   [ \"prefix\", <value> ]\n            |   [ \"suffix\", <value> ]\n```"
        required: false
        explode: false
        schema:
          type: string
        name: where
        in: query
      - $ref: '#/components/parameters/gsc.output'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/gsc.pages-history'
            application/xml:
              schema:
                $ref: '#/components/schemas/gsc.pages-history'
        '400':
          $ref: '#/components/responses/gsc.error_400'
        '401':
          $ref: '#/components/responses/gsc.error_401'
        '403':
          $ref: '#/components/responses/gsc.error_403'
        '429':
          $ref: '#/components/responses/gsc.error_429'
        '500':
          $ref: '#/components/responses/gsc.error_500'
  /gsc/performance-by-device:
    get:
      tags:
      - GSC Insights
      summary: Performance by device
      description: '>Requests to this endpoint are free and do not consume any API units.'
      operationId: gsc.performance-by-device
      parameters:
      - description: Project ID. Required when portfolio_id is not provided.
        required: false
        explode: false
        schema:
          type: integer
        name: project_id
        in: query
      - description: Portfolio ID. When provided, aggregates data across all GSC-connected projects in the portfolio.
        required: false
        explode: false
        schema:
          type: integer
        name: portfolio_id
        in: query
      - description: The start date of the historical period in YYYY-MM-DD format.
        required: true
        explode: false
        schema:
          type: string
          format: date
        name: date_from
        in: query
      - description: The end date of the historical period in YYYY-MM-DD format.
        required: false
        explode: false
        schema:
          type: string
          format: date
        name: date_to
        in: query
      - description: The type of search results to return (web, image, video, news).
        required: false
        explode: false
        schema:
          type: string
          enum:
          - web
          - image
          - video
          - news
          default: web
        name: search_type
        in: query
      - description: A two-letter country code (ISO 3166-1 alpha-2).
        required: false
        explode: false
        schema:
          type: string
          enum:
          - ad
          - ae
          - af
          - ag
          - ai
          - al
          - am
          - ao
          - ar
          - as
          - at
          - au
          - aw
          - az
          - ba
          - bb
          - bd
          - be
          - bf
          - bg
          - bh
          - bi
          - bj
          - bn
          - bo
          - br
          - bs
          - bt
          - bw
          - by
          - bz
          - ca
          - cd
          - cf
          - cg
          - ch
          - ci
          - ck
          - cl
          - cm
          - cn
          - co
          - cr
          - cu
          - cv
          - cy
          - cz
          - de
          - dj
          - dk
          - dm
          - do
          - dz
          - ec
          - ee
          - eg
          - es
          - et
          - fi
          - fj
          - fm
          - fo
          - fr
          - ga
          - gb
          - gd
          - ge
          - gf
          - gg
          - gh
          - gi
          - gl
          - gm
          - gn
          - gp
          - gq
          - gr
          - gt
          - gu
          - gy
          - hk
          - hn
          - hr
          - ht
          - hu
          - id
          - ie
          - il
          - im
          - in
          - iq
          - is
          - it
          - je
          - jm
          - jo
          - jp
          - ke
          - kg
          - kh
          - ki
          - kn
          - kr
          - kw
          - ky
          - kz
          - la
          - lb
          - lc
          - li
          - lk
          - ls
          - lt
          - lu
          - lv
          - ly
          - ma
          - mc
          - md
          - me
          - mg
          - mk
          - ml
          - mm
          - mn
          - mq
          - mr
          - ms
          - mt
          - mu
          - mv
          - mw
          - mx
          - my
          - mz
          - na
          - nc
          - ne
          - ng
          - ni
          - nl
          - 'no'
          - np
          - nr
          - nu
          - nz
          - om
          - pa
          - pe
          - pf
          - pg
          - ph
          - pk
          - pl
          - pn
          - pr
          - ps
          - pt
          - py
          - qa
          - re
          - ro
          - rs
          - ru
          - rw
          - sa
          - sb
          - sc
          - se
          - sg
          - sh
          - si
          - sk
          - sl
          - sm
          - sn
          - so
          - sr
          - st
          - sv
          - td
          - tg
          - th
          - tj
          - tk
          - tl
          - tm
          - tn
          - to
          - tr
          - tt
          - tw
          - tz
          - ua
          - ug
          - us
          - uy
          - uz
          - vc
          - ve
          - vg
          - vi
          - vn
          - vu
          - ws
          - ye
          - yt
          - za
          - zm
          - zw
        name: country
        in: query
      - description: "Supported fields:\n- url\n\nFilter is a JSON string that represents a boolean expression, it should follow the following structure:\n```\n<bool_filter> ::= { \"and\" : <bool_filter>+ }\n              |   { \"or\" : <bool_filter>+ }\n              |   { \"not\" : <bool_filter> }\n              |   <expr>\n\n<expr> ::= {\n             \"field\" : <dimension|metric>,\n             ? \"is\": <condition>,\n           }\n\n<condition> ::= [ \"eq\", <value> ]\n            |   [ \"neq\", <value> ]\n            |   [ \"gt\", <value> ]\n            |   [ \"gte\", <value> ]\n            |   [ \"lt\", <value> ]\n            |   [ \"lte\", <value> ]\n            |   [ \"substring\", <value> ]\n            |   [ \"isubstring\", <value> ]\n            |   [ \"phrase_match\", <value> ]\n            |   [ \"iphrase_match\", <value> ]\n            |   [ \"prefix\", <value> ]\n            |   [ \"suffix\", <value> ]\n```"
        required: false
        explode: false
        schema:
          type: string
        name: where
        in: query
      - $ref: '#/components/parameters/gsc.output'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/gsc.performance-by-device'
            application/xml:
              schema:
                $ref: '#/components/schemas/gsc.performance-by-device'
        '400':
          $ref: '#/components/responses/gsc.error_400'
        '401':
          $ref: '#/components/responses/gsc.error_401'
        '403':
          $ref: '#/components/responses/gsc.error_403'
        '429':
          $ref: '#/components/responses/gsc.error_429'
        '500':
          $ref: '#/components/responses/gsc.error_500'
  /gsc/metrics-by-country:
    get:
      tags:
      - GSC Insights
      summary: Metrics by country
      description: '>Requests to this endpoint are free and do not consume any API units.'
      operationId: gsc.metrics-by-country
      parameters:
      - description: Project ID. Required when portfolio_id is not provided.
        required: false
        explode: false
        schema:
          type: integer
        name: project_id
        in: query
      - description: Portfolio ID. When provided, aggregates data across all GSC-connected projects in the portfolio.
        required: false
        explode: false
        schema:
          type: integer
        name: portfolio_id
        in: query
      - description: The start date of the historical period in YYYY-MM-DD format.
        required: true
        explode: false
        schema:
          type: string
          format: date
        name: date_from
        in: query
      - description: The end date of the historical period in YYYY-MM-DD format.
        required: false
        explode: false
        schema:
          type: string
          format: date
        name: date_to
        in: query
      - description: The time interval used to group historical data.
        required: false
        explode: false
        schema:
          type: string
          enum:
          - daily
          - weekly
          - monthly
          default: monthly
        name: history_grouping
        in: query
      - description: The type of search results to return (web, image, video, news).
        required: false
        explode: false
        schema:
          type: string
          enum:
          - web
          - image
          - video
          - news
          default: web
        name: search_type
        in: query
      - description: Filter by device type (DESKTOP, MOBILE, TABLET). If not specified, all devices are included.
        required: false
        explode: false
        schema:
          type: string
          enum:
          - desktop
          - mobile
          - tablet
        name: device
        in: query
      - description: "Supported fields:\n- url\n\nFilter is a JSON string that represents a boolean expression, it should follow the following structure:\n```\n<bool_filter> ::= { \"and\" : <bool_filter>+ }\n              |   { \"or\" : <bool_filter>+ }\n              |   { \"not\" : <bool_filter> }\n              |   <expr>\n\n<expr> ::= {\n             \"field\" : <dimension|metric>,\n             ? \"is\": <condition>,\n           }\n\n<condition> ::= [ \"eq\", <value> ]\n            |   [ \"neq\", <value> ]\n            |   [ \"gt\", <value> ]\n            |   [ \"gte\", <value> ]\n            |   [ \"lt\", <value> ]\n            |   [ \"lte\", <value> ]\n            |   [ \"substring\", <value> ]\n            |   [ \"isubstring\", <value> ]\n            |   [ \"phrase_match\", <value> ]\n            |   [ \"iphrase_match\", <value> ]\n            |   [ \"prefix\", <value> ]\n            |   [ \"suffix\", <value> ]\n```"
        required: false
        explode: false
        schema:
          type: string
        name: where
        in: query
      - $ref: '#/components/parameters/gsc.output'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/gsc.metrics-by-country'
            application/xml:
              schema:
                $ref: '#/components/schemas/gsc.metrics-by-country'
        '400':
          $ref: '#/components/responses/gsc.error_400'
        '4

# --- truncated at 32 KB (95 KB total) ---
# Full source: https://raw.githubusercontent.com/api-evangelist/ahrefs/refs/heads/main/openapi/ahrefs-gsc-insights-api-openapi.yml