Skip to content

Instantly share code, notes, and snippets.

@cicku
Last active July 6, 2025 14:22
Show Gist options
  • Select an option

  • Save cicku/3c200b49988c78592bbd2029422d4d5a to your computer and use it in GitHub Desktop.

Select an option

Save cicku/3c200b49988c78592bbd2029422d4d5a to your computer and use it in GitHub Desktop.
Calling Cloudflare API without cloudflare-python
import http.client
conn = http.client.HTTPSConnection("api.cloudflare.com")
# Logpush
payload = "{\n \"dataset\": \"http_requests\",\n \"destination_conf\": \"s3://placeholder/logs/placeholder/{DATE}?region=eu-west-1&access-key-id=placeholderaccesskey&secret-access-key=placeholderkey&endpoint=s3.eu-west-1.amazonaws.com\",\n \"enabled\": false,\n \"kind\": \"\",\n \"max_upload_bytes\": 5000000,\n \"max_upload_interval_seconds\": 30,\n \"max_upload_records\": 1000,\n \"name\": \"Testjobapi\",\n \"output_options\": {\n \"CVE-2021-4428\": false,\n \"batch_prefix\": \"\",\n \"batch_suffix\": \"\",\n \"field_delimiter\": \",\",\n \"field_names\": [\n \"ClientASN\",\n \"ClientCountry\",\n \"ClientDeviceType\",\n \"ClientIP\",\n \"ClientIPClass\",\n \"ClientRequestHost\",\n \"ClientRequestMethod\",\n \"ClientRequestPath\",\n \"ClientRequestURI\",\n \"ClientRequestUserAgent\",\n \"ClientRequestProtocol\",\n \"EdgeEndTimestamp\",\n \"EdgeColoCode\",\n \"EdgeColoID\",\n \"RayID\",\n \"SecurityAction\",\n \"SecurityActions\",\n \"SecurityRuleDescription\",\n \"SecurityRuleID\",\n \"SecurityRuleIDs\",\n \"SecuritySources\",\n ],\n \"output_type\": \"ndjson\",\n \"record_delimiter\": \"\",\n \"record_prefix\": \"{\",\n \"record_suffix\": \"}\\n\",\n \"record_template\": \"\",\n \"sample_rate\": 1,\n \"timestamp_format\": \"unixnano\"\n },\n \"ownership_challenge\\\"\": \"eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4R0NNIiwidHlwIjoiSldUIn0..NKwIneYj-8M2tQb2.7cnczwDOR_Cda5vOHCxI7grXUTmyqtiG4IoOhVX96GzvUtra935b0hDOkACB16bK-E9uaXHXlVH1R2cZxQbfbAuV1iI0RaOXFFtQhlN-CQsUmGslIS-qBxYYk5_HNdkkjBnlHOB2sjGb48-XZV189oDfnPRW4jUhFrYNeTndUdU8-fGPN628dV8dl2gKKMomteDX4v-ms4hcm3iF7GjedP90kwEcPbwlGIVRdLSFER0vTDIjkDsZRO1N-nYkDc4YzP8geBxShvzwT4IIc08X0HnnIWZbCnpaYjsxIjlcfSQJgWg.G_sTCAsAL1UzeZFEPQVKVg\"\n}"
headers = {
'Content-Type': "application/json",
'x-auth-email': <auth-email>,
'x-auth-key': <auth-key>"
}
conn.request("POST", "/client/v4/zones/<zone_ID>/logpush/jobs", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment