Tableau:无法使用REST上传数据源.[NodeJS]



我试图上传一个数据源到我的表格网站使用以下代码:

const request = require('request')
const fs = require('fs')

const options = {
url: 'https://prod-apnortheast-a.online.tableau.com/api/3.12/sites/578341b7-325c-4dda-be08-ff0b10c4b18c/datasources',
headers: {
Authorization: 'Bearer xxxxxxxxxxxxxx',
'Content-Type': 'application/xml;charset=UTF-8',
boundary: 'boundary-string'
},
body: `--boundary-string
Content-Disposition: name="request_payload"
Content-Type: text/xml
<tsRequest>
<datasource name="datasource-name"
description="datasource-description">
<connectionCredentials name="xxxx@abc.com"
password="xxxxxx"/>
<project id="96ec15ee-eef1-41ac-beda-1f03d9209305" />
</datasource>
</tsRequest>
--boundary-string
Content-Disposition: name="tableau_datasource"; filename="datasource-file-name"
Content-Type: application/octet-stream
This is the content of data source file.
Hello from Mayank
--boundary-string--`
}

function callback (error, response, body) {
if (error) {
console.log(error)
}
console.log( body, response.headers, response.statusCode)
}

request.post(options, callback)

但不是成功上传,我得到以下错误:

响应主体:

<?xml version='1.0' encoding='UTF-8'?><tsResponse xmlns="http://tableau.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-3.12.xsd"><error code="406000"><summary>Bad Request</summary><detail>Content type 'application/xml;charset=UTF-8' not supported</detail></error></tsResponse>

响应标头:

{
'content-type': 'application/xml;charset=UTF-8',
date: 'Mon, 30 Aug 2021 08:17:57 GMT',
p3p: 'CP="NON"',
'referrer-policy': 'strict-origin-when-cross-origin',
server: 'Tableau',
'set-cookie': [
'hid=pdanaa-hap01; domain=.prod-apnortheast-a.online.tableau.com; path=/; HttpOnly; Secure; SameSite=None',
'AWSELB=05DBF7950E7E74D8AC3E3765F2EF65B6BB96F639EDB7A6D781435ACF3E27CEC2643898FB33239EFFBCA90E45D6EE0951AC6ECA4251ACA4E386D74627D58239403899B395F5F04C31144F69D44D5789C3FA7D6D9DC6;PATH=/;DOMAIN=.prod-apnortheast-a.online.tableau.com;SECURE;HTTPONLY;SAMESITE=None'
],
'strict-transport-security': 'max-age=31536000; includeSubDomains',
tableau_error_code: '0xE3C7443A',
tableau_error_source: 'NeedsClassification',
tableau_service_name: 'vizportal',
tableau_status_code: '2',
'x-content-type-options': 'nosniff',
'x-tableau': 'Tableau Server',
'x-ua-compatible': 'IE=Edge',
'x-xss-protection': '1; mode=block',
'content-length': '365',
connection: 'Close'
}

响应状态码:406

引用:

  1. https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_publishing.htm publish_data_source
  2. https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm

根据Tableau的文档

请求的Content-Type头必须设置为multipart/mixed;边界= boundary-string。

虽然我使用PHP,我有这个完全相同的错误,而你试图使用API发布流。改为"multipart/mixed";在Content-Type中为我修复了它(虽然我的问题还没有结束)。所以可以把代码改成

...
headers: {
Authorization: 'Bearer xxxxxxxxxxxxxx',
'Content-Type': 'multipart/mixed; boundary=boundary-string'
},
...

可以做到。

请注意内容类型的变化,并且该边界本身不是像你那样的标题。

请注意,您的示例代码可能仍然会生成400个错误,因为它不是一个有效的数据源文件。由于我运行Tableau Server,我不得不通过跟踪服务器上的日志来进行大量故障排除,并试图找出问题所在。

最新更新