{
  "openapi": "3.1.0",
  "info": {
    "title": "Fieldproxy REST API",
    "version": "1.0",
    "description": "Read and write a Fieldproxy workspace's data. Every call is a POST with a JSON body to the workspace's regional API base, with an x-api-key header. Keys are created in Settings, Security, API keys with an expiry (24h, 7d, 30d, 90d, 1 year or never), operations (read, insert, update, delete) and an optional table allowlist. Find the base URL with POST https://api.fieldproxy.ai/auth/org {\"orgid\": \"<workspace id>\"} -> settings.url. Responses carry X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset headers. Writes fire the workspace's automations.",
    "contact": {
      "name": "Fieldproxy",
      "url": "https://www.fieldproxy.ai/developers"
    }
  },
  "externalDocs": {
    "url": "https://www.fieldproxy.ai/developers/docs/rest-api"
  },
  "servers": [
    {
      "url": "https://api-india-1.fieldproxy.ai",
      "description": "India"
    },
    {
      "url": "https://api-us-east-1.fieldproxy.ai",
      "description": "US East"
    },
    {
      "url": "https://{apiHost}",
      "description": "Your workspace's regional API host",
      "variables": {
        "apiHost": {
          "default": "api-india-1.fieldproxy.ai"
        }
      }
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      }
    },
    "schemas": {
      "WriteResult": {
        "type": "object",
        "required": [
          "message",
          "rowCount",
          "table",
          "tenant"
        ],
        "properties": {
          "message": {
            "type": "string"
          },
          "rowCount": {
            "type": "integer"
          },
          "table": {
            "type": "string"
          },
          "tenant": {
            "type": "string",
            "description": "The workspace id."
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "message"
        ],
        "properties": {
          "message": {
            "type": "string"
          },
          "error": {
            "type": "string",
            "description": "Database error text (read, update and delete failures)."
          },
          "pgCode": {
            "type": "string",
            "description": "Postgres error code (insert failures)."
          },
          "column": {
            "type": "string"
          },
          "detail": {
            "type": "string"
          },
          "note": {
            "type": "string"
          },
          "table": {
            "type": "string"
          },
          "tenant": {
            "type": "string"
          },
          "expectedColumns": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "rowErrors": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        }
      }
    }
  },
  "paths": {
    "/api/read": {
      "post": {
        "summary": "Read rows",
        "description": "Returns every row matching condition, all columns. No paging, column selection or sorting; extra keys are ignored.",
        "operationId": "read_rows",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "tableName",
                  "condition"
                ],
                "properties": {
                  "tableName": {
                    "type": "string",
                    "pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$",
                    "description": "The table. Must be on the key's table allowlist if it has one."
                  },
                  "condition": {
                    "type": "object",
                    "minProperties": 1,
                    "additionalProperties": {
                      "type": [
                        "string",
                        "number",
                        "boolean"
                      ]
                    },
                    "description": "Column-value pairs; every pair must match by equality (AND). No operators, lists, patterns or null matching. Must not be empty."
                  }
                }
              },
              "examples": {
                "generic": {
                  "summary": "Any table",
                  "value": {
                    "tableName": "your_table",
                    "condition": {
                      "id": 1
                    }
                  }
                },
                "technician_jobs": {
                  "summary": "A technician's assigned jobs",
                  "value": {
                    "tableName": "jobs",
                    "condition": {
                      "status": "assigned",
                      "technician_id": 42
                    }
                  }
                },
                "unpaid_invoices": {
                  "summary": "Unpaid invoices",
                  "value": {
                    "tableName": "invoices",
                    "condition": {
                      "status": "unpaid"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Matching rows.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "rowCount",
                    "table",
                    "tenant"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": true,
                        "description": "Column names to values."
                      }
                    },
                    "rowCount": {
                      "type": "integer"
                    },
                    "table": {
                      "type": "string"
                    },
                    "tenant": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid body (see message).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No x-api-key header: {\"message\": \"Authentication required\"}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Unknown key (\"Invalid token\"), revoked key (\"API key has been revoked\"), or table not on the allowlist (\"API key is not authorized for table '<name>'\").",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown column or a value the column cannot hold: {\"message\": \"Read failed\", \"error\": \"...\"}"
          }
        },
        "tags": [
          "Records"
        ],
        "externalDocs": {
          "description": "Step-by-step guide",
          "url": "https://www.fieldproxy.ai/developers/guides/read-jobs"
        },
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "curl",
            "source": "curl -X POST https://api-india-1.fieldproxy.ai/api/read \\\n  -H \"x-api-key: $FIELDPROXY_API_KEY\" \\\n  -H \"content-type: application/json\" \\\n  -d '{\"tableName\":\"jobs\",\"condition\":{\"status\":\"assigned\",\"technician_id\":42}}'"
          },
          {
            "lang": "JavaScript",
            "label": "Node.js",
            "source": "// Node.js 18+ (built-in fetch)\nconst res = await fetch(\"https://api-india-1.fieldproxy.ai/api/read\", {\n  method: \"POST\",\n  headers: { \"x-api-key\": process.env.FIELDPROXY_API_KEY, \"content-type\": \"application/json\" },\n  body: JSON.stringify({\n    \"tableName\": \"jobs\",\n    \"condition\": {\n      \"status\": \"assigned\",\n      \"technician_id\": 42\n    }\n  }),\n})\nconst out = await res.json()\nif (!res.ok) throw new Error(out.message)\nconsole.log(out.rowCount, out.data)"
          },
          {
            "lang": "Python",
            "label": "Python",
            "source": "# Python 3 (pip install requests)\nimport os, requests\n\nres = requests.post(\n    \"https://api-india-1.fieldproxy.ai/api/read\",\n    headers={\"x-api-key\": os.environ[\"FIELDPROXY_API_KEY\"]},\n    json={\n      \"tableName\": \"jobs\",\n      \"condition\": {\n        \"status\": \"assigned\",\n        \"technician_id\": 42\n      }\n    },\n    timeout=30,\n)\nout = res.json()\nres.raise_for_status()\nprint(out[\"rowCount\"], out[\"data\"])"
          }
        ]
      }
    },
    "/api/insert": {
      "post": {
        "summary": "Insert rows",
        "description": "Inserts all rows in one atomic INSERT: if any row fails, none are inserted. Every row must have the same keys as the first. Omitted columns take database defaults. New rows are not returned.",
        "operationId": "insert_rows",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "tableName",
                  "data"
                ],
                "properties": {
                  "tableName": {
                    "type": "string",
                    "pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$",
                    "description": "The table. Must be on the key's table allowlist if it has one."
                  },
                  "data": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "object",
                      "additionalProperties": true,
                      "description": "Column names to values."
                    }
                  }
                }
              },
              "examples": {
                "generic": {
                  "summary": "Any table",
                  "value": {
                    "tableName": "your_table",
                    "data": [
                      {
                        "name": "Gamma",
                        "status": "open",
                        "qty": 1
                      },
                      {
                        "name": "Delta",
                        "status": "closed",
                        "qty": 9
                      }
                    ]
                  }
                },
                "create_job": {
                  "summary": "Create a job from another system",
                  "value": {
                    "tableName": "jobs",
                    "data": [
                      {
                        "title": "No cooling, unit 4B",
                        "status": "new",
                        "priority": "urgent",
                        "customer_id": 1187,
                        "external_ref": "CRM-55120"
                      }
                    ]
                  }
                },
                "load_customers": {
                  "summary": "Bulk load customers (all or nothing)",
                  "value": {
                    "tableName": "customers",
                    "data": [
                      {
                        "company_name": "Northfield Dental",
                        "phone": "+15550101"
                      },
                      {
                        "company_name": "Riverside Bakery",
                        "phone": "+15550102"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "\"Successfully inserted N rows into <table>\"",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WriteResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid body (see message).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No x-api-key header: {\"message\": \"Authentication required\"}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Unknown key (\"Invalid token\"), revoked key (\"API key has been revoked\"), or table not on the allowlist (\"API key is not authorized for table '<name>'\").",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Records"
        ],
        "externalDocs": {
          "description": "Step-by-step guide",
          "url": "https://www.fieldproxy.ai/developers/guides/create-a-job"
        },
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "curl",
            "source": "curl -X POST https://api-india-1.fieldproxy.ai/api/insert \\\n  -H \"x-api-key: $FIELDPROXY_API_KEY\" \\\n  -H \"content-type: application/json\" \\\n  -d '{\"tableName\":\"jobs\",\"data\":[{\"title\":\"No cooling, unit 4B\",\"status\":\"new\",\"priority\":\"urgent\",\"customer_id\":1187,\"external_ref\":\"CRM-55120\"}]}'"
          },
          {
            "lang": "JavaScript",
            "label": "Node.js",
            "source": "// Node.js 18+ (built-in fetch)\nconst res = await fetch(\"https://api-india-1.fieldproxy.ai/api/insert\", {\n  method: \"POST\",\n  headers: { \"x-api-key\": process.env.FIELDPROXY_API_KEY, \"content-type\": \"application/json\" },\n  body: JSON.stringify({\n    \"tableName\": \"jobs\",\n    \"data\": [\n      {\n        \"title\": \"No cooling, unit 4B\",\n        \"status\": \"new\",\n        \"priority\": \"urgent\",\n        \"customer_id\": 1187,\n        \"external_ref\": \"CRM-55120\"\n      }\n    ]\n  }),\n})\nconst out = await res.json()\nif (!res.ok) throw new Error(out.message)\nconsole.log(out.rowCount)"
          },
          {
            "lang": "Python",
            "label": "Python",
            "source": "# Python 3 (pip install requests)\nimport os, requests\n\nres = requests.post(\n    \"https://api-india-1.fieldproxy.ai/api/insert\",\n    headers={\"x-api-key\": os.environ[\"FIELDPROXY_API_KEY\"]},\n    json={\n      \"tableName\": \"jobs\",\n      \"data\": [\n        {\n          \"title\": \"No cooling, unit 4B\",\n          \"status\": \"new\",\n          \"priority\": \"urgent\",\n          \"customer_id\": 1187,\n          \"external_ref\": \"CRM-55120\"\n        }\n      ]\n    },\n    timeout=30,\n)\nout = res.json()\nres.raise_for_status()\nprint(out[\"rowCount\"])"
          }
        ]
      }
    },
    "/api/update": {
      "post": {
        "summary": "Update rows",
        "description": "Sets data on every row matching condition. No match returns 200 with rowCount 0. Each changed row fires the workspace's automations.",
        "operationId": "update_rows",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "tableName",
                  "condition",
                  "data"
                ],
                "properties": {
                  "tableName": {
                    "type": "string",
                    "pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$",
                    "description": "The table. Must be on the key's table allowlist if it has one."
                  },
                  "condition": {
                    "type": "object",
                    "minProperties": 1,
                    "additionalProperties": {
                      "type": [
                        "string",
                        "number",
                        "boolean"
                      ]
                    },
                    "description": "Column-value pairs; every pair must match by equality (AND). No operators, lists, patterns or null matching. Must not be empty."
                  },
                  "data": {
                    "type": "object",
                    "additionalProperties": true,
                    "description": "Columns to set (one object, not an array).",
                    "minProperties": 1
                  }
                }
              },
              "examples": {
                "generic": {
                  "summary": "Any table",
                  "value": {
                    "tableName": "your_table",
                    "condition": {
                      "status": "open"
                    },
                    "data": {
                      "status": "closed",
                      "qty": 7
                    }
                  }
                },
                "complete_job": {
                  "summary": "Mark a job completed (fires status_transition automations)",
                  "value": {
                    "tableName": "jobs",
                    "condition": {
                      "id": 1042
                    },
                    "data": {
                      "status": "completed"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "\"Update successful\"",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WriteResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid body (see message).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No x-api-key header: {\"message\": \"Authentication required\"}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Unknown key (\"Invalid token\"), revoked key (\"API key has been revoked\"), or table not on the allowlist (\"API key is not authorized for table '<name>'\").",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown column or constraint violation: {\"message\": \"Update failed\", \"error\": \"...\"}"
          }
        },
        "tags": [
          "Records"
        ],
        "externalDocs": {
          "description": "Step-by-step guide",
          "url": "https://www.fieldproxy.ai/developers/guides/update-job-status"
        },
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "curl",
            "source": "curl -X POST https://api-india-1.fieldproxy.ai/api/update \\\n  -H \"x-api-key: $FIELDPROXY_API_KEY\" \\\n  -H \"content-type: application/json\" \\\n  -d '{\"tableName\":\"jobs\",\"condition\":{\"id\":1042},\"data\":{\"status\":\"completed\"}}'"
          },
          {
            "lang": "JavaScript",
            "label": "Node.js",
            "source": "// Node.js 18+ (built-in fetch)\nconst res = await fetch(\"https://api-india-1.fieldproxy.ai/api/update\", {\n  method: \"POST\",\n  headers: { \"x-api-key\": process.env.FIELDPROXY_API_KEY, \"content-type\": \"application/json\" },\n  body: JSON.stringify({\n    \"tableName\": \"jobs\",\n    \"condition\": {\n      \"id\": 1042\n    },\n    \"data\": {\n      \"status\": \"completed\"\n    }\n  }),\n})\nconst out = await res.json()\nif (!res.ok) throw new Error(out.message)\nconsole.log(out.rowCount)"
          },
          {
            "lang": "Python",
            "label": "Python",
            "source": "# Python 3 (pip install requests)\nimport os, requests\n\nres = requests.post(\n    \"https://api-india-1.fieldproxy.ai/api/update\",\n    headers={\"x-api-key\": os.environ[\"FIELDPROXY_API_KEY\"]},\n    json={\n      \"tableName\": \"jobs\",\n      \"condition\": {\n        \"id\": 1042\n      },\n      \"data\": {\n        \"status\": \"completed\"\n      }\n    },\n    timeout=30,\n)\nout = res.json()\nres.raise_for_status()\nprint(out[\"rowCount\"])"
          }
        ]
      }
    },
    "/api/delete": {
      "post": {
        "summary": "Delete rows",
        "description": "Deletes every row matching condition. No match returns 200 with rowCount 0.",
        "operationId": "delete_rows",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "tableName",
                  "condition"
                ],
                "properties": {
                  "tableName": {
                    "type": "string",
                    "pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$",
                    "description": "The table. Must be on the key's table allowlist if it has one."
                  },
                  "condition": {
                    "type": "object",
                    "minProperties": 1,
                    "additionalProperties": {
                      "type": [
                        "string",
                        "number",
                        "boolean"
                      ]
                    },
                    "description": "Column-value pairs; every pair must match by equality (AND). No operators, lists, patterns or null matching. Must not be empty."
                  }
                }
              },
              "examples": {
                "generic": {
                  "summary": "Any table",
                  "value": {
                    "tableName": "your_table",
                    "condition": {
                      "id": 2
                    }
                  }
                },
                "delete_draft": {
                  "summary": "Delete one record by id",
                  "value": {
                    "tableName": "service_requests",
                    "condition": {
                      "id": 2077
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "\"Delete successful\"",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WriteResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid body (see message).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "No x-api-key header: {\"message\": \"Authentication required\"}",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Unknown key (\"Invalid token\"), revoked key (\"API key has been revoked\"), or table not on the allowlist (\"API key is not authorized for table '<name>'\").",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Unknown column: {\"message\": \"Delete failed\", \"error\": \"...\"}"
          }
        },
        "tags": [
          "Records"
        ],
        "externalDocs": {
          "description": "Step-by-step guide",
          "url": "https://www.fieldproxy.ai/developers/guides/read-jobs"
        },
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "curl",
            "source": "curl -X POST https://api-india-1.fieldproxy.ai/api/delete \\\n  -H \"x-api-key: $FIELDPROXY_API_KEY\" \\\n  -H \"content-type: application/json\" \\\n  -d '{\"tableName\":\"service_requests\",\"condition\":{\"id\":2077}}'"
          },
          {
            "lang": "JavaScript",
            "label": "Node.js",
            "source": "// Node.js 18+ (built-in fetch)\nconst res = await fetch(\"https://api-india-1.fieldproxy.ai/api/delete\", {\n  method: \"POST\",\n  headers: { \"x-api-key\": process.env.FIELDPROXY_API_KEY, \"content-type\": \"application/json\" },\n  body: JSON.stringify({\n    \"tableName\": \"service_requests\",\n    \"condition\": {\n      \"id\": 2077\n    }\n  }),\n})\nconst out = await res.json()\nif (!res.ok) throw new Error(out.message)\nconsole.log(out.rowCount)"
          },
          {
            "lang": "Python",
            "label": "Python",
            "source": "# Python 3 (pip install requests)\nimport os, requests\n\nres = requests.post(\n    \"https://api-india-1.fieldproxy.ai/api/delete\",\n    headers={\"x-api-key\": os.environ[\"FIELDPROXY_API_KEY\"]},\n    json={\n      \"tableName\": \"service_requests\",\n      \"condition\": {\n        \"id\": 2077\n      }\n    },\n    timeout=30,\n)\nout = res.json()\nres.raise_for_status()\nprint(out[\"rowCount\"])"
          }
        ]
      }
    }
  }
}