27
loading...
This website collects cookies to deliver better user experience
pip install requests
pip3 install requests # Use this if the first one doesn't work for you.
import json
import requests
# token hasn't been prepended with get_ because it needs to be sent with all requests.
token = {
'api_token': 'your-api-token-found-in-the-web-app'
}
get_url = 'https://your-domain.pipedrive.com/api/v1/personFields'
# The params argument is appended to the url as a query parameter.
get_response = requests.get(get_url, params=token)
get_content = json.loads(get_response.content)
# Upon success, the key 'success' will equal True.
print(get_content['success'])
get_data = get_content['data']
for i, v in enumerate(get_data):
print(i, v['name'])
# If you want to further examine the field at index 5.
print(get_data[5])
# If for example the index of your field is 5.
field_key = get_data[5]['key']
# token should still be defined from the GET request, but in case you skipped over that, here it is again.
token = {
'api_token': 'your-api-token-found-in-the-web-app'
}
# The field that you want to create.
post_data = {
'name': 'trial end date',
'field_type': 'date'
}
post_url = 'https://your-domain.pipedrive.com/api/v1/personFields'
post_response = requests.post(post_url, params=token, data=post_data)
post_content = json.loads(post_response.content)
# The key 'success' should equal True.
print(post_content['success'])
field_key = post_content['data']['key']
# token should still be defined from the GET request, but in case you skipped over that, here it is again.
token = {
'api_token': 'your-api-token-found-in-the-web-app'
}
# Replace id-of-person with the actual ID
put_url = 'https://your-domain.pipedrive.com/api/v1/persons/id-of-person'
# field_key is the 'key' value of the field that you want to write data to
put_payload = {
field_key: '2021-06-01' # If this person's trial ends on 2021-06-01
}
put_response = requests.put(put_url, params=token, data=put_payload)
put_content = json.loads(put_response.content)
# The key 'success' should equal True.
print(put_content['success'])
# This should equal the value that you just wrote using the PUT request.
print(put_content['data'][field_key])