Basic CRUD
Create, read, update and delete
Getting list object
// The recommended way of getting lists is by using their relative URIs
// can be a short form without full web relative URL prefix
list := sp.Web().GetList("Lists/MyList")
// other common but less recommended way of getting a list is
// list := sp.Web().Lists().GetByTitle("My List")Getting items
// itemsResp is a byte array read from response body
// powered with some processing "batteries" as Data() or Unmarshal() methods
itemsResp, err := list.Items().
Select("Id,Title"). // OData $select modifier, limit what props are retrieved
OrderBy("Id", true). // OData $orderby modifier, defines sort order
Top(10). // OData $top modifier, limits page size
Get() // Finalizes API constructor and sends a response
if err != nil {
log.Fatal(err)
}
// Data() method is a helper which unmarshals generic structure
// use custom structs and unmarshal for custom fields
for _, item := range itemsResp.Data() {
itemData := item.Data()
fmt.Printf("ID: %d, Title: %s\n", itemData.ID, itemData.Title)
}Adding an item
Getting a specific item
Updating an item
Delete an item
Last updated
Was this helpful?
