from dotenv import load_dotenv
import os
import requests
import json
# Load environment variables from .env file in the parent directory
load_dotenv('../.env')
# Pipedrive API token
api_token = os.getenv('PIPEDRIVE_API_TOKEN')
# Pipedrive company domain
company_domain = os.getenv('COMPANY_DOMAIN')
# Information regarding the new Activity
data = {
'subject': 'Discuss revenue with John',
'type': 'Call',
'deal_id': '393'
}
# URL for adding an Activity
url = f'https://{company_domain}.pipedrive.com/api/v1/activities?api_token={api_token}'
# Sending the request
print("Sending request...")
response = requests.post(url, data=data)
# Convert the JSON response to a Python dictionary
result = json.loads(response.text)
# Print the entire response
print(f"Response: {result}")
# Check if the data returned in the result is not empty
if not result.get('data'):
print("Adding failed")
exit()
# Check if the Activity's ID came back, if it did, print out the success message
if result['data'].get('id'):
print("Activity was added successfully!")