Skip to content

Code examples

Each example is a file in examples/, and CI runs it against the live development API. If the API changes in a way that breaks an example, the docs build fails.

Storefront: read the business and list products

Section titled “Storefront: read the business and list products”

Uses the public demo publishable key. Safe to run anywhere.

examples/curl/storefront.sh
#!/usr/bin/env bash
# Storefront API: read the business, then list three products with prices. Needs only curl.
set -euo pipefail
API="${SEDRA_API_URL:-https://api.sedra.one}"
PK="${SEDRA_PUBLISHABLE_KEY:-pk_ccc8aa9718ae70bac46d4c9172f8cb3a5e8faf0dc521c30248239725d12ca241}" # public demo key
curl -fsS "$API/store/foulad/tenant" -H "x-publishable-api-key: $PK"
echo
REGION=$(curl -fsS "$API/store/foulad/tenant" -H "x-publishable-api-key: $PK" | sed -E 's/.*"region_id":"([^"]+)".*/\1/')
curl -fsS "$API/store/products?limit=3&region_id=$REGION&fields=id,title,handle,*variants.calculated_price" -H "x-publishable-api-key: $PK"
echo

Expected output:

Foulad Store
- GaN Charger 65W: 12.500 BHD
- Power Bank 20,000 mAh: 15.750 BHD
- USB-C Cable 2 m: 3.250 BHD

Merchant Agent API: who am I, and search products

Section titled “Merchant Agent API: who am I, and search products”
examples/curl/agent.sh
#!/usr/bin/env bash
# Merchant Agent API (server-side only). Needs SEDRA_API_KEY (sdr_int_… or sdr_ai_…) and SEDRA_TENANT.
set -euo pipefail
API="${SEDRA_API_URL:-https://api.sedra.one}"
: "${SEDRA_API_KEY:?set SEDRA_API_KEY}" "${SEDRA_TENANT:?set SEDRA_TENANT, e.g. midad-store}"
curl -fsS -X POST "$API/foulad/agent/invoke/platform.whoami" \
-H "Authorization: Bearer $SEDRA_API_KEY" -H "content-type: application/json" -d '{}'
echo
curl -fsS -X POST "$API/foulad/agent/invoke/catalog.products.search" \
-H "Authorization: Bearer $SEDRA_API_KEY" -H "content-type: application/json" \
-d "{\"tenant\":\"$SEDRA_TENANT\",\"input\":{\"limit\":3}}"
echo
Example cURL TypeScript (Node 22) Python 3.9 Swift 6 (macOS)
Storefront Tested Tested Tested Tested
Agent (read-only credential) Tested Tested Tested –

The Swift example targets iOS 15+ and macOS 12+ and uses only Foundation.