Python
You can use the openapi-python-client package to generate a Python client from the OpenAPI specification of the Rest API. This will allow you to have type-safe access to the API endpoints and data structures.
Install the required package using pip:
pip install openapi-python-client
Run the following command to generate the Python client from the OpenAPI specification:
openapi-python-client generate --url https://api.kimzee.com/docs/swagger.json
Here is an example of how to use the generated client to make a request to the Rest API:
/src/client.py
from rest_api_client import Client, AuthenticatedClient
from rest_api_client.api.campaign.campaign_controller_get_many import sync_detailed as get_campaign_detailed
from rest_api_client.api.campaign.campaign_controller_submit import sync_detailed as submit_campaign_entry
from rest_api_client.models.campaign_submit_one_body import CampaignSubmitOneBody
from rest_api_client.types import Response
# Authenticate the client
authenticated_client = AuthenticatedClient(
base_url="https://api.kimzee.com/api/v1/",
token="YOUR_API_KEY",
)
# Fetch all campaigns accessible with the provided API key
response: Response = get_campaign_detailed(client=authenticated_client)
if response.status_code != 200:
print("Error:", response.content)
exit(1)
data = response.parsed
example_campaign = next((c for c in data if c.name == "Campaign Test"), None)
# Submit a new entry to the campaign with the provided resourceId and body
entry_request = CampaignSubmitOneBody(
data={
"email": "test@example.com",
"name": "Test User",
"birthday": "1997-10-17",
"company": "My Company",
"technology": "Python"
}
)
submit_response = submit_campaign_entry(
client=authenticated_client,
resource_id=example_campaign.resource.id,
json_body=entry_request,
)
if submit_response.status_code != 200:
print("Error:", submit_response.content)
exit(1)
print("Entry submitted successfully!")