-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetafields.go
69 lines (62 loc) · 1.64 KB
/
metafields.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
package goshopify
import (
"encoding/json"
"fmt"
)
func GetMetafields() {
url := urltpl() + "metafields.json"
m := make(map[string]string)
m["limit"] = "2"
response := queryGet(url, m)
var products ProductsResponse
json.Unmarshal(response, &products)
for _, v := range products.Products {
fmt.Println(v.Handle)
}
}
func GetProductMetafield(handle, mfnamspace, mfkey string) {
url := urltpl() + "products/" + handle + "/metafields.json"
m := make(map[string]string)
response := queryGet(url, m)
var products ProductsResponse
json.Unmarshal(response, &products)
for _, v := range products.Products {
fmt.Println(v.Handle)
}
}
func SetProductMetafield(handle, namespace, key, value, valuetype string) {
SetConfig()
url := urltpl() + "products/" + handle + "/metafields.json"
body := `
{
"metafield": {
"namespace": ` + namespace + `,
"key": ` + key + `,
"value": ` + value + `,
"value_type": ` + valuetype + `
}
}
`
queryPost(url, body)
}
type MetafieldResponse struct {
Metafields []struct {
AdminGraphqlAPIID string `json:"admin_graphql_api_id"`
CreatedAt string `json:"created_at"`
Description string `json:"description"`
ID int64 `json:"id"`
Key string `json:"key"`
Namespace string `json:"namespace"`
OwnerID int64 `json:"owner_id"`
OwnerResource string `json:"owner_resource"`
UpdatedAt string `json:"updated_at"`
Value string `json:"value"`
ValueType string `json:"value_type"`
} `json:"metafields"`
}
type Metafield struct {
Namespace string
Key string
Value string
ValueType string
}