Requests and responses

How to call a method, what to put in the body, and the envelope every answer comes back in.

On this page

Every method is called the same way, and every answer has the same shape, so one small helper in your code can call all of them.

The request

Part Value
Method POST
Address https://api.modulify.ai/v1/ followed by the method name, such as /v1/list_sites
Authorization header Bearer and your token. See Authentication
Body A JSON object of the method's arguments

The arguments are exactly the ones on the method's page, with the same names and types. A few rules apply to every method:

  • An empty body means no arguments. list_workspaces takes none, so it can be called with no body at all.
  • The body must be a JSON object. An array, a string or broken JSON is refused with a 400.
  • No Content-Type is needed. The body is read as JSON whatever the header says, so curl -d works as it is. Sending Content-Type: application/json is still good practice.
  • Unknown arguments are refused. A name the method does not take comes back as a 400 naming it, rather than being ignored, so a typo never goes unnoticed.
  • Leave out what you do not need. Every argument a method does not list as required can be omitted, and each page says what happens when it is.
  • The whole body can be up to 100 MB. A larger body is refused with a 413 before any method runs, in the usual envelope. A body far over the limit can be cut off before it reaches Modulify, and that 413 has no JSON body, so check the status code rather than the body. Methods that take a file, such as upload_storage_file, take its bytes base64 encoded in a string argument, about a third larger than the file itself, so a file sent this way can be at most about three quarters of the body limit. Each also sets its own limit on the file, stated on its page.

Examples

The same call in three languages. It lists the sites of one workspace.

curl -X POST https://api.modulify.ai/v1/list_sites \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"workspaceId":"WORKSPACE_ID","offset":0}'
const response = await fetch('https://api.modulify.ai/v1/list_sites', {
    method: 'POST',
    headers: {
        Authorization: `Bearer ${process.env.MODULIFY_TOKEN}`,
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({ workspaceId: 'WORKSPACE_ID', offset: 0 })
})

const result = await response.json()

if (!result.success) throw new Error(`${result.code}: ${result.message}`)

console.log(result.count, result.data)
import os
import requests

response = requests.post(
    'https://api.modulify.ai/v1/list_sites',
    headers={'Authorization': f"Bearer {os.environ['MODULIFY_TOKEN']}"},
    json={'workspaceId': 'WORKSPACE_ID', 'offset': 0},
    timeout=60
)

result = response.json()

if not result['success']:
    raise RuntimeError(f"{result['code']}: {result['message']}")

print(result.get('count'), result['data'])

The response

Every answer is a JSON object with the same fields, whether the call worked or not:

{
  "success": true,
  "message": "Projects were listed successfully.",
  "data": [
    { "_id": "6710f0c2a1b2c3d4e5f60718", "Name": "Lisbon Pottery Studio" }
  ],
  "code": 200,
  "version": "0.0.1740",
  "count": 14
}
Field What it holds
success true when the method did what it was asked, false otherwise
message What happened, in plain English. Errors end with !
data The result. Its shape depends on the method, and each method's page describes it. null when there is nothing to return
count On methods that list things, the total number of items, not just the ones on this page
code The HTTP status code, repeated in the body
version The version of the Modulify server that answered

A success answers 200, or 201 from a method that creates something, such as create_comment, or 202 from one that accepts work that finishes later, such as send_message when the message waits in the queue or create_storage_backup. Treat every 2xx status as a success.

Check success, or the HTTP status, before reading data. A refusal can still carry details in data, such as the reason a site could not be created. See Errors.

Results come back in full. Unlike MCP, where a long result is cut to fit a model, the API returns the whole of data however large it is.

New fields can appear in data at any time, so ignore the ones you do not use rather than failing on them. See Versioning.

Headers on every method call

Header What it holds
X-Request-Id The id of this call in Modulify's records. Quote it when you ask for help. Sent whenever the call is logged, which is every call that reached the method except repeated refusals for going over the per-minute budget: only the first of those in a window is logged
X-RateLimit-Limit How many calls the token may make in a minute
X-RateLimit-Remaining How many are left in the token's current one-minute window
X-RateLimit-Reset Seconds until that window ends

These come with every call that reached the method, including one it refused, such as a missing scope or a wrong argument. A request stopped before that carries none of them: a missing or bad token, an unknown method, a body that is too large or not a JSON object, a bad Idempotency-Key on a method that changes something, or an Idempotency-Key that is still running or was used for something else.

Retry-After is added when a call is refused for going over the per-minute budget, and when a method refuses it with a wait of its own, such as a quota on the work that says how long to wait. When an Idempotency-Key decided the answer, Idempotency-Status says how: replayed for a stored answer, which also carries Idempotency-Replayed: true, running on a 409 and mismatch on a 422. A replayed answer has no X-Request-Id or rate limit headers, because the method did not run again. See Idempotency and retries. Every answer to a request that needs a token, refusals included, is sent with Cache-Control: no-store, so nothing in between keeps a copy.

The API answers browsers from any website, without cookies, and lets a page's code read every header above and send Idempotency-Key. That does not make a token safe in a web page, where anyone who opens it can read it. See Security.

Three requests that are not methods

Request What it does Token
GET /v1/token Describes the token: name, scopes, workspaces, sites, expiry, whether it is deleted at expiry, and this minute's budget Required, no scope needed
GET /v1/tools Lists the methods the token can use, each with its arguments as a JSON Schema Required
GET /v1/openapi.json Describes every method in OpenAPI 3.1 Not needed

Calling a method's address with GET instead of POST goes through the same token check first, so it answers 401 without a valid token. With one, it is refused with a 405 and an Allow: POST header, or a 404 when the name is not a method.

Next

  • Errors for every status code.
  • Pagination for methods that return a page at a time.