Form Files

Form Files allow you to attach supporting documents to your forms in Forms Live. On this page, we'll dive into the different form file endpoints you can use to manage file attachments programmatically. We'll look at how to list, create, update, download, and delete form files.

The form file model

The form file model contains all the information about files attached to forms, such as the filename, content type, and their ordering index. These files can be made available as attachments when printing forms.

Properties

  • Name
    id
    Type
    integer
    Description

    Unique identifier for the form file.

  • Name
    form_id
    Type
    integer
    Description

    Unique identifier for the form the file belongs to.

  • Name
    user_id
    Type
    integer
    Description

    Unique identifier for the user that created the file.

  • Name
    filename
    Type
    string
    Description

    The filename of the original file.

  • Name
    content_type
    Type
    string
    Description

    The MIME type of the file.

  • Name
    attachment
    Type
    boolean
    Description

    Indicates if the file should be attached when printing.

  • Name
    deleted
    Type
    boolean
    Description

    Indicates if the file has been deleted.

  • Name
    index
    Type
    integer
    Description

    The index/order of the file.

  • Name
    created
    Type
    timestamp
    Description

    Timestamp of when the file was created.

  • Name
    updated
    Type
    timestamp
    Description

    Timestamp of when the file was last updated.


GET/forms/:form_id/files

List form files

This endpoint allows you to retrieve a list of all files attached to a specific form.

Optional attributes

  • Name
    attachments
    Type
    boolean
    Description

    If set to true, only returns files that can be attached when printed. Default is false.

Request

GET
/forms/:form_id/files
curl https://app-api.reiformslive.com.au/forms/1/files \
  --request GET \
  --header "Authorization: Basic YTlkOWIwYItNGY4Yi1hYTQxLTI5NzZmMTcyZmEyMQ=="

Response

[
  {
    "id": 1,
    "form_id": 1,
    "user_id": 1,
    "filename": "Test.pdf",
    "content_type": "application/pdf",
    "attachment": true,
    "deleted": false,
    "created": "1506294669",
    "updated": "1506294669",
    "index": 1
  },
  {
    "id": 2,
    // ...
  }
]

POST/forms/:form_id/files

Create a form file

This endpoint allows you to upload a new file attachment to a specific form.

Required attributes

  • Name
    filename
    Type
    string
    Description

    The original filename of the file.

  • Name
    data
    Type
    string
    Description

    The contents of the file base64 encoded in Data URI scheme.

Request

POST
/forms/:form_id/files
curl https://app-api.reiformslive.com.au/forms/1/files \
  --request POST \
  --header "content-type: application/json" \
  --header "Authorization: Basic YTlkOWIwYItNGY4Yi1hYTQxLTI5NzZmMTcyZmEyMQ==" \
  --data '{"filename": "Example Form", "data": "data:application/pdf;base64,R0lGODdh"}'

Response

{
  "id": 1,
  "form_id": 1,
  "user_id": 1,
  "filename": "Test.pdf",
  "content_type": "application/pdf",
  "attachment": true,
  "deleted": false,
  "created": "1506294669",
  "updated": "1506294669",
  "index": 1
}

PUT/forms/:form_id/files/:file_id

Update a form file

This endpoint allows you to update the index/order of a form file. Note that the file contents or filename cannot be changed.

Required attributes

  • Name
    index
    Type
    integer
    Description

    The new index/order for the file.

Request

PUT
/forms/:form_id/files/:file_id
curl https://app-api.reiformslive.com.au/forms/1/files/1 \
  --request PUT \
  --header "content-type: application/json" \
  --header "Authorization: Basic YTlkOWIwYItNGY4Yi1hYTQxLTI5NzZmMTcyZmEyMQ==" \
  --data '{"index": 2}'
// Returns 204 No Content on success

GET/forms/:form_id/files/:file_id

Download a form file

This endpoint allows you to download a specific form file by providing the form ID and file ID.

Request

GET
/forms/:form_id/files/:file_id
curl https://app-api.reiformslive.com.au/forms/1/files/1 \
  --request GET \
  --header "Authorization: Basic YTlkOWIwYItNGY4Yi1hYTQxLTI5NzZmMTcyZmEyMQ==" \
  --output "downloaded_file.pdf"
// Returns the file as a binary download

DELETE/forms/:form_id/files/:file_id

Delete a form file

This endpoint allows you to delete a specific form file by providing the form ID and file ID.

Request

DELETE
/forms/:form_id/files/:file_id
curl https://app-api.reiformslive.com.au/forms/1/files/1 \
  --request DELETE \
  --header "content-type: application/json" \
  --header "Authorization: Basic YTlkOWIwYItNGY4Yi1hYTQxLTI5NzZmMTcyZmEyMQ=="

Response

{
  "message": "The file was successfully deleted."
}

Was this page helpful?