Documentation ¶
Overview ¶
Package kintone provides interfaces for kintone REST API.
See http://developers.kintone.com/ for API specs.
import ( "log" "github.com/kintone/go-kintone" ) ... app := &kintone.App{ "example.cybozu.com", "user1", "password", 25, }
To retrieve 3 records from a kintone app (id=25):
records, err := app.GetRecords(nil, "limit 3") if err != nil { log.Fatal(err) } // use records
To retrieve 10 latest comments in record (id=3) from a kintone app (id=25)
var offset uint64 = 0 var limit uint64 = 10 comments, err := app.GetRecordComments(3, "desc", offset, limit) if err != nil { log.Fatal(err) } // use comments
To retrieve oldest 10 comments and skips the first 30 comments in record (id=3) from a kintone app (id=25)
var offset uint64 = 30 var limit uint64 = 10 comments, err := app.GetRecordComments(3, "asc", offset, limit) if err != nil { log.Fatal(err) } // use comments
To add comments into record (id=3) from a kintone app (id=25)
mentionMemberCybozu := &ObjMention{Code: "cybozu", Type: kintone.ConstCommentMentionTypeUser} mentionGroupAdmin := &ObjMention{Code: "Administrators", Type: kintone.ConstCommentMentionTypeGroup} mentionDepartmentAdmin := &ObjMention{Code: "Admin", Type: ConstCommentMentionTypeDepartment} var cmt Comment cmt.Text = "Test comment 222" cmt.Mentions = []*ObjMention{mentionGroupAdmin, mentionMemberCybozu, mentionDepartmentAdmin} cmtID, err := app.AddRecordComment(3, &cmt) if err != nil { log.Fatal(err) } // use comments id
To remove comments (id=12) in the record (id=3) from a kintone app (id=25)
err := app.DeleteComment(3, 12) if err != nil { log.Fatal(err) }
Index ¶
- Constants
- Variables
- func IsBuiltinField(o interface{}) bool
- type App
- func (app *App) AddRecord(rec *Record) (id string, err error)
- func (app *App) AddRecordComment(recordId uint64, comment *Comment) (id string, err error)
- func (app *App) AddRecords(recs []*Record) ([]string, error)
- func (app *App) DeleteComment(recordId uint64, commentId uint64) error
- func (app *App) DeleteRecords(ids []uint64) error
- func (app *App) Download(fileKey string) (*FileData, error)
- func (app *App) Fields() (map[string]*FieldInfo, error)
- func (app *App) GetAllRecords(fields []string) ([]*Record, error)
- func (app *App) GetBasicAuthPassword() string
- func (app *App) GetBasicAuthUser() string
- func (app *App) GetRecord(id uint64) (*Record, error)
- func (app *App) GetRecordComments(recordID uint64, order string, offset, limit uint64) ([]Comment, error)
- func (app *App) GetRecords(fields []string, query string) ([]*Record, error)
- func (app *App) GetUserAgentHeader() string
- func (app *App) HasBasicAuth() bool
- func (app *App) SetBasicAuth(user, password string)
- func (app *App) SetUserAgentHeader(userAgentHeader string)
- func (app *App) UpdateRecord(rec *Record, ignoreRevision bool) error
- func (app *App) UpdateRecordByKey(rec *Record, ignoreRevision bool, keyField string) error
- func (app *App) UpdateRecords(recs []*Record, ignoreRevision bool) error
- func (app *App) UpdateRecordsByKey(recs []*Record, ignoreRevision bool, keyField string) error
- func (app *App) Upload(fileName, contentType string, data io.Reader) (key string, err error)
- type AppError
- type AssigneeField
- type CalcField
- type CategoryField
- type CheckBoxField
- type Comment
- type CreationTimeField
- type CreatorField
- type DateField
- type DateTimeField
- type DecimalField
- type FieldInfo
- type File
- type FileData
- type FileField
- type Group
- type GroupField
- type LinkField
- type ModificationTimeField
- type ModifierField
- type MultiLineTextField
- type MultiSelectField
- type ObjCreator
- type ObjMention
- type Organization
- type OrganizationField
- type RadioButtonField
- type Record
- type RecordNumberField
- type RichTextField
- type SingleLineTextField
- type SingleSelectField
- type StatusField
- type SubTableEntry
- type SubTableField
- type TimeField
- type UpdateKey
- type UpdateKeyField
- type User
- type UserField
Constants ¶
const ( NAME = "kintone-go-SDK" VERSION = "0.1.1" DEFAULT_TIMEOUT = time.Second * 600 // Default value for App.Timeout )
const ( ConstCommentMentionTypeGroup = "GROUP" ConstCommentMentionTypeDepartment = "ORGANIZATION" ConstCommentMentionTypeUser = "USER" )
const ( FT_SINGLE_LINE_TEXT = "SINGLE_LINE_TEXT" FT_MULTI_LINE_TEXT = "MULTI_LINE_TEXT" FT_RICH_TEXT = "RICH_TEXT" FT_DECIMAL = "NUMBER" FT_CALC = "CALC" FT_CHECK_BOX = "CHECK_BOX" FT_RADIO = "RADIO_BUTTON" FT_SINGLE_SELECT = "DROP_DOWN" FT_MULTI_SELECT = "MULTI_SELECT" FT_FILE = "FILE" FT_LINK = "LINK" FT_DATE = "DATE" FT_TIME = "TIME" FT_DATETIME = "DATETIME" FT_USER = "USER_SELECT" FT_ORGANIZATION = "ORGANIZATION_SELECT" FT_GROUP = "GROUP_SELECT" FT_CATEGORY = "CATEGORY" FT_STATUS = "STATUS" FT_ASSIGNEE = "STATUS_ASSIGNEE" FT_RECNUM = "RECORD_NUMBER" FT_CREATOR = "CREATOR" FT_CTIME = "CREATED_TIME" FT_MODIFIER = "MODIFIER" FT_MTIME = "UPDATED_TIME" FT_SUBTABLE = "SUBTABLE" FT_ID = "__ID__" FT_REVISION = "__REVISION__" )
Field type identifiers.
Variables ¶
var ( ErrTimeout = errors.New("Timeout") ErrInvalidResponse = errors.New("Invalid Response") ErrTooMany = errors.New("Too many records") )
Library internal errors.
Functions ¶
func IsBuiltinField ¶
func IsBuiltinField(o interface{}) bool
IsBuiltinField returns true if the field is a built-in field.
Types ¶
type App ¶
type App struct { Domain string // domain name. ex: "sample.cybozu.com", "sample.kintone.com", "sample.cybozu.cn" User string // User account for API. Password string // User password for API. AppId uint64 // application ID. Client *http.Client // Specialized client. Timeout time.Duration // Timeout for API responses. ApiToken string // API token. GuestSpaceId uint64 // guest space ID. // contains filtered or unexported fields }
App provides kintone application API client.
You need to provide Domain, User, Password, and AppId. You can also use the api token instead of user/password. When using Google AppEngine, you must supply Client too.
import ( "appengine" "appengine/urlfetch" "github.com/kintone/go-kintone" "http" ) func handler(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) app := &kintone.App{urlfetch.Client(c)} ... }
Errors returned by the methods of App may be one of *AppError, ErrTimeout, ErrInvalidResponse, or ErrTooMany.
func (*App) AddRecord ¶
AddRecord adds a new record.
If successful, the record ID of the new record is returned.
func (*App) AddRecordComment ¶
AddRecordComments post some comments by record ID.
If successful, it returns the target record ID.
func (*App) AddRecords ¶
AddRecords adds new records.
Up to 100 records can be added at once. If successful, a list of record IDs is returned.
func (*App) DeleteComment ¶
DeleteComment - Delete single comment
func (*App) DeleteRecords ¶
DeleteRecords deletes multiple records.
Up to 100 records can be deleted at once.
func (*App) Download ¶
Download fetches an attached file contents.
fileKey should be obtained from FileField (= []File).
func (*App) Fields ¶
Fields returns the meta data of the fields in this application.
If successful, a mapping between field codes and FieldInfo is returned.
func (*App) GetAllRecords ¶
GetAllRecords fetches all records.
If fields is nil, all fields are retrieved.
func (*App) GetBasicAuthPassword ¶ added in v0.1.1
GetBasicAuthPassword return password string for basic authentication
func (*App) GetBasicAuthUser ¶ added in v0.1.1
GetBasicAuthUser return username string for basic authentication
func (*App) GetRecordComments ¶
func (app *App) GetRecordComments(recordID uint64, order string, offset, limit uint64) ([]Comment, error)
GetRecordComments get comment list by record ID.
It returns comment array.
func (*App) GetRecords ¶
GetRecords fetches records matching given conditions.
This method can retrieve up to 100 records at once. To retrieve more records, you need to call GetRecords with increasing "offset" query parameter until the number of records retrieved becomes less than 100.
If fields is nil, all fields are retrieved. See API specs how to construct query strings.
func (*App) GetUserAgentHeader ¶ added in v0.1.1
GetUserAgentHeader get user-agent header string
func (*App) HasBasicAuth ¶ added in v0.1.1
HasBasicAuth indicate authentication is basic or not
func (*App) SetBasicAuth ¶
SetBasicAuth enables use of HTTP basic authentication for access to kintone.
func (*App) SetUserAgentHeader ¶ added in v0.1.1
SetUserAgentHeader set custom user-agent header for http request
func (*App) UpdateRecord ¶
UpdateRecord edits a record.
If ignoreRevision is true, the record will always be updated despite the revision number. Else, the record may not be updated when the same record was updated by another client.
func (*App) UpdateRecordByKey ¶
UpdateRecordByKey edits a record by specified key field.
func (*App) UpdateRecords ¶
UpdateRecords edits multiple records at once.
Up to 100 records can be edited at once. ignoreRevision works the same as UpdateRecord method.
func (*App) UpdateRecordsByKey ¶
UpdateRecordsByKey edits multiple records by specified key fields at once.
type AppError ¶
type AppError struct { HttpStatus string `json:"-"` // e.g. "404 NotFound" HttpStatusCode int `json:"-"` // e.g. 404 Message string `json:"message"` // Human readable message. Id string `json:"id"` // A unique error ID. Code string `json:"code"` // For machines. Errors string `json:"errors"` // Error Description. }
Server-side errors.
type AssigneeField ¶
type AssigneeField []User
AssigneeField is a list of user entries who are assigned to a record.
func (AssigneeField) JSONValue ¶
func (f AssigneeField) JSONValue() interface{}
func (AssigneeField) MarshalJSON ¶
func (f AssigneeField) MarshalJSON() ([]byte, error)
type CalcField ¶
type CalcField string
CalcField is a field type for auto-calculated values.
func (CalcField) MarshalJSON ¶
type CategoryField ¶
type CategoryField []string
CategoryField is a list of category names.
func (CategoryField) JSONValue ¶
func (f CategoryField) JSONValue() interface{}
func (CategoryField) MarshalJSON ¶
func (f CategoryField) MarshalJSON() ([]byte, error)
type CheckBoxField ¶
type CheckBoxField []string
CheckBoxField is a field type for selected values in a check-box.
func (CheckBoxField) JSONValue ¶
func (f CheckBoxField) JSONValue() interface{}
func (CheckBoxField) MarshalJSON ¶
func (f CheckBoxField) MarshalJSON() ([]byte, error)
type Comment ¶
type Comment struct { Id string `json:"id"` Text string `json:"text"` CreatedAt string `json:"createdAt"` Creator *ObjCreator `json:"creator"` Mentions []*ObjMention `json:"mentions"` }
Comment structure
func DecodeRecordComments ¶
DecodeRecordComments decodes JSON response for comment api
type CreationTimeField ¶
CreationTimeField is the time when a record is created.
func (CreationTimeField) JSONValue ¶
func (t CreationTimeField) JSONValue() interface{}
func (CreationTimeField) MarshalJSON ¶
func (t CreationTimeField) MarshalJSON() ([]byte, error)
type CreatorField ¶
type CreatorField User
CreatorField is a user who created a record.
func (CreatorField) JSONValue ¶
func (f CreatorField) JSONValue() interface{}
func (CreatorField) MarshalJSON ¶
func (f CreatorField) MarshalJSON() ([]byte, error)
type DateField ¶
type DateField struct { Date time.Time // stores date information. Valid bool // false when not set. }
DateField is a field type for dates.
func NewDateField ¶
NewDateField returns an instance of DateField.
func (DateField) MarshalJSON ¶
type DateTimeField ¶
type DateTimeField struct { Time time.Time // stores time information. Valid bool // false when not set. }
DateTimeField is a field type for date & time.
func NewDateTimeField ¶
func NewDateTimeField(year int, month time.Month, day, hour, min int) DateTimeField
NewDateTimeField returns an instance of DateTimeField.
func (DateTimeField) JSONValue ¶
func (f DateTimeField) JSONValue() interface{}
func (DateTimeField) MarshalJSON ¶
func (f DateTimeField) MarshalJSON() ([]byte, error)
type DecimalField ¶
type DecimalField string
DecimalField is a field type for decimal numbers.
func (DecimalField) JSONValue ¶
func (f DecimalField) JSONValue() interface{}
func (DecimalField) MarshalJSON ¶
func (f DecimalField) MarshalJSON() ([]byte, error)
type FieldInfo ¶
type FieldInfo struct { Label string `json:"label"` // Label string Code string `json:"code"` // Unique field code Type string `json:"type"` // Field type. One of FT_* constant. NoLabel bool `json:"noLabel"` // true to hide the label Required bool `json:"required"` // true if this field must be filled Unique bool `json:"unique"` // true if field values must be unique MaxValue interface{} `json:"maxValue"` // nil or numeric string MinValue interface{} `json:"minValue"` // nil or numeric string MaxLength interface{} `json:"maxLength"` // nil or numeric string MinLength interface{} `json:"minLength"` // nil or numeric string Default interface{} `json:"defaultValue"` // anything DefaultTime interface{} `json:"defaultExpression"` // nil or "NOW" Options []string `json:"options"` // list of selectable values Expression string `json:"expression"` // to calculate values Separator bool `json:"digit"` // true to use thousand separator Medium string `json:"protocol"` // "WEB", "CALL", or "MAIL" Format string `json:"format"` // "NUMBER", "NUMBER_DIGIT", "DATETIME", "DATE", "TIME", "HOUR_MINUTE", "DAY_HOUR_MINUTE" Fields []FieldInfo `json:"fields"` // Field list of this subtable }
FieldInfo is the meta data structure of a field.
func (*FieldInfo) UnmarshalJSON ¶
Work around code to handle "true"/"false" strings as booleans...
type File ¶
type File struct { ContentType string `json:"contentType"` // MIME type of the file FileKey string `json:"fileKey"` // BLOB ID of the file Name string `json:"name"` // File name Size uint64 `json:"size,string"` // The file size }
File is a struct for an uploaded file.
func (*File) MarshalJSON ¶
type FileData ¶
type FileData struct { ContentType string // MIME type of the contents. Reader io.Reader // File contents. }
FileData stores downloaded file data.
type FileField ¶
type FileField []File
FileField is a field type for uploaded files.
func (FileField) MarshalJSON ¶
type Group ¶
type Group struct { Code string `json:"code"` // A unique identifer of the group(or role). Name string `json:"name"` // The group name. }
Group represents a group(or role) entry.
type GroupField ¶
type GroupField []Group
GroupField is a field type for group(or role) entries.
func (GroupField) JSONValue ¶
func (f GroupField) JSONValue() interface{}
func (GroupField) MarshalJSON ¶
func (f GroupField) MarshalJSON() ([]byte, error)
type LinkField ¶
type LinkField string
LinkField is a field type for hyper-links.
func (LinkField) MarshalJSON ¶
type ModificationTimeField ¶
ModificationTimeField is the time when a record is last modified.
func (ModificationTimeField) JSONValue ¶
func (t ModificationTimeField) JSONValue() interface{}
func (ModificationTimeField) MarshalJSON ¶
func (t ModificationTimeField) MarshalJSON() ([]byte, error)
type ModifierField ¶
type ModifierField User
ModifierField is a user who modified a record last.
func (ModifierField) JSONValue ¶
func (f ModifierField) JSONValue() interface{}
func (ModifierField) MarshalJSON ¶
func (f ModifierField) MarshalJSON() ([]byte, error)
type MultiLineTextField ¶
type MultiLineTextField string
MultiLineTextField is a field type for multi-line texts.
func (MultiLineTextField) JSONValue ¶
func (f MultiLineTextField) JSONValue() interface{}
func (MultiLineTextField) MarshalJSON ¶
func (f MultiLineTextField) MarshalJSON() ([]byte, error)
type MultiSelectField ¶
type MultiSelectField []string
MultiSelectField is a field type for selected values in a selection box.
func (MultiSelectField) JSONValue ¶
func (f MultiSelectField) JSONValue() interface{}
func (MultiSelectField) MarshalJSON ¶
func (f MultiSelectField) MarshalJSON() ([]byte, error)
type ObjCreator ¶
ObjCreator structure
type ObjMention ¶
ObjMentions structure
type Organization ¶
type Organization struct { Code string `json:"code"` // A unique identifer of the department. Name string `json:"name"` // The department name. }
Organization represents a department entry.
type OrganizationField ¶
type OrganizationField []Organization
OrganizationField is a field type for department entries.
func (OrganizationField) JSONValue ¶
func (f OrganizationField) JSONValue() interface{}
func (OrganizationField) MarshalJSON ¶
func (f OrganizationField) MarshalJSON() ([]byte, error)
type RadioButtonField ¶
type RadioButtonField string
RadioButtonField is a field type for the selected value by a radio-button.
func (RadioButtonField) JSONValue ¶
func (f RadioButtonField) JSONValue() interface{}
func (RadioButtonField) MarshalJSON ¶
func (f RadioButtonField) MarshalJSON() ([]byte, error)
type Record ¶
type Record struct { Fields map[string]interface{} // contains filtered or unexported fields }
Record represens a record in an application.
Fields is a mapping between field IDs and fields. Although field types are shown as interface{}, they are guaranteed to be one of a *Field type in this package.
func DecodeRecord ¶
DecodeRecord decodes JSON response for single-get API.
func DecodeRecords ¶
DecodeRecords decodes JSON response for multi-get API.
func NewRecordWithId ¶
NewRecord creates using an existing record id.
The revision number is initialized to -1.
func (Record) MarshalJSON ¶
MarshalJSON marshals field data of a record into JSON.
type RecordNumberField ¶
type RecordNumberField string
RecordNumberField is a record number.
func (RecordNumberField) JSONValue ¶
func (f RecordNumberField) JSONValue() interface{}
func (RecordNumberField) MarshalJSON ¶
func (f RecordNumberField) MarshalJSON() ([]byte, error)
type RichTextField ¶
type RichTextField string
RichTextField is a field type for HTML rich texts.
func (RichTextField) JSONValue ¶
func (f RichTextField) JSONValue() interface{}
func (RichTextField) MarshalJSON ¶
func (f RichTextField) MarshalJSON() ([]byte, error)
type SingleLineTextField ¶
type SingleLineTextField string
SingleLineTextField is a field type for single-line texts.
func (SingleLineTextField) JSONValue ¶
func (f SingleLineTextField) JSONValue() interface{}
func (SingleLineTextField) MarshalJSON ¶
func (f SingleLineTextField) MarshalJSON() ([]byte, error)
type SingleSelectField ¶
type SingleSelectField struct { String string // Selected value. Valid bool // If not selected, false. }
SingleSelectField is a field type for the selected value in a selection box.
func (SingleSelectField) JSONValue ¶
func (f SingleSelectField) JSONValue() interface{}
func (SingleSelectField) MarshalJSON ¶
func (f SingleSelectField) MarshalJSON() ([]byte, error)
type StatusField ¶
type StatusField string
StatusField is a string label of a record status.
func (StatusField) JSONValue ¶
func (f StatusField) JSONValue() interface{}
func (StatusField) MarshalJSON ¶
func (f StatusField) MarshalJSON() ([]byte, error)
type SubTableEntry ¶
type SubTableEntry struct { Id string `json:"id"` // The entry ID Value map[string]interface{} `json:"value"` // Subtable data fields. }
SubTableEntry is a type for an entry in a subtable.
type SubTableField ¶
type SubTableField []*Record
SubTableField is a list of subtable entries.
func (SubTableField) JSONValue ¶
func (f SubTableField) JSONValue() interface{}
func (SubTableField) MarshalJSON ¶
func (f SubTableField) MarshalJSON() ([]byte, error)
type TimeField ¶
type TimeField struct { Time time.Time // stores time information. Valid bool // false when not set. }
TimeField is a field type for times.
func NewTimeField ¶
NewTimeField returns an instance of TimeField.
func (TimeField) MarshalJSON ¶
type UpdateKey ¶
type UpdateKey struct { FieldCode string Field UpdateKeyField }
func (UpdateKey) MarshalJSON ¶
type UpdateKeyField ¶
type UpdateKeyField interface {
JSONValue() interface{}
}