Magidoc

How to Attach a File to a Message with GraphQL

Introduction

#

In this guide, we will walk you through the process of attaching a file to a message using GraphQL. This process involves two main steps and utilizes the Attachment Type and Message Type .

Step-by-Step Guide

#

Step 1: Get an attachment ID

#

First, use the attachmentUploadFromUrl mutation to obtain an attachmentId in the response. Make sure to store this, as you'll need them later. The URL is anywhere you want to store the file yourself, this can be your own CDN, or someone else's, so long as it's publicly accessible to the internet, we'll be able to download the file.

    
  

Alternatively, you can use our direct upload endpoint to upload a file using form-data at POST https://api.rasayel.io/api/files/upload

The endpoint is authorized with the same authorization technique as our GraphQL endpoint; provide your access token in the Authorization header: Authorization: <your-access-token>

The form-data body should contain a single key called file , and its value should be the attached file

Here is an example cURL request:

    
  

The response should contain the attachment id which can be used later on.

Step 2: Send the Message

#

This step uses the id from Step 1. Pass it into the mutation's variables as the blobOrAttachmentId . In this example, we are using templateProactiveMessageCreate to create a proactive message to a user using a template. The same workflow applies for Media Message Create .

This uses the MessageProactiveTemplateCreateInput input type .

    
  

In your variables, $input could look like this: