nylas-nodejs icon indicating copy to clipboard operation
nylas-nodejs copied to clipboard

Get Child Folders in v3

Open spo-pgraessle opened this issue 1 year ago • 1 comments

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 avatar May 03 '24 21:05 spo-pgraessle

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.

spo-pgraessle avatar May 06 '24 16:05 spo-pgraessle

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

mrashed-dev avatar May 17 '24 20:05 mrashed-dev