Skip to content

Instantly share code, notes, and snippets.

@jordigg
Created March 8, 2022 14:59
Show Gist options
  • Save jordigg/d4b2cb2d9f10b47a2d8e612e5421b936 to your computer and use it in GitHub Desktop.
Save jordigg/d4b2cb2d9f10b47a2d8e612e5421b936 to your computer and use it in GitHub Desktop.
Get Notion workspace users through API using go and jomei/notionapi wrapper
package main
import (
"context"
"encoding/json"
"fmt"
"github.com/jomei/notionapi"
"github.com/pkg/errors"
)
func main() {
client := notionapi.NewClient("YOUR_SECRET_HERE")
var userList []notionapi.User
var cursor = &notionapi.Pagination{}
for hasMore := true; hasMore; {
resp, err := client.User.List(context.Background(), cursor)
if err != nil {
errors.New(err.Error())
}
userList = append(userList, resp.Results...)
hasMore = resp.HasMore
cursor.StartCursor = resp.NextCursor
}
result, _ := json.MarshalIndent(userList, "", "\t")
fmt.Println(string(result))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment