-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (45 loc) · 1.31 KB
/
Copy pathindex.js
File metadata and controls
47 lines (45 loc) · 1.31 KB
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
// Lib for http calls
var request = require('request');
// Jscrambler code to produce the signature and the payload
var gsp = require("./generate-signed-params");
// Params for generate-signed-params
var method = "POST";
var path = "/application";
var host = "api4.jscrambler.com";
var keys = {
"accessKey":"CHANGE_ME",
"secretKey":"CHANGE_ME"
};
// GraphQL params and query to create an APP.
var graphiQuery = {
params:{
data:{
name:"Hello world",
//languageSpecifications: {es6:true}, // optional
//parameters: [{ "name": "stringSplitting", "status": 1 }] // optional
}
},
query:`mutation createApplication ($data: ApplicationCreate!) {
createApplication (data: $data) {
_id, createdAt, name, parameters
}
}`
};
var mySignedParams = gsp(method, path, host, keys, graphiQuery); // build signature from params
// Simple POST to API
request({
url: "https://"+host+path,
method: "POST",
headers: {
'jscramblerVersion': '5.2' // if omitted will pick the stable version
},
json: true, // <-- important! Make sure body will be send as JSON
body: mySignedParams
}, function (error, response, body){
// print response body or error
if(error) {
console.log("error:",error);
return;
}
console.log("body result:",JSON.stringify(body));
});