I’m trying to post data to the server, do some stuff there and return a string, but i cant get any response…
function(properties, context) {
const fetch = require(‘cross-fetch’);
fetch("https://idealinktask.herokuapp.com/", {
method: “post”,
headers: {
‘Accept’: ‘application/json’,
‘Content-Type’: ‘application/json’
},
//make sure to serialize your JSON body
body: JSON.stringify({
text: properties.text_in,
letter: properties.letter_in
})
})
.then( (response) => {
return {
text_out: “asdawsd”
}
})
}
It isn’t clear but my assumption is your are doing this within a plugin ssa given the function(properties, context) definition. If so, try this:
// Incantation to request content
var getoptions = {
uri: 'https://idealinktask.herokuapp.com/',
method: "POST",
encoding: null,
headers: { "Accept": "application/json" }
};
// results
var results = context.request(getoptions).body;
2 Likes
but how to pass some parameters to the request? I want to pass two strings to the server
var data = {
text: properties.text_in,
letter: properties.letter_in
};
// Incantation to request content
var options = {
uri: 'https://idealinktask.herokuapp.com/',
method: "POST",
encoding: null,
headers: { "Accept": "application/json" },
json: data
};
// results
var results = context.request(options).body;
Thanks fot the help, but i get a second problem:
