# /api/v3/posts/{id}/attachments
---
get:
  parameters:
  - description: ID of the post whose attachments will be listed
    example: '1'
    in: path
    name: id
    required: true
    schema:
      type: integer
  responses:
    '200':
      content:
        application/hal+json:
          examples:
            response:
              value:
                _embedded:
                  elements:
                  - _links:
                      author:
                        href: "/api/v3/users/1"
                        title: OpenProject Admin
                      container:
                        href: "/api/v3/posts/72"
                        title: wiki
                      delete:
                        href: "/api/v3/attachments/376"
                        method: delete
                      downloadLocation:
                        href: "/api/v3/attachments/376/content"
                      self:
                        href: "/api/v3/attachments/376"
                        title: 200.gif
                    _type: Attachment
                    contentType: image/gif
                    createdAt: '2018-06-01T07:24:19.706Z'
                    description:
                      format: plain
                      html: ''
                      raw: ''
                    digest:
                      algorithm: md5
                      hash: 7ac9c97ef73d47127f590788b84c0c1c
                    fileName: some.gif
                    fileSize: 3521772
                    id: 376
                _links:
                  self:
                    href: "/api/v3/posts/72/attachments"
                _type: Collection
                count: 1
                total: 1
          schema:
            "$ref": "../components/schemas/attachments_model.yml"
      description: OK
      headers: {}
    '404':
      content:
        application/hal+json:
          schema:
            $ref: "../components/schemas/error_response.yml"
          examples:
            response:
              value:
                _type: Error
                errorIdentifier: urn:openproject-org:api:v3:errors:NotFound
                message: The requested resource could not be found.
      description: |-
        Returned if the post does not exist or the client does not have sufficient permissions
        to see it.

        **Required permission:** view messages

        *Note: A client without sufficient permissions shall not be able to test for the existence of a post.
        That's why a 404 is returned here, even if a 403 might be more appropriate.*
      headers: {}
  tags:
  - Attachments
  description: ''
  operationId: List_attachments_by_post
  summary: List attachments by post
post:
  parameters:
  - description: ID of the post to receive the attachment
    example: '1'
    in: path
    name: id
    required: true
    schema:
      type: integer
  responses:
    '200':
      content:
        application/hal+json:
          examples:
            response:
              value:
                _embedded:
                  author:
                    _links:
                      lock:
                        href: "/api/v3/users/1/lock"
                        method: post
                        title: Set lock on admin
                      self:
                        href: "/api/v3/users/1"
                        title: OpenProject Admin
                      showUser:
                        href: "/users/1"
                        type: text/html
                      updateImmediately:
                        href: "/api/v3/users/1"
                        method: patch
                        title: Update admin
                    _type: User
                    admin: true
                    avatar: ''
                    createdAt: '2015-03-20T12:56:52.850Z'
                    email:
                    firstName: OpenProject
                    id: 1
                    identityUrl:
                    lastName: Admin
                    login: admin
                    name: OpenProject Admin
                    status: active
                    updatedAt: '2018-05-29T13:57:44.604Z'
                  container:
                    _links:
                      addAttachment:
                        href: "/api/v3/posts/150/attachments"
                        method: post
                      attachments:
                        href: "/api/v3/posts/150/attachments"
                      project:
                        href: "/api/v3/projects/12"
                        title: Demo project
                      self:
                        href: "/api/v3/posts/150"
                    _type: Post
                    id: 150
                    subject: sfsdfsdfsdfsdf
                _links:
                  author:
                    href: "/api/v3/users/1"
                    title: OpenProject Admin
                  container:
                    href: "/api/v3/posts/150"
                    title: sfsdfsdfsdfsdf
                  delete:
                    href: "/api/v3/attachments/377"
                    method: delete
                  downloadLocation:
                    href: "/api/v3/attachments/377/content"
                  self:
                    href: "/api/v3/attachments/377"
                    title: 200.gif
                _type: Attachment
                contentType: image/gif
                createdAt: '2018-06-01T07:53:36.831Z'
                description:
                  format: plain
                  html: ''
                  raw: ''
                digest:
                  algorithm: md5
                  hash: 7ac9c97ef73d47127f590788b84c0c1c
                fileName: some.gif
                fileSize: 3521772
                id: 377
      description: OK
      headers: {}
    '400':
      content:
        application/hal+json:
          schema:
            $ref: "../components/schemas/error_response.yml"
          examples:
            response:
              value:
                _type: Error
                errorIdentifier: urn:openproject-org:api:v3:errors:InvalidRequestBody
                message: The request could not be parsed as JSON.
      description: |-
        Returned if the client sends a not understandable request. Reasons include:

        * Omitting one of the required parts (metadata and file)

        * sending unparsable JSON in the metadata part
      headers: {}
    '403':
      content:
        application/hal+json:
          schema:
            $ref: "../components/schemas/error_response.yml"
          examples:
            response:
              value:
                _type: Error
                errorIdentifier: urn:openproject-org:api:v3:errors:MissingPermission
                message: You are not allowed to delete this attachment.
      description: |-
        Returned if the client does not have sufficient permissions.

        **Required permission:** edit messages

        *Note that you will only receive this error, if you are at least allowed to see the wiki page*
      headers: {}
    '404':
      content:
        application/hal+json:
          schema:
            $ref: "../components/schemas/error_response.yml"
          examples:
            response:
              value:
                _type: Error
                errorIdentifier: urn:openproject-org:api:v3:errors:NotFound
                message: The requested resource could not be found.
      description: |-
        Returned if the post does not exist or the client does not have sufficient permissions
        to see it.

        **Required permission:** view messages

        *Note: A client without sufficient permissions shall not be able to test for the existence of a post.
        That's why a 404 is returned here, even if a 403 might be more appropriate.*
      headers: {}
    '406':
      $ref: "../components/responses/missing_content_type.yml"
    '415':
      $ref: "../components/responses/unsupported_media_type.yml"
    '422':
      content:
        application/hal+json:
          schema:
            $ref: "../components/schemas/error_response.yml"
          examples:
            response:
              value:
                _type: Error
                errorIdentifier: urn:openproject-org:api:v3:errors:PropertyConstraintViolation
                message: File is too large (maximum size is 5242880 Bytes).
      description: |-
        Returned if the client tries to send an invalid attachment.
        Reasons are:

        * Omitting the file name (`fileName` property of metadata part)

        * Sending a file that is too large
      headers: {}
  tags:
  - Attachments
  description: |-
    Adds an attachment with the post as it's container.

  operationId: Add_attachment_to_post
  summary: Add attachment to post
