我正在尝试通过REST API在Tableau服务器上执行某些操作,我需要使用Auth令牌。我尝试使用Postman的signin API,它就像一个魅力。但是,相同的代码正在提供"错误请求"尝试从我的网页上调用javacript代码时出错。
var dataVal = {
"credentials": {
"name": "admin",
"password": "admin",
"site": {
"contentUrl": "MySite"
}
}
};
$.ajax({
contentType: 'application/json',
data: JSON.stringify(dataVal),
dataType: 'jsonp',
success: function (data) {
console.log("call succeeded");
},
error: function (request, textStatus, errorThrown) {
console.log(request.getAllResponseHeaders());
},
processData: false,
type: 'POST',
url: 'http://mytableauserver/api/2.6/auth/signin'
});
以上代码返回令牌,siteid,来自邮递员的用户ID但返回"" BAD REQUEST"来自javascript代码的错误。任何指针都将受到高度赞赏。
答案 0 :(得分:0)
对于其他人来说,Tableau 现在支持 CORS,但目前仅支持 Tableau Server
。
Enabling CORS on Tableau Server for the REST API
For security, most web browsers restrict HTTP requests to the same origin. That is, to
access a resource on a server through an API, the request must come from the same
origin (server), or a proxy must be set up to handle the request.
Tableau Server now supports Cross-Origin Resource Sharing (CORS), so you can do away
with your proxy and call the REST API from the browser. The CORS mechanism is
currently only enabled for Tableau Server, and can be turned on by server
administrators in a couple of steps using the TSM command-line tool. To learn more,
see the description of the vizportal.rest_api.cors.allow_origin option in tsm
configuration set Options. As a security measure, you should make API calls to Tableau
Server using the HTTPS protocol (SSL or TLS). See Using HTTPS (SSL/TLS) for API Calls.
Add the origins that need access to the Tableau Server.
Determine the origins (servers) you want to allow access to the REST API, and use the
tsm configuration set command with the vizportal.rest_api.cors.allow_origin option.
For example, to grant access to one two origins, https://mysite and https://yoursite,
you would stop the server (tsm stop) and then use the following command:
tsm configuration set -k vizportal.rest_api.cors.allow_origin -v
https://mysite,https://yoursite
You can enter multiple origins. Use a comma to separate the entries.
Note: You could also use an asterisk (*) as a wild card to match all sites. This is
not recommended as it allows access from any origin that has access to the server and
could present a security risk. Do not use an asterisk (*) unless you fully understand
the implications and risks for your site.
Enable CORS on Tableau Server.
Use the tsm configuration set command with the vizportal.rest_api.cors.enabled option.
The default setting is false, so set this to true as follows:
tsm configuration set -k vizportal.rest_api.cors.enabled -v true
Update your Tableau Server configuration (tsm pending-changes apply) to restart
Tableau Server and make the changes take effect. Only the origins you specify will
have access.
https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_concepts_fundamentals.htm