[英]Can't Send JSON request by ajax post to hubspot create contact api via chrome Extension popup.js
I am developing an extension for Chrome to update my contacts in hubspot via API. 我正在开发Chrome扩展程序,以通过API更新集线器中的联系人。
I used $.ajax
method in popup.js
of Chrome extension but can't post data it gives Error: 400
我在Chrome扩展程序的popup.js
中使用了$.ajax
方法,但无法发布它给出Error: 400
数据Error: 400
Here is my code for manifest.json
这是我的manifest.json
代码
{
"name": "myext",
"version": "1.0",
"manifest_version": 2,
"description": "update contact",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html",
"defaul": "run!"
},
"options_ui": {
"page": "settings.html",
"chrome_style": true,
"open_in_tab": true
},
"content_scripts": [ {"css": [ "style.css" ] } ],
"permissions": [ "tabs", "<all_urls>", "storage","cookies", "http://*/*","https://*/*" ]
}
And My Request in popup.js
is: 在popup.js
,我的要求是:
var myData = '{"properties":[{ "property": "email", "value": "testinga2112pis@hubspot.com" }, { "property": "firstname", "value": "Adrian" }, ] }';
$.ajax({
type: "POST",
data : JSON.stringify(myData),
url: " http://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/harisbintari1221q@gmail.com/?hapikey=9d5ade00-6367-45be-a2c4-8fd22144aaa4",
contentType: "application/json; charset=utf-8",
success: function(data){
alert('success');
console.log(data)
},
error : function(error) {
alert('error -->' + eval(error));
}
});
A little late but for those searching on the same issue - HubSpot does not support CORS
as a security feature, meaning that you cannot call HubSpot APIs directly from the browser using JQuery
or other. 有点晚了,但对于那些在同一问题上进行搜索的人-HubSpot不支持CORS
作为安全功能,这意味着您不能使用JQuery
或其他工具直接从浏览器中调用HubSpot API。
You might consider moving that part of your application to the server side and passing the data you that wish to save to your own endpoint before submitting it to HubSpot. 您可能会考虑将应用程序的这一部分移到服务器端,然后将想要保存的数据传递到自己的端点,然后再将其提交给HubSpot。
Please read these docs and discussion on HubSpot. 请阅读这些文档和有关HubSpot的讨论 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.