-
-
Notifications
You must be signed in to change notification settings - Fork 495
Todoist API
An example of using Todoist API with VBA-Web is included in the examples/todoist
folder of the project. Some details:
The Todoist API Documentation describes how to authenticate and make requests to the Todoist API. Based on the Authorization: OAuth section the following items are needed: Client Id, Client Secret, and Redirect Url. These can be found in the Todoist App Management Console. For the redirect url, any valid url seems to work as only the querystring is used in authentication (e.g. www.example.com, www.yourcompany.com, etc.)
- Go to https://developer.todoist.com/appconsole.html, create a new app if necessary, and note the Client Id and Client Secret
- Set a Redirect Url for your app (see above note)
- Determine the scope for your application from https://developer.todoist.com/#oauth (e.g.
data:read,task:add
) - Add The
TodoistAuthenticator
to your project and set it up as follows
Dim Auth As New TodoistAuthenticator
Auth.Setup _
ClientId:="Your Client Id", _
ClientSecret:="Your Client Secret"
RedirectUrl:="Your Redirect Url"
Auth.Scope = "data:read,task:add"
Set Client.Authenticator = Auth
With authentication setup for your client, you can use the normal request configuration. Here's an example of the desired url for retrieving the list of projects you have and how to setup the request: (See https://developer.todoist.com/#retrieve-data)
' Desired request: POST https://todoist.com/API/v6/sync
' ?token=SET Automatically from TodoistAuthenticator
' &seq_no=0
' &seq_no_global=0
' &resource_types=["projects"]
Public Function CountProjects() As Long
Dim Client As New WebClient
Client.BaseUrl = "https://todoist.com/API/v6"
Dim Auth As New TodoistAuthenticator
Auth.Setup _
ClientId:="Your Client Id", _
ClientSecret:="Your Client Secret"
RedirectUrl:="Your Redirect Url"
Auth.Scope = "data:read,task:add"
Set Client.Authenticator = Auth
Dim Request As New WebRequest
Request.Resource = "sync"
Request.AddQuerystringParam "seq_no", 0
Request.AddQuerystringParam "seq_no_global", 0
Request.AddQuerystringParam "resource_types", "[""projects""]"
Dim Response As WebResponse
Set Response = TodoistClient.Execute(Request)
If Response.StatusCode = WebStatusCode.Ok Then
CountProjects = Response.Data("Projects").Count
End If
End Function