-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (39 loc) · 1.58 KB
/
index.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
function badgrBadsClassesAsJSON(name) {
// Make a GET request and log the returned content.
var badgeClass =
{
"name": name,
"image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==",
"description": "This is a tiny badge with a tiny little image. People who earn it might have done something tiny to deserve it.",
"criteriaUrl": "https://tinybuddha.com/blog/30-accomplishments-to-be-proud-of/",
"criteriaNarrative": "Do something both small and meaningful",
"alignments": [
{
"targetName": "30 Accomplishments to Be Proud Of",
"targetUrl": "https://tinybuddha.com/blog/30-accomplishments-to-be-proud-of/",
"targetDescription": "Be proud of accomplishments like these"
}
],
"tags": [
"test"
]
};
var issuerId = "9IGmqFKgSiGdx5uhFcj4Ow";
var bearer = "iJ60xGOf9jMkDWiy6w1RaxvkUHzYQT";
var params = {
"contentType": "application/json",
"headers": {
"Authorization" : "Bearer " + bearer
},
"method": "POST",
"payload": badgeClass,
};
var response = UrlFetchApp.fetch("https://api.badgr.io/v2/issuers/" + issuerId + "/badgeclasses", params);
Logger.log(response.getContentText());
msg = "HTTP 1.1 " + response.getResponseCode();
var responseContent = response.getContent();
var bufferized = Buffer.from(responseContent);
var asJSON = JSON.parse(bufferized.toString("UTF-8"));
msg += " " + (asJSON.result && asJSON.result.openBadgeId ? "unkown openBadgeId in response" : asJSON.result.openBadgeId)
return msg
}