nylas-python
nylas-python copied to clipboard
Labels working but generating an error message
trafficstars
Describe the bug We can use labels on messages to move them to another folder or even the trash. Right now, the correct label will be applied but the SDK will return an error.
To Reproduce Some steps involved to reproduce the bug and any code samples you can share.
I have omitted the Try - Except to fully return the error message.
messageId = "<MESSAGE_ID>"
labelsDict = {}
labels = nylas.labels.all()
for label in labels:
labelsDict[label["name"]] = label["id"]
message = nylas.messages.get(messageId)
message.update_labels([labelsDict["trash"]])
message.save()
print(f"Your message was successfully deleted")
The error message is
nylas.client.errors.NylasApiError: 400 Bad Request. Reason: Invalid 'label_id': {u'display_name': u'TRASH', u'id': u'c1vwdjcvfh0m4w8es2ovp6qq8', u'name': u'trash'}. Nylas Error Type: invalid_request_error
Expected behavior There shouldn't be an error message. We can do the same in Ruby without further issues
messageId = "<MESSAGE_ID>"
labelsDict = Hash.new
labels = nylas.labels
labels.each{ |label|
labelsDict[label.name] = label.id
}
begin
message = nylas.messages.find(messageId)
message.update(label_ids: [labelsDict["trash"]])
message.save
puts "Your message was succesfully deleted"
rescue => error
puts error.message
end
SDK Version: Python 3.10.4 Nylas SDK 5.14.0
Additional context While the error can be bypassed by using pass, there shouldn't be an error at all.
I've run into the same issue while working on this particular endpoint.