Is the replyToMessageId property available when sending via the multipart/form-data schema?

"When I send a message using this method:

const { data: message } = await this.nylasService.messages.send({  
    identifier: account.grantId,  
    requestBody: data,  
});

the message lands in the correct thread. But if I send it with an attachment using form-data, the message ends up in a new thread. Is this the expected behavior?"

public async sendWithGcsAttachments(credentials: Credentials, data: SendNylasMessageDto): Promise<NylasMessage> {
        const account = await this.nylasAccountsService.getMe(credentials);
        const formData = new FormData();

        const gcsAttachments = data.gcsAttachments ?? [];

        const messageData = {
            ...data,
            attachments: gcsAttachments.map((att, index) => ({
                filename: att.filename,
                content_type: att.contentType,
                content_id: `file${index}`,
            })),
        };

        formData.append('message', JSON.stringify(messageData));

        await Promise.all(
            gcsAttachments.map(async (att, i) => {
                const stream = this.gcpBucketService.getReadStream(att.gcpUrl);
                const metadata = await this.gcpBucketService.getFileMetadata(att.gcpUrl);
                const size = Number(metadata.size);

                if (Number.isNaN(size)) {
                    throw new Error(`Invalid file size for ${att.gcpUrl}`);
                }

                formData.append(`file${i}`, stream, {
                    filename: att.filename,
                    contentType: att.contentType,
                    knownLength: size,
                });
            }),
        );

        return (
            await this.nylasService.apiClient.request<{ data: NylasMessage }>({
                method: 'POST',
                path: `/v3/grants/${account.grantId}/messages/send`,
                form: formData,
            })
        ).data;
    }

not working

In the second method (using form-data), I’m sending the same data and can see that this field (e.g., replyToMessageId or threadId) exists in the form-data. How do I properly pass it to ensure the message lands in the correct thread?

thx

Welcome to the Nylas Community! When sending messages with attachments using multipart/form-data , you must ensure all fields required for threading—such as reply_to_message_id —are included in the JSON you append as the message part of the form data. According to the documentation, threading is determined by referencing the reply_to_message_id property in the message payload. This applies regardless of whether you use application/json or multipart/form-data.

If your message is ending up in a new thread, verify that the reply_to_message_id is being set correctly in the JSON object you provide as the message form field. The reply_to_message_id should match the ID of the message you want to reply to, ensuring the new message is threaded appropriately.

Here’s an excerpt from the documentation showing the relevant property:

json
{
  ...
  "reply_to_message_id": "1t8tv3890q4vgmwq6pmdwm8qg",
  ...
}

Make sure your messageData object includes the correct reply_to_message_id and that it is serialized and attached as the message field in the form data. There is no documentation indicating that sending as multipart/form-data should break threading, so the issue is likely with how the threading fields are being set or received by the API.

This is an example you can use:

curl --location 'https://api.us.nylas.com/v3/grants/[GRANT_ID]/messages/send' \
--header 'Authorization: Bearer [API_KEY]' \
--form 'attachments=@"[FILE_LOCATION]"' \
--form 'message="{
    \"subject\": \"Re: Testing Replay with multipart\",
    \"from\": [
        {
            \"name\": \"Test\",
            \"email\": \"test@nylas.com\"
        }
    ],
\"reply_to_message_id\": \"195051feb2fd3fac\",
    \"to\": [
        {
            \"name\": \"user1\",
            \"email\": \"user1@outlook.com\"
        }
    ],
    \"body\": \"this is just a test"
}"'

thank you very much for your help, the problem was in the style of the field names.
The built-in send function converts fields to metadata.
reply_to_message_id
replyToMessageId