Talkdesk API using POST method in python

628 views Asked by At

I am trying to get into talkdesk Reporting API. irrespective of correct credential, it is giving me 401. I am following this document: https://docs.talkdesk.com/docs/client-credentials and I have following credential:

id='XXXXXXX'
secret='XXXXXXX'
public_key='XXXXXXX'
algorithm='XXXXXXX'
private_key='XXXXXXX'
key_id ='XXXXXXX'
import requests
     
consumer_key = key_id
consumer_secret = secret
username = "XXXX"
password = "XXXXX"

payload = {
    'grant_type': 'password',
    'client_id': consumer_key,
    'client_secret': consumer_secret,
    'username': username,
    'password': password,
    'scope':'reports:read'
}
 
r = requests.post("https://xxx.talkdeskid.com/oauth/token",  headers={"Content-Type":"application/x-www-form-urlencoded"},    data=payload)
 
print(r.content)
1

There are 1 answers

0
Bridger Cohen On

Not sure if password is an option for the grant_type parameter. The documentation only mentions client_credentials as an option.

Code below:

import requests
import base64

signed_request = base64.b64encode(b'<client_id>:<client_secret>').decode()

payload = {
    'grant_type': 'client_credentials',
    'client_id': 'xxxx',
    'client_secret': 'xxxx',
    'username': 'xxxx',
    'password': 'xxxx',
    'scope':'reports:read'
}

response = requests.post("https://xxx.talkdeskid.com/oauth/token", headers={"Authorization": "Basic {}".format(signed_request), "Content-Type":"application/x-www-form-urlencoded"}, data=payload)

print(response.content)