Created
March 8, 2022 14:59
-
-
Save jordigg/d4b2cb2d9f10b47a2d8e612e5421b936 to your computer and use it in GitHub Desktop.
Get Notion workspace users through API using go and jomei/notionapi wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = ¬ionapi.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