-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathorganization_field.go
78 lines (69 loc) · 3.37 KB
/
organization_field.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package zendesk
import (
"context"
"encoding/json"
"time"
)
// OrganizationField represents the Organization Custom field structure
type OrganizationField struct {
ID int64 `json:"id,omitempty"`
URL string `json:"url,omitempty"`
Title string `json:"title"`
Type string `json:"type"`
RelationshipTargetType string `json:"relationship_target_type"`
RelationshipFilter RelationshipFilter `json:"relationship_filter"`
Active bool `json:"active,omitempty"`
CustomFieldOptions []CustomFieldOption `json:"custom_field_options,omitempty"`
Description string `json:"description,omitempty"`
Key string `json:"key"`
Position int64 `json:"position,omitempty"`
RawDescription string `json:"raw_description,omitempty"`
RawTitle string `json:"raw_title,omitempty"`
RegexpForValidation string `json:"regexp_for_validation,omitempty"`
System bool `json:"system,omitempty"`
Tag string `json:"tag,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
}
// OrganizationFieldAPI an interface containing all the organization field related zendesk methods
type OrganizationFieldAPI interface {
GetOrganizationFields(ctx context.Context) ([]OrganizationField, Page, error)
CreateOrganizationField(ctx context.Context, organizationField OrganizationField) (OrganizationField, error)
GetOrganizationFieldsIterator(ctx context.Context, opts *PaginationOptions) *Iterator[OrganizationField]
GetOrganizationFieldsOBP(ctx context.Context, opts *OBPOptions) ([]OrganizationField, Page, error)
GetOrganizationFieldsCBP(ctx context.Context, opts *CBPOptions) ([]OrganizationField, CursorPaginationMeta, error)
}
// GetOrganizationFields fetches organization field list
// ref: https://developer.zendesk.com/api-reference/ticketing/organizations/organization_fields/#list-organization-fields
func (z *Client) GetOrganizationFields(ctx context.Context) ([]OrganizationField, Page, error) {
var data struct {
OrganizationFields []OrganizationField `json:"organization_fields"`
Page
}
body, err := z.get(ctx, "/organization_fields.json")
if err != nil {
return []OrganizationField{}, Page{}, err
}
err = json.Unmarshal(body, &data)
if err != nil {
return []OrganizationField{}, Page{}, err
}
return data.OrganizationFields, data.Page, nil
}
// CreateOrganizationField creates new organization field
// ref: https://developer.zendesk.com/api-reference/ticketing/organizations/organization_fields/#create-organization-field
func (z *Client) CreateOrganizationField(ctx context.Context, organizationField OrganizationField) (OrganizationField, error) {
var data, result struct {
OrganizationField OrganizationField `json:"organization_field"`
}
data.OrganizationField = organizationField
body, err := z.post(ctx, "/organization_fields.json", data)
if err != nil {
return OrganizationField{}, err
}
err = json.Unmarshal(body, &result)
if err != nil {
return OrganizationField{}, err
}
return result.OrganizationField, nil
}