jean_sahlberg
02/02/2023, 12:19 PMjean_sahlberg
02/02/2023, 12:25 PMclient.py
@property
def authenticator(self) -> APIKeyAuthenticator:
"""Return a new authenticator object."""
talkdesk_auth = TalkdeskAuth(self.config)
token_request = talkdesk_auth.request_bearer_token()
return APIKeyAuthenticator.create_for_stream(
self,
key="Authorization",
value=f"Bearer {token_request['access_token']}",
location="header"
)
def generate_report(self):
start_time = datetime.utcnow() - timedelta(days=3)
end_time = datetime.utcnow() - timedelta(hours=2)
data = json.dumps({
"format": "json",
"timespan": {
"from": start_time.strftime("%Y-%m-%dT%H:%M:%SZ"),
"to": end_time.strftime("%Y-%m-%dT%H:%M:%SZ")
}
})
headers={'Authorization':'Bearer token',
'Content-Type':'application/json'}
resp = <http://requests.post|requests.post>("<https://api.talkdeskapp.com/data/reports/calls/jobs>", headers=headers, data=data)
datar = resp.json()
return datar['job']['id']
I’m implementing the generate_report
methodedgar_ramirez_mondragon
02/02/2023, 5:49 PMself.requests_session.auth = self.authenticator
<http://self.requests_session.post|self.requests_session.post>(...)
jean_sahlberg
02/02/2023, 6:58 PM