Attachments API

creates a text attachment and its text constructor

POST /api/v1/attachments/

Parameters

Name Description
attachable_id the id of the object this should be attached to (Lecture/Course)
attachable_type type of the object (Lecture/Course)
file a filepicker file blob {url:, filename:, mimetype:, size:, key:,container:}
text the contents of a text/html attachment
text_constructor_attributes text constructor attributes
kind the attachment kind

Request

Headers

Accept: application/json
X-Api-Token: aeytMEzdA1k4Ks_qo4KJCQ_7zUpK9yc-Yw
X-Api-Email: user-358@example.com

Route

POST /api/v1/attachments/

Body

{"attachable_id":49,"attachable_type":"Lecture","text_constructor_attributes":{"constructor":{"ops":[{"insert":"Hello"},{"insert":"World","attributes":{"bold":true}},{"insert":{"image":"https://exclamation.com/mark.png"},"attributes":{"width":"100"}}]}},"kind":"text"}

cURL

curl "http://localhost:3000/api/v1/attachments/" -d '{"attachable_id":49,"attachable_type":"Lecture","text_constructor_attributes":{"constructor":{"ops":[{"insert":"Hello"},{"insert":"World","attributes":{"bold":true}},{"insert":{"image":"https://exclamation.com/mark.png"},"attributes":{"width":"100"}}]}},"kind":"text"}' -X POST \
	-H "Accept: application/json" \
	-H "X-Api-Token: aeytMEzdA1k4Ks_qo4KJCQ_7zUpK9yc-Yw" \
	-H "X-Api-Email: user-358@example.com" \
	-H "Content-Type: application/json" \
	-H "Host: school.worksonmy.computer"

Response

Headers

Content-Type: application/json; charset=utf-8
Content-Length: 886

Status

201 Created

Body

{
  "created_at": "2019-10-31T22:01:17Z",
  "code_syntax": null,
  "content_type": null,
  "audio_type": null,
  "should_be_uploaded_to_wistia?": false,
  "data": null,
  "schema": null,
  "text_constructor": {
    "id": 2,
    "constructor": {
      "ops": [
        {
          "insert": "Hello"
        },
        {
          "insert": "World",
          "attributes": {
            "bold": true
          }
        },
        {
          "insert": {
            "image": "https://exclamation.com/mark.png"
          },
          "attributes": {
            "width": "100"
          }
        }
      ]
    },
    "attachment_id": 31,
    "school_id": 179,
    "created_at": "2019-10-31T22:01:17Z",
    "updated_at": "2019-10-31T22:01:17Z"
  },
  "full_url": "http://school.worksonmy.computer/courses/146/lectures/49",
  "url": null,
  "host_id": null,
  "source": "user",
  "kind": "text",
  "name": null,
  "host": null,
  "position": 1,
  "attachable_id": 49,
  "is_published": true,
  "downloadable": false,
  "text": null,
  "attachable_type": "Lecture",
  "thumbnail_url": null,
  "meta": {
    "class": "attachment",
    "url": null,
    "name": null,
    "description": "",
    "image_url": null
  },
  "embeddable": false,
  "id": 31,
  "plain_text_html": ""
}