API call to Fathom Analytics via Postman - python

I'm trying to make an API call to Fathom Analytics. But I cannot figure out the filtering option (e.g. filter reportings for specific pathname). Can someone help me figuring this out?
curl --location --request GET 'https://api.usefathom.com/v1/aggregations?entity=pageview&entity_id=[SITE_ID_HERE]&aggregates=visits, uniques, pageviews, avg_duration, bounce_rate' \
--header 'Authorization: Bearer [BEARER_TOKEN_HERE]'
How can I insert the json-payload here in order to use the Fathom Filter option (https://usefathom.com/api#aggregation)
Also, I rebuilt the api call in python, without success. When I remove the payload from the API call it works just fine.
import requests
endpoint = "https://api.usefathom.com/v1/aggregations?entity=pageview&entity_id=[SITE_ID]&aggregates=pageviews,visits,uniques,avg_duration,bounce_rate&date_from=2022-10-01&date_to=2022-10-31"
payload = [{"property": "pathname",
"operator": "is",
"value": "/[URL TO FILTER]"}]
headers = {
"Authorization": "[BEARER_TOKEN]"}
response=requests.get(endpoint, json=payload, headers=headers)
print(response.json())

I struggled a bit with this too, and in my case it worked when I included the "filter" key name in the JSON payload itself rather than the curl command.
Here's what worked for me:
curl https://api.usefathom.com/v1/aggregations \
-H "Authorization: Bearer [BEARER_TOKEN_HERE]" \
-H "Accept: application/json" \
-d entity="pageview" \
-d entity_id="[SITE_ID_HERE]" \
-d aggregates="pageviews" \
-d "{'filters': [{'property':'country', 'operator':'is', 'value':'UK'}]}" \
-G
Moving the JSON to its own file (payload.json) and updating that curl line to this also worked:
-d #payload.json \

Related

github api : List workflow runs with created and status parameters

I am trying to list Lists all workflow runs for a repository with parameters created and status also i am using per_page. I am using below url but it doss not work as expected. It does not throw any error but the filter for date(created)does not work. I can see workflows with date 2022-08-02T09:29:07Z as well.
But i am trying to do it in python as well
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <TOKEN>" \
https://<base url>/api/v3/repos/<org>/<repo>/actions/runs\
?q=status:completed+created:>=2022-10-10&per_page=100
import requests
u= f"https://<base url>/api/v3/repos/<org>/<repo>/actions/runs?q=status:completed+created:>=2022-10-10&per_page=100"
res = requests.get(u, headers={"Authorization": "Bearer <TOKEN>",
"Accept": "application/vnd.github+json"})
From the docs, it looks like created should be a query parameter itself.
Try: runs?status=completed&created=>=2022-10-10&per_page=100

how to curl file using python

I have curl code recived a image file
curl -X GET -H 'Authorization: Bearer TOKENS' https://api.line.me/v2/bot/message/8595925133330/content -o image.png
how to get the file using python?
curl -X GET -H 'Authorization: Bearer TOKENS' https://api.line.me/v2/bot/message/8595925133330/content -o image.png
Comparable Python Script should be like below:
import requests
endpoint = "https://api.line.me/v2/bot/message/8595925133330/content"
headers = {"Authorization":"Bearer TOKENS"}
r = requests.post(endpoint,headers=headers)
open('image.png', 'wb').write(r.content)

how to automate api request with sessionID and csrf token in python

Hi I use following curl commands to fetch information , here I get session ID and csrf token and then proceed further to do post login and any request.
1. Get /login/, show headers to get the cookies but don't care about output:
curl -o /dev/null -D - 'https://192.168.2.1/login/' --insecure
2. Post /login/. Note how we set the cookies with '-b', pass the parameters with '-d' and set an HTTP Referer header with '-e'.
curl -o /dev/null -D - -b 'csrftoken=TOKEN;sessionid=ID' \
-d 'csrfmiddlewaretoken=TOKEN' \
-d 'username=USER' \
-d 'password=PASSWORD' \
-e 'https://192.168.2.1/login/' \
'https://192.168.2.1/login/'
3. Get list of projects (/api/project/). Here we do care about the output.
curl -D - -b 'csrftoken=TOKEN;sessionid=ID' \
'https://192.168.2.1/api/project/?format=json&limit=0'
How can I automate the same using python , may be any example usingn request or pycurl

Convert curl command to http request in python

I'm new on REST API's and I'm unable to make run an http request.
If I try the curl command it works by terminal:
curl \
--request POST \
--header "X-OpenAM-Username: user" \
--header "X-OpenAM-Password: password" \
--header "Content-Type: application/json" \
--data "{}" \
http://openam.sp.com:8095/openamSP/json/authenticate
and the result:
{"tokenId":"AQIC5wM2LY4Sfczw67Mo6Mkzq-srfED3YO8GCSe0Be6wtPs.*AAJTSQACMDEAAlNLABM2NzQ5NjQ4Mjc0MDY0MzEwMDEyAAJTMQAA*","successUrl":"/openamSP/console"}
But now, from my web on Django I want to make a request and I'm unable to make it work, the code that I use it's:
import requests
headers = {'X-OpenAM-Username':'user', 'X-OpenAM-Password':'password', 'Content-Type':'application/json'}
data = {}
r = requests.get('http://openam.sp.com:8095/openamSP/json/authenticate', headers=headers, params=data)
and if I check the answer:
u'{"code":405,"reason":"Method Not Allowed","message":"Method Not Allowed"}'
What I'm doing wrong? I can't see where is my mistake.
Thanks and regards.
You are doing everything correct, except POST method just do this:
r = requests.post('http://openam.sp.com:8095/openamSP/json/authenticate', headers=headers, params=data)
The method URL receives is POST method not GET.

Converting cURL to Python Requests

I need to convert the following cURL command to python requests.
curl 'https://test.com/api/v1/courses/xx/discussion_topics/xx/entries.json' \
-F 'message=<message>' \
-H "Authorization: Bearer <token>"
So far I have requests.post("https://test.com/api/v1/courses/xx/discussion_topics/xx/entries")
but how do I add the message and auth?
requests.post("https://test.com/api/v1/courses/xx/discussion_topics/xx/entries.json, data=json.dumps({"message": "<message>"}), headers={"Authorization": "Bearer <token>"})

Categories

Resources