Upload Attachment

Upload a file or file URL to use in messages

POSThttps://api.pact.im/api/p2/attachments/

Creates an attachment that can be sent in a message.

Use:

  • Content-Type: multipart/form-data when sending file
  • Content-Type: application/json when sending file_url

Body Parameters

ParameterRequiredValidationsDescription
private_api_tokentrueMust be a stringYOUR_API_TOKEN
company_idtrueMust be an integerID of the company
filefalseMust be a File. Mutually exclusive with file_urlAttachment file
file_urlfalseMust be a URL (http or https). Mutually exclusive with fileAttachment file URL
metadatafalseMust be an objectCan contain push_to_talk and data

Metadata

ParameterRequiredValidationsDescription
push_to_talkfalseBooleanSend audio files as voice messages
datafalseMust be an objectImages only. May contain height and width

Example

Request

shell
curl -X POST 'https://api.pact.im/api/p2/attachments/' \
  --header 'Content-Type: multipart/form-data' \
  --form 'file=@"spec/fixtures/files/1.jpg"' \
  --form 'private_api_token=YOUR_API_TOKEN' \
  --form 'company_id=COMPANY_ID' \
  --form 'metadata[data][width]="1024"' \
  --form 'metadata[data][height]="1280"'

Response

json
{
  "attachment": {
    "id": 53439177,
    "message_id": null,
    "file_name": "1.jpg",
    "mime_type": "image/jpg",
    "size": 812089,
    "attachment_url": "The path to the file",
    "preview_url": "The path to the file",
    "aspect_ratio": 0.8,
    "data": {
      "width": 1024,
      "height": 1280
    }
  }
}

Search…

Start typing to search