Python SDK Custom Requests

Python SDK Custom Requests

Explanation

What are Custom Requests?

The Python SDK provides a generic request() method that lets you call any CATAPA API endpoint, including those not yet wrapped by generated methods.


Quickstart

A simple example:

from catapa import Catapa, HTTPMethod

client = Catapa(
    tenant="zfrl",
    client_id="demo",
    client_secret="demo-secret"
)

# Make a custom GET request
response = client.request(
    method=HTTPMethod.GET,
    path="/core/v1/employees",
    params={"page": 0, "size": 10}
)

print(f"Found {len(response.json()['content'])} employees")

Tutorial: Basic CRUD Operations

This tutorial demonstrates complete CRUD (Create, Read, Update, Delete) operations on Employee Identity Cards.

Setup

1. CREATE - Add Employee Identity Card

2. READ - List Employee Identity Cards

3. UPDATE - Modify Employee Identity Card

4. DELETE - Remove Employee Identity Card


Cookbook

Recipe 1: Upload Files with Multipart Form-Data

Create a company with logo upload using multipart/form-data:

Key Points:

  • "request" field contains JSON data with application/json content type

  • "file" field contains the actual file to upload

  • Use None as filename for JSON fields (not a file attachment)

  • SDK automatically sets multipart/form-data with boundary

Recipe 2: Download Files

Key Points:

  • Use response.content for binary data

  • Use response.json() for JSON data


Advanced Topics

parse_json Parameter

By default request() returns an HttpResponse object so you can check status_code.

If you only need the JSON body, you can enable auto-parse:

Content-Type Handling

JSON Requests (default):

Multipart Requests (with files):

Important: When using files, do not set Content-Type manually. The SDK sets the correct multipart boundary.

HTTPMethod Enum

Available methods: HTTPMethod.GET, HTTPMethod.POST, HTTPMethod.PUT, HTTPMethod.DELETE, HTTPMethod.PATCH

Response Object (HttpResponse)


API Reference

client.request() Parameters

Parameter
Type
Required
Description

method

str | HTTPMethod

✅ Yes

HTTP method (GET, POST, PUT, DELETE, PATCH)

path

str

✅ Yes

API endpoint path (e.g., "/core/v1/employees")

params

dict[str, Any]

❌ No

Query parameters

headers

dict[str, str]

❌ No

Additional headers

body

Any

❌ No

Request body (sent as JSON)

files

dict[str, Any]

❌ No

Files for multipart uploads

parse_json

bool

❌ No

If True, return parsed dict/list

Returns ​ ​ HttpResponse when parse_json=False (default) ​ dict or list when parse_json=True

Last updated