Skip to content

Conversation

scottlovegrove
Copy link
Contributor

Fixes: #131

The problem with passing in just an array of objects into axios is it may not do what we're expecting it to do when it comes to formatting. This was exactly what was happening.

In this PR I'm adding a custom paramsSerializer function to ensure that formatting is as we want it.

Testing

You can try this out with the scratch.ts file (see readme for usage). Make sure you set your token and a couple of task IDs for your account.

With this fix, you will get just those two tasks returned, prior to this fix, it would have returned all your tasks.

import { TodoistApi } from './TodoistApi'

const token = '<TOKEN>'

const api = new TodoistApi(token)

async function doIt() {
    try {
        const tasks = await api.getTasks({
            ids: ['<YOUR_TASK_1>', '<YOUR_TASK_2>'],
        })
        console.log(tasks.length)
    } catch (error: unknown) {
        if (error instanceof Error) {
            console.log(error)
        }
        console.log({ error })
    }
}

doIt().catch(() => {
    // noop
})

@scottlovegrove scottlovegrove requested a review from a team September 13, 2022 17:03
@scottlovegrove scottlovegrove self-assigned this Sep 13, 2022
@scottlovegrove scottlovegrove requested review from a team and engfragui and removed request for a team September 13, 2022 17:03
Copy link
Contributor

@engfragui engfragui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works as expected for me now (tested via scratch file).

@scottlovegrove scottlovegrove merged commit f546fe0 into main Sep 14, 2022
@scottlovegrove scottlovegrove deleted the scottl/fix-array-format-on-requests branch September 14, 2022 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GetTasks endpoint does not work with ids parameter
2 participants