Skip to content

Commit a74890c

Browse files
committed
feat: implement update page
1 parent f26e115 commit a74890c

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ go get -u github.com/mkfsn/notion-go
2222
* [x] Retrieve ✅
2323
* [x] List ✅
2424
* [x] Query ✅
25-
- [ ] Pages ⚠️
25+
- [x] Pages
2626
* [x] Retrieve ✅
2727
* [x] Create ✅️
28-
* [ ] Update
28+
* [x] Update ✅️
2929
- [x] Blocks ✅️
3030
* [x] Children ✅
3131
- [x] Retrieve ✅

examples/update-page/main.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"log"
6+
"os"
7+
8+
"github.com/mkfsn/notion-go"
9+
)
10+
11+
func main() {
12+
c := notion.New(notion.WithAuthToken(os.Getenv("NOTION_AUTH_TOKEN")))
13+
14+
page, err := c.Pages().Update(context.Background(),
15+
notion.PagesUpdateParameters{
16+
PageID: "6eaac3811afd4f368209b572e13eace4",
17+
Properties: map[string]notion.PropertyValue{
18+
"In stock": notion.CheckboxPropertyValue{
19+
Checkbox: true,
20+
},
21+
22+
"Price": notion.NumberPropertyValue{
23+
Number: 30,
24+
},
25+
},
26+
},
27+
)
28+
29+
if err != nil {
30+
log.Fatal(err)
31+
}
32+
33+
log.Printf("page: %#v\n", page)
34+
}

pages.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,8 @@ type PagesRetrieveResponse struct {
648648
}
649649

650650
type PagesUpdateParameters struct {
651-
PageID string
652-
Properties map[string]PropertyValue `json:"properties"`
651+
PageID string `json:"-" url:"-"`
652+
Properties map[string]PropertyValue `json:"properties" url:"-"`
653653
}
654654

655655
type PagesUpdateResponse struct {
@@ -703,7 +703,20 @@ func (p *pagesClient) Retrieve(ctx context.Context, params PagesRetrieveParamete
703703
}
704704

705705
func (p *pagesClient) Update(ctx context.Context, params PagesUpdateParameters) (*PagesUpdateResponse, error) {
706-
return nil, ErrUnimplemented
706+
endpoint := strings.Replace(APIPagesUpdateEndpoint, "{page_id}", params.PageID, 1)
707+
708+
b, err := p.client.Request(ctx, http.MethodPatch, endpoint, params)
709+
if err != nil {
710+
return nil, err
711+
}
712+
713+
var response PagesUpdateResponse
714+
715+
if err := json.Unmarshal(b, &response); err != nil {
716+
return nil, err
717+
}
718+
719+
return &response, nil
707720
}
708721

709722
func (p *pagesClient) Create(ctx context.Context, params PagesCreateParameters) (*PagesCreateResponse, error) {

0 commit comments

Comments
 (0)