{
  "swagger": "2.0",
  "info": {
    "title": "Fieldify REST API",
    "description": "Reads and adds the files of Fieldify File Fields from outside Jira: list the fields, list the files of a field, get download links, upload a file, import a Jira attachment.",
    "version": "1.0"
  },
  "host": "your-site.atlassian.net",
  "basePath": "/gateway/api/svc/jira/apps/5f2edfae-1945-473f-874e-99fba4a4cba2_9dd13fa4-cc83-4cdd-8e68-459a0fbe97f7",
  "schemes": [
    "https"
  ],
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "tags": [
    {
      "name": "Fieldify"
    }
  ],
  "paths": {
    "/v1/fields": {
      "get": {
        "operationId": "ListFileFields",
        "summary": "List File Fields",
        "description": "Lists the File Fields of Fieldify on the site, so a client can find the customfield_ id. Scopes: read:file-field:custom, read:forge-app:jira.",
        "parameters": [],
        "responses": {
          "200": {
            "description": "File Fields.",
            "schema": {
              "$ref": "#/definitions/FieldsResponse"
            }
          },
          "default": {
            "description": "Error. Fieldify's errors have the body {\"error\":{\"code\",\"message\",\"details\"?}}. Errors from the Atlassian gateway (for example 401, 403, or 424 when a call runs too long) have Atlassian's own body.",
            "schema": {
              "$ref": "#/definitions/Error"
            }
          }
        },
        "tags": [
          "Fieldify"
        ]
      }
    },
    "/v1/files": {
      "get": {
        "operationId": "ListFiles",
        "summary": "List files in a File Field",
        "description": "Returns the current files of one File Field on one work item. Scopes: read:file-field:custom, read:forge-app:jira.",
        "parameters": [
          {
            "name": "issue",
            "in": "query",
            "required": true,
            "type": "string",
            "description": "Work item key (for example SUP-12) or numeric id.",
            "x-ms-summary": "Work item"
          },
          {
            "name": "field",
            "in": "query",
            "required": true,
            "type": "string",
            "description": "File Field id, for example customfield_10123. ListFileFields returns them.",
            "x-ms-summary": "File Field id"
          }
        ],
        "responses": {
          "200": {
            "description": "Current files.",
            "schema": {
              "$ref": "#/definitions/FilesResponse"
            }
          },
          "default": {
            "description": "Error. Fieldify's errors have the body {\"error\":{\"code\",\"message\",\"details\"?}}. Errors from the Atlassian gateway (for example 401, 403, or 424 when a call runs too long) have Atlassian's own body.",
            "schema": {
              "$ref": "#/definitions/Error"
            }
          }
        },
        "tags": [
          "Fieldify"
        ]
      }
    },
    "/v1/files/links": {
      "post": {
        "operationId": "GetDownloadLinks",
        "summary": "Get download links",
        "description": "Returns one-hour public download URLs for 1 to 50 current files of the field. Fetch each URL with a plain GET, without an Authorization header. Scopes: read:file-field:custom, read:forge-app:jira.",
        "parameters": [
          {
            "name": "body",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/LinksRequest"
            },
            "description": "Request body"
          }
        ],
        "responses": {
          "200": {
            "description": "Links. A file that could not be linked is listed in errors or notProcessed.",
            "schema": {
              "$ref": "#/definitions/LinksResponse"
            }
          },
          "default": {
            "description": "Error. Fieldify's errors have the body {\"error\":{\"code\",\"message\",\"details\"?}}. Errors from the Atlassian gateway (for example 401, 403, or 424 when a call runs too long) have Atlassian's own body.",
            "schema": {
              "$ref": "#/definitions/Error"
            }
          }
        },
        "tags": [
          "Fieldify"
        ]
      }
    },
    "/v1/files/upload": {
      "post": {
        "operationId": "UploadFile",
        "summary": "Upload a file (base64)",
        "description": "Adds a file of at most 3,500,000 bytes, sent as base64. A field that takes one file has it replaced; a field that takes several gets the file appended (409 field-full when full). Answers 201 when written, or 200 with mode unchanged when the same name and bytes were already in the field (safe to retry). Answers 409 busy with Retry-After when another API write into the same field is in progress: write into one field one file after another, not in parallel. Scopes: write:file-field:custom, read:forge-app:jira.",
        "parameters": [
          {
            "name": "body",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/UploadRequest"
            },
            "description": "Request body"
          }
        ],
        "responses": {
          "200": {
            "description": "The same name and bytes were already in the field (mode unchanged); nothing changed.",
            "schema": {
              "$ref": "#/definitions/WriteResponse"
            }
          },
          "201": {
            "description": "File written.",
            "schema": {
              "$ref": "#/definitions/WriteResponse"
            }
          },
          "default": {
            "description": "Error. Fieldify's errors have the body {\"error\":{\"code\",\"message\",\"details\"?}}. Errors from the Atlassian gateway (for example 401, 403, or 424 when a call runs too long) have Atlassian's own body.",
            "schema": {
              "$ref": "#/definitions/Error"
            }
          }
        },
        "tags": [
          "Fieldify"
        ]
      }
    },
    "/v1/files/import": {
      "post": {
        "operationId": "ImportAttachment",
        "summary": "Import a Jira attachment",
        "description": "Copies a Jira attachment of the same work item into the field. Meant for files larger than the upload limit: at most 100 MB, and never more than the field's own size limit. Checks run now; the copy is queued and the answer is 202 with a jobId and a statusPath. Poll GetImportStatus. Scopes: write:file-field:custom, read:forge-app:jira.",
        "parameters": [
          {
            "name": "body",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/ImportRequest"
            },
            "description": "Request body"
          }
        ],
        "responses": {
          "202": {
            "description": "Import queued.",
            "schema": {
              "$ref": "#/definitions/ImportJob"
            },
            "headers": {
              "Retry-After": {
                "type": "integer",
                "description": "Seconds to wait before the next poll."
              }
            }
          },
          "default": {
            "description": "Error. Fieldify's errors have the body {\"error\":{\"code\",\"message\",\"details\"?}}. Errors from the Atlassian gateway (for example 401, 403, or 424 when a call runs too long) have Atlassian's own body.",
            "schema": {
              "$ref": "#/definitions/Error"
            }
          }
        },
        "tags": [
          "Fieldify"
        ]
      },
      "get": {
        "operationId": "GetImportStatus",
        "summary": "Get import status",
        "description": "Answers 202 while the import is queued or running (with Retry-After), and 200 once it succeeded or failed (the error object says why; code stalled when it made no progress for 20 minutes). Only the account that started the import can read it. Scopes: write:file-field:custom, read:forge-app:jira.",
        "parameters": [
          {
            "name": "jobId",
            "in": "query",
            "required": true,
            "type": "string",
            "description": "The jobId returned by ImportAttachment.",
            "x-ms-summary": "Job id"
          }
        ],
        "responses": {
          "200": {
            "description": "Finished (status succeeded or failed).",
            "schema": {
              "$ref": "#/definitions/ImportJob"
            }
          },
          "202": {
            "description": "Still queued or running.",
            "schema": {
              "$ref": "#/definitions/ImportJob"
            },
            "headers": {
              "Retry-After": {
                "type": "integer",
                "description": "Seconds to wait before the next poll."
              }
            }
          },
          "default": {
            "description": "Error. Fieldify's errors have the body {\"error\":{\"code\",\"message\",\"details\"?}}. Errors from the Atlassian gateway (for example 401, 403, or 424 when a call runs too long) have Atlassian's own body.",
            "schema": {
              "$ref": "#/definitions/Error"
            }
          }
        },
        "tags": [
          "Fieldify"
        ]
      }
    }
  },
  "definitions": {
    "Error": {
      "type": "object",
      "properties": {
        "error": {
          "type": "object",
          "properties": {
            "code": {
              "type": "string",
              "description": "Machine-readable code.",
              "enum": [
                "bad-request",
                "not-allowed",
                "license-required",
                "field-not-found",
                "issue-not-found",
                "field-not-on-issue",
                "attachment-not-found",
                "job-not-found",
                "foreign-value",
                "field-full",
                "type-not-allowed",
                "file-too-large",
                "empty-file",
                "duplicate",
                "value-full",
                "bad-filename",
                "unknown-category",
                "older-version",
                "payload-too-large",
                "busy",
                "unavailable",
                "unexpected"
              ]
            },
            "message": {
              "type": "string",
              "description": "Readable explanation."
            },
            "details": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "FileField": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "description": "customfield_ id"
        },
        "name": {
          "type": "string"
        }
      }
    },
    "FieldsResponse": {
      "type": "object",
      "properties": {
        "fields": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/FileField"
          }
        }
      }
    },
    "ApiFile": {
      "type": "object",
      "properties": {
        "fileId": {
          "type": "string",
          "description": "Object Store key of the file; GetDownloadLinks takes it."
        },
        "filename": {
          "type": "string",
          "x-nullable": true
        },
        "mimeType": {
          "type": "string",
          "x-nullable": true
        },
        "size": {
          "type": "integer",
          "format": "int64",
          "x-nullable": true,
          "description": "Size in bytes."
        },
        "uploadedAt": {
          "type": "string",
          "x-nullable": true
        },
        "uploadedBy": {
          "type": "string",
          "x-nullable": true
        },
        "category": {
          "type": "string",
          "x-nullable": true
        },
        "versions": {
          "type": "integer",
          "description": "Number of versions; 1 for a file never replaced."
        }
      }
    },
    "IssueRef": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "key": {
          "type": "string"
        }
      }
    },
    "FieldRef": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        }
      }
    },
    "FilesResponse": {
      "type": "object",
      "properties": {
        "issue": {
          "$ref": "#/definitions/IssueRef"
        },
        "field": {
          "$ref": "#/definitions/FieldRef"
        },
        "files": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/ApiFile"
          }
        }
      }
    },
    "LinksRequest": {
      "type": "object",
      "required": [
        "issue",
        "field",
        "fileIds"
      ],
      "properties": {
        "issue": {
          "type": "string",
          "description": "Work item key (for example SUP-12) or numeric id.",
          "title": "Work item"
        },
        "field": {
          "type": "string",
          "description": "File Field id, for example customfield_10123. ListFileFields returns them.",
          "title": "File Field id"
        },
        "fileIds": {
          "type": "array",
          "minItems": 1,
          "maxItems": 50,
          "items": {
            "type": "string"
          },
          "description": "1 to 50 fileId values from ListFiles.",
          "title": "File ids"
        }
      }
    },
    "FileLink": {
      "type": "object",
      "properties": {
        "fileId": {
          "type": "string"
        },
        "filename": {
          "type": "string",
          "x-nullable": true
        },
        "mimeType": {
          "type": "string",
          "x-nullable": true
        },
        "size": {
          "type": "integer",
          "format": "int64",
          "x-nullable": true
        },
        "uploadedAt": {
          "type": "string",
          "x-nullable": true
        },
        "uploadedBy": {
          "type": "string",
          "x-nullable": true
        },
        "category": {
          "type": "string",
          "x-nullable": true
        },
        "versions": {
          "type": "integer"
        },
        "url": {
          "type": "string",
          "description": "One-hour public download URL. Do not log or share it."
        },
        "expiresAt": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "LinkError": {
      "type": "object",
      "properties": {
        "fileId": {
          "type": "string"
        },
        "code": {
          "type": "string",
          "description": "not-in-field or mint-failed."
        },
        "message": {
          "type": "string"
        },
        "retryable": {
          "type": "boolean"
        }
      }
    },
    "LinksResponse": {
      "type": "object",
      "properties": {
        "links": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/FileLink"
          }
        },
        "errors": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/LinkError"
          }
        },
        "notProcessed": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "File ids not started because the time budget ran out; send them again."
        }
      }
    },
    "UploadRequest": {
      "type": "object",
      "required": [
        "issue",
        "field",
        "filename",
        "contentBase64"
      ],
      "properties": {
        "issue": {
          "type": "string",
          "description": "Work item key (for example SUP-12) or numeric id.",
          "title": "Work item"
        },
        "field": {
          "type": "string",
          "description": "File Field id, for example customfield_10123. ListFileFields returns them.",
          "title": "File Field id"
        },
        "filename": {
          "type": "string",
          "description": "File name with extension.",
          "title": "File name"
        },
        "mimeType": {
          "type": "string",
          "description": "Optional MIME type, for example application/pdf.",
          "title": "MIME type"
        },
        "contentBase64": {
          "type": "string",
          "description": "File content in standard base64, no data: prefix, no line breaks. At most 3,500,000 bytes decoded.",
          "title": "Content (base64)"
        },
        "category": {
          "type": "string",
          "description": "Optional category defined on the field.",
          "title": "Category"
        }
      }
    },
    "WriteResponse": {
      "type": "object",
      "properties": {
        "issue": {
          "$ref": "#/definitions/IssueRef"
        },
        "field": {
          "$ref": "#/definitions/FieldRef"
        },
        "mode": {
          "type": "string",
          "enum": [
            "replaced",
            "appended",
            "unchanged"
          ],
          "description": "replaced for a one-file field, appended otherwise; unchanged when the same name and bytes were already a current file (a retry)."
        },
        "file": {
          "$ref": "#/definitions/ApiFile"
        },
        "replacedFileIds": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "files": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/ApiFile"
          },
          "description": "All current files after the write."
        }
      }
    },
    "ImportRequest": {
      "type": "object",
      "required": [
        "issue",
        "field",
        "attachmentId"
      ],
      "properties": {
        "issue": {
          "type": "string",
          "description": "Work item key (for example SUP-12) or numeric id.",
          "title": "Work item"
        },
        "field": {
          "type": "string",
          "description": "File Field id, for example customfield_10123. ListFileFields returns them.",
          "title": "File Field id"
        },
        "attachmentId": {
          "type": "string",
          "description": "Id of a Jira attachment on that work item.",
          "title": "Attachment id"
        },
        "category": {
          "type": "string",
          "description": "Optional category defined on the field.",
          "title": "Category"
        }
      }
    },
    "ImportError": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        },
        "details": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "ImportResult": {
      "type": "object",
      "properties": {
        "mode": {
          "type": "string",
          "enum": [
            "replaced",
            "appended",
            "unchanged"
          ],
          "description": "unchanged when the same name and bytes were already a current file."
        },
        "file": {
          "$ref": "#/definitions/ApiFile"
        },
        "replacedFileIds": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "ImportJob": {
      "type": "object",
      "properties": {
        "jobId": {
          "type": "string"
        },
        "status": {
          "type": "string",
          "enum": [
            "queued",
            "running",
            "succeeded",
            "failed"
          ]
        },
        "issue": {
          "$ref": "#/definitions/IssueRef"
        },
        "field": {
          "$ref": "#/definitions/FieldRef"
        },
        "attachmentId": {
          "type": "string"
        },
        "createdAt": {
          "type": "string",
          "format": "date-time"
        },
        "updatedAt": {
          "type": "string",
          "format": "date-time"
        },
        "result": {
          "$ref": "#/definitions/ImportResult"
        },
        "error": {
          "$ref": "#/definitions/ImportError"
        },
        "statusPath": {
          "type": "string",
          "description": "The GetImportStatus path for this job, relative to the base URL. Only in the 202 of ImportAttachment."
        },
        "retryAfterSeconds": {
          "type": "integer",
          "description": "Only in 202 answers."
        }
      }
    }
  },
  "securityDefinitions": {
    "bearer": {
      "type": "apiKey",
      "in": "header",
      "name": "Authorization",
      "description": "Send \"Bearer <access token>\". The token comes from your own OAuth 2.0 (3LO) integration in the Developer Console: start the consent from the URL that the integration's Authorization URL generator gives for Fieldify (it carries the sns parameter); a token from a URL without sns is refused with 403. See https://www.teranoapps.com/file-field/docs/usage/rest-api. Each operation's description lists the scopes it needs."
    }
  },
  "security": [
    {
      "bearer": []
    }
  ]
}
