nylas-nodejs
nylas-nodejs copied to clipboard
API URL path components are not correctly encoded
Describe the bug
When calling an endpoint like Return a message which is at /v3/grants/{grant_id}/messages/{message_id}, message_id is not correctly encoded by the SDK, which is problematic because the message_id can contain slashes (/)
This results in the API returning a 404 and then a thrown exception by the SDK
To Reproduce
const nylas = new Nylas({ ... })
// This is close to an actual message Id I received from a webhook `message.created` notification (`data.object.id` in the payload)
const messageId = '<!&!AAAAAAAAAAAuAAAAAAAAAPL4NVAlECZImvB/pLie/4YBAMO2jhD3dRHOtM0AqgC7tuYAAAAAAA4AABAAAACZVwwoazxqQKlwtj+kjwWaAQAAAAA=@someaddr.com>'
const identifier = 'some-grant-id'
const message = await nylas.messages.find({ identifier, messageId }) // 👈❌ throws a `NylasApiError` with 'Unrecognized request URL (GET: /v3/grants/some-grant-id/messages/%3C!&!AAAAAAAAAAAuAAAAAAAAAPL4NVAlECZImvB/pLie/4YBAMO2jhD3dRHOtM0AqgC7tuYAAAAAAA4AABAAAACZVwwoazxqQKlwtj+kjwWaAQAAAAA=@someaddr.com%3E). Please see https://devel...'
const message = await nylas.messages.find({ identifier, messageId: encodeURIComponent(messageId) }) // 👈 ✅ works and returns the expected message
Expected behavior
I expected the SDK to encode path components and not to have to manually call e.g. encodeURIComponent(someId) when making those kinds of API call
SDK Version: 7.7.2