Python Example for Calling API
Python Example for Calling the CatFee.IO REST API
Prerequisites
You need a valid API Key and API Secret.
Make sure your environment has the requests
library installed. You can install it using:
Use Python version 3.6 or above.
Example Code
Code Explanation
generate_timestamp()
Generates the current UTC timestamp in ISO 8601 format usingtime.strftime('%Y-%m-%dT%H:%M:%S.000Z')
.build_request_path()
Builds the full request path including query parameters. If no parameters are provided, it returns the original path.generate_signature()
Concatenatestimestamp + method + request_path
, then generates a signature using thehmac_sha256()
function.hmac_sha256()
Uses the HMAC-SHA256 algorithm with yourAPI_SECRET
as the key, and encodes the result with Base64.create_request()
Sends the HTTP request using therequests
library. Supports POST, GET, PUT, and DELETE methods.main()
The main function sets the HTTP method, prepares query parameters, builds headers and request path, sends the request, and prints the response.
Notes
API Key and Secret Replace
API_KEY
andAPI_SECRET
with the actual credentials you obtained from CatFee.IO.Error Handling If the response status code is not 200, the code will print the error details.
HTTP Methods This example supports POST, GET, PUT, and DELETE. You can modify the
method
variable based on your needs.
Summary
This example demonstrates how to use Python to securely call the CatFee.IO Rest API. It ensures security through HMAC-SHA256 signature authentication. You can adjust the code as needed to support different endpoints and HTTP methods.
If you have any questions or need further assistance, feel free to contact the CatFee.IO support team.
Last updated
Was this helpful?