Updating draft in V3 with formdata returning error

I am sending a request from Nylas docs as mentioned in the examples. While creating the draft with form data its working fine ,but when I try it with updating the draft it is giving below error

{
“request_id”: “”,
“error”: {
“type”: “invalid_request_error”,
“message”: “NOT IMPLEMENTED”
}
}

i have tested with python, I am sending it as requests.

import requests
import json

Define your Nylas API credentials and endpoint

grant_id = “xxxxxx”
draft_id = “xxxxx”
url = f"/v3/grants/{grant_id}/drafts/{draft_id}"

Set the authorization token and headers

headers = {
“accept”: “application/json”,
“authorization”: “Bearer xxxxxxxxxxxxxx”,
“content-type”: “multipart/form-data”
}

Prepare the data for the draft update

data = {
“bcc”: [
{
“email”: “brandon.carson@exam”,
“name”: “”
}
],
“body”: “Hi, Welcome to Nylas!”,
“cc”: [
{
“email”: “clivescounters@exam”,
“name”: “”
}
],
“reply_to”: [
{
“email”: “healthcare.demo@example.com”,
“name”: “”
}
],
“starred”: False,
“thread_id”: “1910xxxxxxxxx”,
“subject”: “Invitation: Welcome! @ Thu Oct 28, 2021 7am - 8am (EDT) - Toronto”,
“to”: [
{
“email”: “demo”,
“name”: “”
},
{
“email”: “realestate.demo”,
“name”: “”
}
]
}

files = {
‘attachment’: open(“mails_sample.html”, ‘rb’)
}

Make the PUT request to update the draft

response = requests.put(url, headers=headers, data=data, files=files)

Check the response

if response.status_code == 200:
print(“Draft updated successfully:”, response.json())
else:
print(“Error updating draft:”, response.status_code, response.json())

@sheik thanks for posting, let me take a look and follow up!

Hi @sheik are you using our Python SDK for updating a draft?

That would simplify the coding side of things and ensure you have all the correct config.

Alternative, its worth trying out our postman collection to debug further.

Hi @ram , It is working fine when I update a file with size below 3mb, I am trying to send a file which is greater than 3mb. As mentioned in the documentation, one can send files greater than 3mb should be sent in form data. I am trying to do same in updating a draft with attachment greater than 3mb.I am using Node Js SDK. For use cases like this I am using url directly to send form data.

@sheik have a look at this related thread, let me know if it helps clarify.

Hey @ram, I have the same issue in my update draft requests.
@sheik were you actually able to update the file with less than 3mb? To me, the request return a 200 OK, but the file wasn’t really updated.

@VictorMonteiro7 let me take a look, do you have a code sample that I can see the approach?

@VictorMonteiro7 just following up with Eng, let me circle back once I have an update.

@ram I haven’t a code example now, but I opened a topic that have relation with this topic.
Topic here

Hey @ram got a new issue while creating a draft with multipart/formdata I am getting below error

{
“request_id”: “749489a6-b077-4a6b-a1fe-77851dd5f8f9”,
“error”: {
“type”: “provider_error”,
“message”: “provider returned error”,
“provider_error”: {
“error”: {
“code”: 400,
“message”: "were unable to deserialize "
}
}
}
}
same code was working fine 1 day before and today it is not working

Hello @ram, Its working fine for google mails , when I am trying to create draft with attachments its giving me above error in Microsoft mails.

@sheik as mentioned previously, waiting to hear back on this from our team, let me follow up as soon as I have an update.

Just wanted to add I am experiencing the same behaviour with multipart/formdata:
Microsoft

  • Creating a draft results in 400 provider_error

Google

  • Updating a draft results in 501 NOT IMPLEMENTED

Have not tested updating a Microsoft draft as getting drafts is also in a weird spot where I don’t receive exclusive-draft threads when querying threads and any thread that should have drafts have their draftIds array empty.

Querying drafts gives me all drafts but I would rather not fetch them this way.

I can only assume you are still working on this and hope you fix it soon.

Hey @stiry ,

const fileStream = fs.createReadStream(file.path);
/**
* append file to form-data
* filename and contentType and knownLength are required for microsoft mails
*/
form.append(‘file’, fileStream, {
filename:file.originalname,
contentType:file.mimetype,
knownLength:file.size
});

I used this to add attachments while creating a draft, Its working fine now for both google and microsoft mails while creating drafts with attachments.
Updating attachments of the drafts is still not resolved. Waiting for the update from @ram :slight_smile:

Thanks for the reply @sheik, i was not able to reproduce your success in nodejs.

But I feel it should not be possible to make these mistakes and it is Nylas’ responsibility to test these integrations before pushing us to v3 with a deadline. It is losing us faith in the product if standard functions don’t work or are documented incorrectly.

@stiry I’m sorry to hear this is still an issue and am working with our team to address the issue. Will keep you posted as soon as I have an update.

@stiry just an update, we just released a related fix, so I’m going try this out myself and will keep you posted!