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.

    
  

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: