I'm working to send the data from my server to the webhook.
I'm using a "REQUEST" service, but I'm getting an error. My request hits there but I'm getting an error.
var request = require('request');
var data:any = [];
data[5] = {email5 : "abc#gmail.com"};
request.post({
"url": "https://api.jotform.com/form/formId/submissions?apiKey=apikey",
"json": {
submission : data
},
"headers": {
"Content-type": "application/json"
}
}, (error:any, response:any) => {
if (error) {
console.log(error);
}
else {
if(response){
console.log(response);
console.log('=================');
}
}
});
I'm getting an error of questionId.
Here is my error
body:
{ responseCode: 500,
message: 'error',
content: 'QuestionID not found on form questions!',
duration: '29ms' } }
Please help me!
Related
I have an app that connects doctors with patients. When I use the API to create a meeting for the doctor, I get the following error:
{ code: 200, message: 'Invalid api key or secret.' }
var defer = Q.defer();
var op = {
method: "POST",
uri: "https://api.zoom.us/v2/users/" + options.email + "/meetings",
body: {
topic: "test.com 1-1 session",
type: 2,
start_time: new Date(options.startDate),
duration: 40,
settings: {
host_video: "true",
participant_video: "true"
}
},
headers: {
'content-type': 'application/json',
authorization: `Bearer ${options.refreshToken}`
},
json: true //Parse the JSON string in the response
};
request.post(op, (error, response, body) => {
if (error) {
defer.reject(error);
}
defer.resolve(body);
});
return defer.promise;
Can someone please help?
I'm trying to hit the Intercom API to retrieve a list of conversations and I can't figure out what's wrong. Here is the code:
const request=require('request')
const search_intercom=(admin_id, callback) => {
const options = {
url: 'https://api.intercom.io/conversations/search',
method: 'POST',
headers: {
Authorization: 'Bearer <token>'
},
json: {
query: JSON.stringify({
"field": "teammate_ids",
"operator": "=",
"value": admin_id
})
}
};
request(options, (error, {body} = {}) => {
if (error) {
callback('unable to connect to intercom API', undefined)
} else if (body.length === 0) {
callback('something went wrong', undefined)
} else {
callback(undefined, {
conversation_id: body.conversations[0].id,
client_name: body.conversations[0].source.author.name
})
console.log(body)
}
})
}
module.exports = search_intercom
I was able to wire it up correctly with the web server, so when I debug, options.json.query.admin_id does contain a valid id.
It breaks and says
conversation_id: body.conversations[0].id,
TypeError: Cannot read property '0' of undefined
Here is the content of the body response:
{
type: 'error.list',
request_id: '<some request_id>',
errors: [ { code: 'server_error', message: 'Server Error' } ]
}
Where should I look? I've tried a few different variations of options for sending the payload and I am guessing this is the issue, but I can't find the winning formula...
It looks like I got the body all wrong.
options should look like this instead:
const options = {
url: 'https://api.intercom.io/conversations/search',
method: 'POST',
headers: {
Authorization: 'Bearer <token>'
},
json: true,
body: {
query: {
"field": "teammate_ids",
"operator": "=",
"value": JSON.stringify(admin_id)
}
}
};
I want to show data from JSON URL on my facebook messenger bot. I've tried with a lot of code approach. However, I couldn't still get it. I just could show the data the terminal with console.log.
This is the code I use to get data from JSON URL:
const ambilDataProfil = (sender_psid) => {
//sorry this url below is not valid I write intentionally for my privacy data.
request({
url: 'https://sorry-url-privately.firebaseio.com/server/saving-data/users.json',
method: "GET",
}, function(error, response, body){
let jsonBody = JSON.parse(response.body);
let resp = jsonBody.Ndus;
console.log(resp);
let respon = {"text": "resp"};
callSendAPI(sender_psid, respon);
}
// console.log(body.Ndus.goldar);
);
};
function callSendAPI(sender_psid, response) {
// Construct the message body
let request_body = {
"recipient": {
"id": sender_psid
},
"message": response
}
// Send the HTTP request to the Messenger Platform
request({
"uri": "https://graph.facebook.com/v2.6/me/messages",
"qs": { "access_token": PAGE_ACCESS_TOKEN },
"method": "POST",
"json": request_body
}, (err, res, body) => {
if (!err) {
console.log('message sent!')
} else {
console.error("Unable to send message:" + err);
}
});
}
I have to send some parameters of String type along with one array in my body.
But it throws me an error message:
First argument must be String or buffer
Here is my code:
var tokenList = JSON.parse(req.body.tokenList);
var mobParams = {
"tokens": tokenList,
"profile": "<myprofile>",
"notification": {
"title": req.body.title,
"message": req.body.text
}
};
request({
method: "POST",
url: 'https://api.ionic.io/push/notifications',
headers: {
"content-type": "application/json",
"authorization": "Bearer ********"
},
body: (mobParams)
}, function(error, response, body){
console.log('Ionic push error', error);
console.log('IOnic push res', response);
console.log('IOnic push body', body);
if(!error){
return res.send({
code: 1,
message: "success"
});
}else{
return res.send({
code: 0,
message: error
});
}
How can I pass my array inside this object to request npm?
Also, I would like to add that this implementation works pretty fine through front-end but I have separate codebase which requires me to hit multiple FCM requests i.e. in a loop. So I would be happy to have a solution as neither ionic push nor FCM push works
For the FCM push I am trying the code below :
let desktopParams = {
"notification": {
"title": 'Merchant Portal Notifications',
"body": req.body.text
// "click_action" : action
},
"to": '/topics/' + topic
};
request({
method: "POST",
json: true,
url: 'https://fcm.googleapis.com/fcm/send',
headers: {
"content-type": "application/json",
"authorization": "key=****"
},
body: desktopParams
}, function(error, response, body){
console.log('error', error);
console.log('response', response);
console.log('body', body);
//return body;
});
you should try stringifying your tokenList & req.body.text before you join it with with the string (try to log it and post the outcome so that people will have a better idea about the objects...):
var cho = [{name:'john',lname:'cena'},{name:'mary',lname:'jane'}];
var che = {list:[{name:'john',lname:'cena'},{name:'mary',lname:'jane'}],group:'people'}
var mobParams = {
"tokens":JSON.parse(JSON.stringify(cho)),
"profile": "<myprofile>",
"notification": {
"title": "Some title",
"message":JSON.parse(JSON.stringify(che))
}
};
console.log(JSON.stringify(mobParams));//----->{"tokens":[{"name":"john","lname":"cena"},{"name":"mary","lname":"jane"}],"profile":"<myprofile>","notification":{"title":"Some title","message":{"list":[{"name":"john","lname":"cena"},{"name":"mary","lname":"jane"}],"group":"people"}}}
var arr = [{name:'john',lname:'cena'},{name:'mary',lname:'jane'}]
var js = JSON.stringify(arr);
var blabla = {'item':'something',js}
console.log(blabla); //-----> Object {item: "something", js: "[{"name":"john","lname":"cena"},{"name":"mary","lname":"jane"}]"}
var js = JSON.parse(JSON.stringify(arr));
var blabla = {'item':'something',js}
console.log(blabla); //-----> Object {item: "something", js: Array(2)}
var js = JSON.parse(arr);
var blabla = {'item':'something',js}
console.log(blabla); //-----> "SyntaxError: Unexpected identifier"
I am Creating REST API Call in jira using below code :-
var loginArgs = {
data: {
"username": "singhharwinder#seasiainfotech.com",
"password": "Seasia#123"
},
headers: {
"Content-Type": "application/json"
}
};
client.post("http://jira.atlassian.com/rest/auth/1/session",
loginArgs,function (data, response) {
if (response.statusCode == 200) {
console.log('succesfully logged in, session:', data.session);
var session = data.session;
var searchArgs = {
headers: {
cookie: session.name + '=' + session.value,
"Content-Type": "application/json"
},
data: {
jql: "type=Bug AND status=Closed"
}
};
client.post("http://jira.atlassian.com/rest/api/2/search", searchArgs, function (searchResult, response) {
console.log('status code:', response.statusCode);
console.log('search result:', searchResult);
});
} else {
throw "Login failed :(";
}
});
It is giving me "Reference Error: client is not defined".
Please help me .