Hey there, fellow developer! Ready to supercharge your proposal process with Proposify's API? Let's dive in and build a Python integration that'll make your life easier. We'll cover the essentials, so you can get up and running in no time.
Before we jump in, make sure you've got:
requests
library (pip install requests
)First things first, let's get you authenticated:
import requests API_KEY = 'your_api_key_here' BASE_URL = 'https://api.proposify.com/v1' headers = { 'Authorization': f'Bearer {API_KEY}', 'Content-Type': 'application/json' }
Now, let's make some noise with basic GET and POST requests:
# GET example response = requests.get(f'{BASE_URL}/proposals', headers=headers) proposals = response.json() # POST example new_proposal = { 'name': 'Awesome New Proposal', 'client_id': 'client_id_here' } response = requests.post(f'{BASE_URL}/proposals', headers=headers, json=new_proposal)
Pro tip: Always check response.status_code
to handle errors gracefully!
Let's tackle the bread and butter of proposal management:
# Retrieve proposals def get_proposals(): return requests.get(f'{BASE_URL}/proposals', headers=headers).json() # Create a proposal def create_proposal(proposal_data): return requests.post(f'{BASE_URL}/proposals', headers=headers, json=proposal_data).json() # Update a proposal def update_proposal(proposal_id, update_data): return requests.put(f'{BASE_URL}/proposals/{proposal_id}', headers=headers, json=update_data).json() # Delete a proposal def delete_proposal(proposal_id): return requests.delete(f'{BASE_URL}/proposals/{proposal_id}', headers=headers)
Ready to level up? Let's handle sections, recipients, and webhooks:
# Add a section to a proposal def add_section(proposal_id, section_data): return requests.post(f'{BASE_URL}/proposals/{proposal_id}/sections', headers=headers, json=section_data).json() # Manage recipients def add_recipient(proposal_id, recipient_data): return requests.post(f'{BASE_URL}/proposals/{proposal_id}/recipients', headers=headers, json=recipient_data).json() # Set up a webhook def create_webhook(event_type, target_url): webhook_data = { 'event': event_type, 'target_url': target_url } return requests.post(f'{BASE_URL}/webhooks', headers=headers, json=webhook_data).json()
Keep these in mind to stay on Proposify's good side:
Don't forget to test! Here's a quick example:
import unittest class TestProposifyAPI(unittest.TestCase): def test_get_proposals(self): proposals = get_proposals() self.assertIsInstance(proposals, list) self.assertTrue(len(proposals) > 0) if __name__ == '__main__': unittest.main()
And there you have it! You're now armed with the knowledge to build a robust Proposify API integration. Remember, the API docs are your best friend for diving deeper. Happy coding!
For the full code examples and more, check out our GitHub repo.
Now go forth and conquer those proposals!