nylas / nylas-nodejs

A NodeJS wrapper for the Nylas REST API for email, contacts, and calendar.
MIT License
166 stars 116 forks source link

Get Child Folders in v3 #563

Closed spo-pgraessle closed 2 months ago

spo-pgraessle commented 2 months ago

I have been unable to determine how to properly obtain a child folder in v3. Previously in v2, if there was a folder foo with a sub-folder of bar, the folder would be obtained by doing the following:

const folders = await nylas.folders.list();
for (const folder of folders) {
  if (folder.displayName === 'foo/bar') {
    return folder;
  }
}

In v3, I was able to determine how to create a sub-folder. So from the SDK a new sub-folder can be created as follows:

nylas.folder.create({
  identifier: <user grant id>,
  requestBody: {
    name: <name of sub-folder>,
    parent_id: <id of parent folder>
  }
})

So if I wanted to create a sub-folder called bar of foo (foo/bar), it would be

nylas.folder.create({
  identifier: <user grant id>,
  requestBody: {
    name: 'bar',
    parent_id: <id of foo>
  }
})

Once bar is created, I cannot figure out how to get the id for this folder, so I can move email messages to it. I have an existing structure, so saving the id at the time of creation is not going to work without recreating my entire folder structure.

Is there a way to do obtain a sub-folder with current version of the SDK (using 7.3.0)? I attempted to use list and find while attempting to set the overrides; however, I wasn't able to determine the required configuration. I did find that the following cURL call would work, but couldn't find how to do this within the SDK:

curl --request GET \
  --url https://api.us.nylas.com/v3/grants/<user grant id>/folders?parent_id=<parent folder id> \
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer <api key>' \
  --header 'Content-Type: application/json'

Thank you much!

spo-pgraessle commented 2 months ago

Found that list and find under resources/folders.ts do not accept query parameters, and should, to allow functionality described above in cURL command. I can raise a PR for this change.

mrashed-dev commented 2 months ago

It looks like #565 closes your issue! It's currently being released as part of v7.5.0 😄