-
Notifications
You must be signed in to change notification settings - Fork 0
/
pokeToWordPress.js
89 lines (74 loc) · 2.96 KB
/
pokeToWordPress.js
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
79
80
81
82
83
84
85
86
87
88
89
function pokeToWordPressOrders(data, order_id) {
//console.log("Wordpress " + data);
let encodedAuthInformation = Utilities.base64Encode(apiusername + ":" + apipassword);
let headers = { "Authorization": "Basic " + encodedAuthInformation };
let options = {
'method': 'post',
'contentType': 'application/json',
'headers': headers, // Convert the JavaScript object to a JSON string.
'payload': JSON.stringify(data)
};
apiUrl = "https://www." + apidomain + "/wp-json/wc/v3/orders/" + order_id
var response = UrlFetchApp.fetch(apiUrl, options);
var responseData = JSON.parse(response.getContentText());
//console.log(responseData)
if (response.getResponseCode() == 200) {
return responseData.id;
} else {
return 'Error';
}
}
function pokeToWordPressProducts(data, product_id) {
//console.log("Wordpress " + data);
let encodedAuthInformation = Utilities.base64Encode(apiusername + ":" + apipassword);
let headers = { "Authorization": "Basic " + encodedAuthInformation };
let options = {
'method': 'post',
'contentType': 'application/json',
'headers': headers, // Convert the JavaScript object to a JSON string.
'payload': JSON.stringify(data)
};
apiUrl = "https://www." + apidomain + "/wp-json/wc/v3/products/" + product_id
var response = UrlFetchApp.fetch(apiUrl, options);
var responseData = JSON.parse(response.getContentText());
if (response.getResponseCode() == 200) {
return responseData.id;
} else {
return 'Error';
}
}
function pokeToWooUserMeta(data, user_id) {
//console.log("Wordpress " + data);
let encodedAuthInformation = Utilities.base64Encode(apiusername + ":" + apipassword);
let headers = { "Authorization": "Basic " + encodedAuthInformation };
let options = {
'method': 'post',
'contentType': 'application/json',
'headers': headers, // Convert the JavaScript object to a JSON string.
'payload': JSON.stringify(data)
};
apiUrl = "https://www." + apidomain + "/wp-json/wc/v3/customers/" + user_id
var response = UrlFetchApp.fetch(apiUrl, options);
var responseData = JSON.parse(response.getContentText());
if (response.getResponseCode() == 200) {
return responseData;
} else {
return 'Error';
}
}
function pokeNoteToOrder(orderNumber, noteText) {
var apiUrl = 'https://www.' + apidomain + '/wp-json/wc/v3/orders/' + orderNumber + '/notes';
var encodedAuthInformation = Utilities.base64Encode(apiusername + ':' + apipassword);
var headers = {'Authorization': 'Basic ' + encodedAuthInformation, 'Content-Type': 'application/json'};
var payload = {'note': noteText};
var options = {'method': 'post', 'headers': headers, 'payload': JSON.stringify(payload)};
var response = UrlFetchApp.fetch(apiUrl, options);
var responseData = JSON.parse(response.getContentText());
//console.log(response.getResponseCode())
if (response.getResponseCode() == 201) {
//console.log(responseData)
return responseData.id;
} else {
return 'Error';
}
}