Python code to do GET request from pipedrive API -
i using python-pipedrive wrap pipedrive's api though doesn't quite work out of box on python3 (which i'm using) modified it. i'm having trouble http requests portion.
this taught me how use httplib2: https://github.com/jcgregorio/httplib2/wiki/examples-python3
basically, want send request this: https://api.pipedrive.com/v1/persons/123?api_token=1234abcd1234abcd
this works:
from httplib2 import http urllib.parse import urlencode pipedrive_api_url = "https://api.pipedrive.com/v1/persons/123?api_token=1234abcd1234abcd" response, data = http.request(pipedrive_api_url, method='get', headers={'content-type': 'application/x-www-form-urlencoded'})
however, pipedrive returns error 401 'you need authorized make request.' if this:
pipedrive_api_url = "https://api.pipedrive.com/v1/" parameters = 'persons/123' api_token = '1234abcd1234abcd' response, data = http.request(pipedrive_api_url + parameters, method='get', body=urlencode(api_token), headers={'content-type': 'application/x-www-form-urlencoded'})
the actual response is:
response = {'server': 'nginx', 'status': '401', 'connection': 'keep-alive', 'set-cookie': 'pipe-session=7b6ddadbc67abdadb6a67dbadcb; path=/; domain=.pipedrive.com; secure; httponly', 'date': 'sat, 11 jun 2016 06:50:13 gmt', 'transfer-encoding': 'chunked', 'x-frame-options': 'sameorigin', 'content-type': 'application/json, charset=utf-8', 'x-xss-protection': '1; mode=block'} data = {'success': false, 'error': 'you need authorized make request.'}
how provide api_token parameter (body) request? know i'm doing wrong?
you need provide api_token
query parameter. concatenate stings
pipedrive_api_url = "https://api.pipedrive.com/v1/" route = 'persons/123' api_token = '1234abcd1234abcd' response, data = http.request(pipedrive_api_url + route + '?api_token=' + api_token, method='get', headers={'content-type': 'application/x-www-form-urlencoded'})
Comments
Post a Comment