Skip to content
Verified

Calling a method

POST or GET, body versus query string, and what the field validator expects.

A method name is part of the URL. Every other input, including an id, is a parameter: a JSON body field on POST, a query string parameter on GET. Both forms reach the same method and return the same envelope.

POST: a JSON body

The normal shape for anything with more than a couple of parameters, or with a nested object or an array.

curl -s https://xuda.ai/cpi/agent_domain_connect \
  -H 'content-type: application/json' \
  -d '{"api_key":"YOUR_API_KEY","domain":"example.com","subdomain":"app"}'
const res = await fetch('https://xuda.ai/cpi/agent_domain_connect', {
  method: 'POST',
  headers: { 'content-type': 'application/json' },
  body: JSON.stringify({
    api_key: 'YOUR_API_KEY',
    domain: 'example.com',
    subdomain: 'app',
  }),
});
const { code, data } = await res.json();
if (code > 0) console.log(data);
import requests

res = requests.post(
    'https://xuda.ai/cpi/agent_domain_connect',
    json={'api_key': 'YOUR_API_KEY', 'domain': 'example.com', 'subdomain': 'app'},
)
body = res.json()
if body['code'] > 0:
    print(body['data'])

GET: a query string

Handy for a quick check from a browser address bar or a curl one-liner. The server parses the query string into the same body the method handler sees, so the rules below matter more here than they do on POST.

cURL
curl -s 'https://xuda.ai/cpi/agent_domain_connect?api_key=YOUR_API_KEY&domain=example.com&subdomain=app'

A field's declared type decides how its query string value is read:

  • string: used as-is.
  • number: run through Number(...).
  • boolean: only the literal string true is read as true. Anything else you pass for a boolean field on GET, including false, is coerced to a truthy 1. If a boolean matters, send it on POST with a real JSON true/false, or simply omit the query parameter to leave it at the method's default.
  • object / array: the value is run through JSON.parse(...), so a nested value on GET has to be one query parameter holding a JSON string (filters=%7B%22status%22%3A%22open%22%7D), not bracket-style query nesting.

Required fields and type errors

A method's fields each carry a mandatory flag and a type. Missing a mandatory field, or sending the wrong type on POST (where nothing is auto-coerced), gets you back a -1 before the method itself ever runs:

json
{ "code": -1, "data": "Error: 'domain' is a mandatory field" }
json
{ "code": -1, "data": "Error: 'domain' is a wrong type" }

The interactive API reference lists every method's fields with their types and mandatory flags, and lets you run a call from the browser to see the exact request it built.

Next