I'm doing a chatbot based project. I came across Chatbase and I wanted to implement chatbase to analyse the data more indept I get from my chatbot. However, I am confused as to how to write the post method to the chatbase api and keeps receiving error 405 or 400. I don't have much experience in writing ajax requests so most probably the problem might be with the format of the code. If anyone is willing to help me out, I would really appreciate it. Thanks
Code for reference:
function chatbaseInput() {
$.ajax({
type: "POST",
url: chatbaseURL,
contentType: "charset=utf-8",
dataType: "json",
headers: {
"Access-Control-Allow-Origin": "website link"
},
data: JSON.stringify({
api_key: "apikey",
type: "user",
user_id: "140012004300",
time_stamp: 1516765680000,
platform: "Website",
message: "Default Welcome Intent",
intent: "Welcome Intent",
version: "1.0"
}),
success: function (data) {
setResponse("Chatbase works!");
},
error: function () {
setResponse("Chatbase not working");
}
});
}
Chatbase requests are meant to be sent from your server, they do not accept calls from a browser (CORS is not enabled).
I did the exact same thing before I discovered the same as you. We now proxy our calls via the server.
Here is the link where they mention this:
https://discuss.api.ai/t/chatbase-integration-and-api-ai/9966/15
Related
I'm trying to use API Gateway as my server for a small database project, and I'm using Ajax to upload data to the server. I know I need to enable CORS to allow me to have cross-domain requests, and I've tried over and over multiple different methods of enabling CORS that I've found online, with no luck. No matter what I do, I seem to get the same error callback: {"readyState":0,"responseText":"","status":0,"statusText":"error"}
Here is the code I am using in the ajax request (for obvious reasons I omitted the URL of the API):
$.ajax({
type: 'POST',
url: API_URL,
data: data,
crossDomain: true,
dataType: "text",
contentType: 'text/plain',
success: (data, status, xhr) => {
alert("Success");
},
error: (e) => {
alert(JSON.stringify(e));
}
});
CORS is in fact enabled in my API, I can confirm this by checking the integration response for my OPTIONS method (there's only one resource and the only methods that exist for it are POST and OPTIONS). Any pointer in the right direction would be appreciated, trying to make this work has been very frustrating.
I have been trying to post an attachment on Yammer using Yammer Javascript api. There is not much documentation available on Yammer regarding this. Can someone help me to achieve this.
Thanks.
Hopes this may help you to solve the issue,
You can use POST:/pending-attachments yammer API for posting the images in yammer.
But If you want to create yammer post with images, POST:/messages.json can be used with attaching files - attachment_N or pending_attachment_N as a multipart form field.
Use this link for info - Yammer message API
adding a sample code using JavaScript SDK -
let otherFormData = {
"group_id": groupId,
"body": message,
"og_url": postUrl,
"og_fetch": false,
"og_title": title,
"og_image": og_image,
"og_description": summary,
"og_object_type": og_object_type,
"direct_to_user_ids": []
};
let formData = new FormData();
formData.append("attachment1", imgData_Base64, AfileName);
for (let i in otherFormData) {
formData.append(i, otherFormData[i]);
}
window.yam.platform.request({
url: "messages.json",
method: "POST",
data: formData,
processData: false,
contentType: false,
type: 'POST',
dataType: 'json',
success: (response) => {
console.info("The request is successful. ", response);
},
error: (err) => {
console.info("There is an error in the request.", err);
}
});
Thank you in advance for any assistance you maybe able to provide. I'm trying to post from my app to an app group that I have created. Using the code below it completes the request successfully but the data returned is empty. Please tell me what I'm doing wrong. I did also notice that it's not performing a POST but rather a GET.
$.ajax({
type: 'POST',
url: 'https://graph.facebook.com/v2.1/'+g_id+'/feed?access_token='+User["User AccessToken"],
data: JSON.stringify({
message: g_mes
}),
dataType: "jsonp",
success: function(data){
console.log(data);
},
error: function(data1){
console.log(data1);
}
})
You really should use the JavaScript SDK for the API. Here is a basic tutorial: https://developers.facebook.com/docs/javascript/quickstart/v2.1
And this is what the API call would look like:
FB.api('/' + g_id + '/feed', 'post', {message: g_mes}, function(response) {
console.log(response);
});
See Facebook docs for a code example too: https://developers.facebook.com/docs/graph-api/reference/v2.1/group/feed
You donĀ“t even need to worry about the Access Token. You just need to use FB.login with the appropriate permissions in the scope parameter to authorize the user.
I am sending username and password as request parameter to the server in AJAX and trying to show the response message. But not able to showing the response message.In fiddler it is showing the response message. But while on the browser screen it is not showing.PLEASE somebody help me out where i am wrong or need to change anything..
I have written like this-
$(document).ready(function () {
$("#btnCity").click(function () {
$.ajax({
type: "POST",
url: "http://test.xyz.com/login",
crossDomain: true,
contentType: "application/json; charset=utf-8",
data: { username: "abc", password: "1234" },
dataType: "JSONP",
jsonpCallback: 'jsonCallback',
async: false,
success: function (resdata) {
alert(resdata);
},
error: function (result, status, err) {
alert(result.responseText);
alert(status.responseText);
alert(err.Message);
}
});
});
});
TL;DR: I guess the problem is on the server side of your code (that we don't know yet).
At first: I don't know why it fails for you. I've taken your code and ran it against a public available JSONP API, that returns the current IP of your system and it worked.
Please try yourself using the URL: http://ip.jsontest.com/.
So most probably, the server doesn't return the right response to the JSONP request. Have a look at the network tab in developer tools. With your current code, the answer of the server should be something like:
jsonCallback({'someResponseKeys': 'someResponseValue'});
Note: The header should contain Content-Type:application/javascript!
BTW, even if this doesn't for now solve your problem - here are some tweaks, I'd like to advice to you:
Don't set async to false, at the documentation of jQuery.ajax() says:
Cross-domain requests and dataType: "jsonp" requests do not support synchronous
operation.
You don't need to set a jsonpCallback, because jQuery will generate and handle (using the success function a random one for you. Quote from the docs:
This value will be used instead of the random name automatically generated by jQuery. It is preferable to let jQuery generate a unique name as it'll make it easier to manage the requests and provide callbacks and error handling.
So here comes my code:
$(document).ready(function () {
$("#btnCity").click(function () {
$.ajax({
type: "POST",
url: "http://ip.jsontest.com/",
crossDomain: true,
data: { username: "abc", password: "1234" },
dataType: "JSONP",
success: function (resdata) {
console.log("success", resdata);
},
error: function (result, status, err) {
console.log("error", result.responseText);
console.log("error", status.responseText);
console.log("error", err.Message);
}
});
});
});
A working example can be found here.
Another solution, like Yonatan Ayalon suggested, can be done with a predefined function and then setting the jsonpCallback explicitly to the function that should be called.
if you see the response in Fiddler, it seems that the issue is in the callback function.
you are doing a jsonP call - which means that you need a callback function to "read" the response data.
Do you have a local function that calls "jsonCallback"?
this is a simple jsonP request, which initiates the function "gotBack()" with the response data:
function gotBack(data) {
console.log(data);
}
$.ajax({
url: 'http://test.xyz.com/login' + '?callback=?',
type: "POST",
data: formData,
dataType: "jsonp",
jsonpCallback: "gotBack"
});
You can try with the following methods and close every instance of chrome browser in task manager, then open browser in web security disable mode by the command "chrome.exe --disable-web-security"
success: function (resdata) {
alert(resdata);
alert(JSON.stringify(resdata));
},
And the better option to debug the code using "debugger;"
success: function (resdata) {
debugger;
alert(resdata);
alert(JSON.stringify(resdata));
},
I am trying to test the security of an application which uses AJAX requests.
I have tried using the Firebug terminal but the data does not make it through to the server.
Is this type of testing even possible in Firebug or would I need a different program?
$.ajax({
url: 'http://127.0.0.1:5000/admin/update',
type: 'POST',
data: JSON.stringify(
{extension:'x', mobile:'x', mobex:'x', altContact:'x', fax:'x', userid:'x', lcode:'x', desk: 'x'}
),
contentType: "application/json",
success: function(data) {
}
});
The back end is Python:
#jsonify
def updateExceptLocationAndDesk(self):
print "Params:",request.params
The results is:
Params: UnicodeMultiDict([])
I got this working, but Im not sure how.
$.post(
'/admin/update',
{'extension':'123', 'mobile':'123', 'mobex':'123', 'altContact':'123', 'fax':'123', 'userid':'19700', 'lcode':'456456', 'desk': '123'},
function (data)
{
if(data=='success')
{
$('#message').show();
$('#message').html('Record successfully updated.');
setTimeout(function(){$('#message').fadeOut('slow')}, 5000);
}
},
'json'
);
I dont think the jsonify changed anything. If anyone comes across this at least there is an answer here!