microsoft/clarity

Data Export API Example Fails For Popular Pages

Closed this issue · 1 comments

I tried the example Clarity Data Export API. API calls are limited to 10 calls per project, per day, which makes getting the incantation right problematic.

The bash example works as shown. I stored my token in CLARITY_DATA.

DAYS=30
DIM1="OS"
PARAMS="numOfDays=$DAYS&dimension1=$DIM1"
URL="https://www.clarity.ms/export-data/api/v1/project-live-insights"
curl \
  --location "$URL?$PARAMS" \
  --header 'Content-Type: application/json' \
  --header "Authorization: Bearer $CLARITY_DATA"

However, changing DIM1 to Popular Pages, Popular+Pages and PopularPages results in no response.

I get a similar result with Python:

#!/usr/bin/python3

import os, requests

auth = f"Bearer {os.environ["CLARITY_DATA"]}"
params = {"numOfDays": "30", "dimension1": "Popular Pages"}
headers = {
   "Authorization": auth,
   "Content-type": "application/json"
}
response = requests.get(
   "https://www.clarity.ms/export-data/api/v1/project-live-insights",
   params=params,
   headers=headers,
)

print(response.json())

Here is the error:

Traceback (most recent call last):
  File "/home/mslinn/venv/default/lib/python3.12/site-packages/requests/models.py", line 974, in json
    return complexjson.loads(self.text, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.12/runpy.py", line 198, in _run_module_as_main
    return _run_code(code, main_globals, None,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/runpy.py", line 88, in _run_code
    exec(code, run_globals)
  File "/home/mslinn/.vscode-server/extensions/ms-python.debugpy-2024.6.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 39, in <module>
    cli.main()
  File "/home/mslinn/.vscode-server/extensions/ms-python.debugpy-2024.6.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 430, in main
    run()
  File "/home/mslinn/.vscode-server/extensions/ms-python.debugpy-2024.6.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "/home/mslinn/.vscode-server/extensions/ms-python.debugpy-2024.6.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mslinn/.vscode-server/extensions/ms-python.debugpy-2024.6.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/home/mslinn/.vscode-server/extensions/ms-python.debugpy-2024.6.0-linux-x64/bundled/libs/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "blog/bin/clarity_popular_pages", line 16, in <module>
    print(response.json())
          ^^^^^^^^^^^^^^^
  File "/home/mslinn/venv/default/lib/python3.12/site-packages/requests/models.py", line 978, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Hey there,

The limit on days back is 3 (not 30) https://learn.microsoft.com/en-us/clarity/setup-and-installation/clarity-data-export-api#api-endpoint

And Popular Pages will be a return value, not an input dimension. These are the only possible dimensions:
Browser
Device
Country
OS
Source
Medium
Campaign
Channel
URL
Metrics: