· 8 years ago · Dec 13, 2017, 09:06 PM
1/**
2 * @header
3 * @name MyCred API call
4 * @description Integrate with MyCred
5 * @category Custom APIs
6 */
7
8/**
9 * @inspectable
10 * @name Transition
11 * @description Where this block transitions when it is finished
12 * @type transition
13 */
14const transition = `ffe2a469-084d-437d-a6a8-bdce288ae9b9`;
15
16
17const secretKey = 'mysecretkey';
18const remoteUrl = 'http://siteb.com/api';
19
20const action = 'CREDIT';
21const account = 'john.doe@email.com';
22const amount = 10;
23const ref = 'reference';
24const refId = 0;
25const entry = 'Points for viewing video';
26const data = 'optional extra';
27const pointType = 'my_custom_type';
28
29const host = 'blog_url';
30
31// Calculate token
32let token = `${host}${action}${amount}${secretKey}`;
33token = await Meta.actions.post(`http://api.rest7.com/v1/text_hash.php?text=${token}&algo=md5`, { method: 'get' });
34token = await token.json();
35token = JSON.stringify(token);
36token = token.hash;
37
38Meta.actions.post(remoteUrl, {
39 method: 'post',
40 headers: {
41 Accept: 'application/x-www-form-urlencoded',
42 'Content-Type': 'application/x-www-form-urlencoded',
43 },
44 body: `action=${action}&account=${account}&amount=${amount}&ref=${reference}&ref_id=${referenceId}&type=${pointType}&entry=${entry}&data=${data}&host=${host}&token=${token}`,
45});
46
47Meta.callbacks.transitionTo(transition);