### Install Dwolla Python SDK Source: https://github.com/dwolla/dwolla-v2-python/blob/main/README.md Install the Dwolla Python SDK using pip. This is the first step to begin using the SDK. ```shell pip install dwollav2 ``` -------------------------------- ### Perform GET Request Source: https://github.com/dwolla/dwolla-v2-python/blob/main/README.md Make a GET request to a specified resource. Supports query parameters as keyword arguments or a dictionary. ```python # GET api.dwolla.com/resource?foo=bar token.get('resource', foo = 'bar') ``` ```python # GET api.dwolla.com/resource?foo=bar token.get('resource', {'foo' = 'bar', 'baz' = 'foo'}) ``` -------------------------------- ### Initialize Dwolla Client with Environment and Timeout Source: https://github.com/dwolla/dwolla-v2-python/blob/main/README.md Initialize the Dwolla Client with your application key, secret, and environment. Optionally configure request timeout. ```python client = dwollav2.Client( key = os.environ['DWOLLA_APP_KEY'], secret = os.environ['DWOLLA_APP_SECRET'], environment = 'sandbox', # defaults to 'production' requests = {'timeout': 0.001} ) ``` -------------------------------- ### Initialize Dwolla Client with on_grant Callback Source: https://github.com/dwolla/dwolla-v2-python/blob/main/README.md Initialize the Dwolla Client and configure an optional on_grant callback to handle new token grants. ```python client = dwollav2.Client( key = os.environ['DWOLLA_APP_KEY'], secret = os.environ['DWOLLA_APP_SECRET'], on_grant = lambda t: save(t) ) ``` -------------------------------- ### Initialize Pre-Existing Token Source: https://github.com/dwolla/dwolla-v2-python/blob/main/README.md Initialize a Token object with an existing access token and its expiration time. ```python client.Token(access_token = '...', expires_in = 123) ``` -------------------------------- ### Perform POST Request with JSON Data Source: https://github.com/dwolla/dwolla-v2-python/blob/main/README.md Make a POST request to a specified resource with JSON data. Parameters are sent as keyword arguments. ```python # POST api.dwolla.com/resource {"foo":"bar"} token.post('resource', foo = 'bar') ``` -------------------------------- ### Perform POST Request with Multipart Form Data Source: https://github.com/dwolla/dwolla-v2-python/blob/main/README.md Make a POST request with multipart/form-data, suitable for file uploads. Specify filename, file object, and content type. ```python # POST api.dwolla.com/resource multipart/form-data foo=... token.post('resource', foo = ('mclovin.jpg', open('mclovin.jpg', 'rb'), 'image/jpeg')) ``` -------------------------------- ### Handling Dwolla API Errors Source: https://github.com/dwolla/dwolla-v2-python/blob/main/README.md Demonstrates how to catch and handle specific Dwolla API errors, such as NotFoundError, using a try-except block. It shows how to access error details like status, headers, and the error code from the exception object. ```python try: token.get('/not-found') except dwollav2.NotFoundError as e: e.status # => 404 e.headers # => {"server"=>"cloudflare-nginx", "date"=>"Mon, 28 Mar 2016 15:35:32 GMT", "content-type"=>"application/vnd.dwolla.v1.hal+json; profile=\"http://nocarrier.co.uk/profiles/vnd.error/\"; charset=UTF-8", "content-length"=>"69", "connection"=>"close", "set-cookie"=>"__cfduid=da1478bfdf3e56275cd8a6a741866ccce1459179332; expires=Tue, 28-Mar-17 15:35:32 GMT; path=/; domain=.dwolla.com; HttpOnly", "access-control-allow-origin"=>"*", "x-request-id"=>"667fca74-b53d-43db-bddd-50426a011881", "cf-ray"=>"28ac270abca64207-MSP"} e.body.code # => "NotFound" except dwollav2.Error: # ... ``` -------------------------------- ### Set Request Headers for POST Request Source: https://github.com/dwolla/dwolla-v2-python/blob/main/README.md Set additional headers, such as 'Idempotency-Key', for a POST request by passing a dictionary as the third argument. ```python token.post('customers', { 'firstName': 'John', 'lastName': 'Doe', 'email': 'jd@doe.com' }, { 'Idempotency-Key': 'a52fcf63-0730-41c3-96e8-7147b5d1fb01' }) ``` -------------------------------- ### Generate Application Access Token Source: https://github.com/dwolla/dwolla-v2-python/blob/main/README.md Generate an application access token using the client credentials grant type. This token is used for authenticating API requests on behalf of the application. ```python application_token = client.Auth.client() ``` -------------------------------- ### Perform DELETE Request Source: https://github.com/dwolla/dwolla-v2-python/blob/main/README.md Make a DELETE request to a specified resource. ```python # DELETE api.dwolla.com/resource token.delete('resource') ``` -------------------------------- ### Handle Successful API Response Source: https://github.com/dwolla/dwolla-v2-python/blob/main/README.md Access the status code and headers from a successful API response object. ```python res = token.get('/') res.status # => 200 res.headers ``` -------------------------------- ### Accessing Event Href Source: https://github.com/dwolla/dwolla-v2-python/blob/main/README.md This snippet shows how to access the 'href' attribute from the 'events' link in a Dwolla API response body. ```python res.body['_links']['events']['href'] # => 'https://api-sandbox.dwolla.com/events' ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.