r - 如何使用 R 通过 Tableau API 发布/更新 Tableau 数据源
问题描述
我正在帮助一个团队使用 Tableau Server API 以编程方式(从 R 并最终从 SAS)发布新的或更新的数据文件。我一直在关注 API 文档,并且能够成功地获得自己的凭据、获取密钥、请求工作簿和项目 ID……但我一直在尝试上传新的数据源。
例如,我可以使用下面的(第一个)代码来生成下面的(第二个)请求:
请求格式错误的任何想法?在 github(Python 或其他)上似乎没有任何我可以建模的示例 - Tableau 似乎没有所有 API 的示例。
感谢您对此的任何帮助。
-麦克风
# > Prepare request ####
overwrite_flag = "true"
url = base_url %>% paste0("sites/", dph_site_id, "/datasources", "?overwrite=", overwrite_flag)
boundary_string = "boundary-string"
request_header=c('Content-type' = "multipart/mixed", boundary=boundary_string)
xml_request =
xmlNode("tsRequest",
xmlNode("datasource", attrs = c(name = test_datasource_name, useRemoteQueryAgent = "use-remote-query-agent-flag"),
xmlNode("project", attrs = c(id = target_project_ID)))) %>%
XML::toString.XMLNode() %>% str_replace_all("\\\n", "") %>% str_replace_all("\"", "'")
xml_request
xml_temp_file = tempfile(); xml_request %>% writeLines(xml_temp_file)
api_response <- POST(url,
add_headers(request_header),
add_headers("X-Tableau-Auth" = tableau_session_tbl$auth_token),
body = list(
request_payload = upload_file(xml_temp_file, type = "text/xml"),
tableau_datasource = upload_file(test_datasource_filename,
type = "Content-Type:application/octet-stream")
),
encode = "multipart", verbose())
-> POST /api/3.8/sites/ed4d47de-f7ea-47e8-8eba-d8507d426623/datasources?overwrite=true HTTP/1.1
-> Host: internaldashboards.ncdhhs.gov
-> User-Agent: libcurl/7.64.1 r-curl/4.3 httr/1.4.2
-> Accept-Encoding: deflate, gzip
-> Accept: application/json, text/xml, application/xml, */*
-> boundary: boundary-string
-> X-Tableau-Auth: fImLlDJyQIusChNRyb36xw|VDAOY920d3b8fOXiBvEIZma1Uo3Tezrd
-> Content-Length: 777
-> Content-Type: multipart/mixed; boundary=------------------------24379841295f2aa2
->
>> --------------------------24379841295f2aa2
>> Content-Disposition: attachment; name="request_payload"; filename="file35a478543d9a"
>> Content-Type: text/xml
>>
>> <tsRequest> <datasource name='letters and numbers' useRemoteQueryAgent='use-remote-query-agent-flag'> <project id='9d0152af-a190-44eb-9172-b1d31b37a971'/> </datasource></tsRequest>
>>
>> --------------------------24379841295f2aa2
>> Content-Disposition: attachment; name="tableau_datasource"; filename="test_datasource.csv"
>> Content-Type: Content-Type:application/octet-stream
>>
>> letters,LETTERS,numbers
>> a,A,1
>> b,B,2
>> c,C,3
>> d,D,4
>> e,E,5
>> f,F,6
>> g,G,7
>> h,H,8
>> i,I,9
>> j,J,10
>> k,K,11
>> l,L,12
>> m,M,13
>> n,N,14
>> o,O,15
>> p,P,16
>> q,Q,17
>> r,R,18
>> s,S,19
>> t,T,20
>> u,U,21
>> v,V,22
>> w,W,23
>> x,X,24
>> y,Y,25
>> z,Z,26
>>
>> --------------------------24379841295f2aa2--
<- HTTP/1.1 400 Bad Request
<- Date: Mon, 08 Mar 2021 21:06:50 GMT
<- Server: Tableau
<- Content-Type: application/json;charset=utf-8
<- Content-Length: 130
<- X-Tableau: Tableau Server
<- P3P: CP="NON"
<- X-UA-Compatible: IE=Edge
<- X-Content-Type-Options: nosniff
<- X-XSS-Protection: 1; mode=block
<- Referrer-Policy: no-referrer-when-downgrade
<- Content-Security-Policy-Report-Only: connect-src * https://*.tiles.mapbox.com https://api.mapbox.com; default-src blob:; font-src * data:; frame-src * data:; img-src * data: blob:; object-src data:; report-uri /vizql/csp-report; script-src * blob:; style-src * 'unsafe-inline'
<- Connection: close
Response is 400 - badly formed.
-> POST /api/3.8/sites/ed4d47de-f7ea-47e8-8eba-d8507d426623/datasources?overwrite=true HTTP/1.1
-> Host: internaldashboards.ncdhhs.gov
-> User-Agent: libcurl/7.64.1 r-curl/4.3 httr/1.4.2
-> Accept-Encoding: deflate, gzip
-> Accept: application/json, text/xml, application/xml, */*
-> boundary: boundary-string
-> X-Tableau-Auth: fImLlDJyQIusChNRyb36xw|VDAOY920d3b8fOXiBvEIZma1Uo3Tezrd
-> Content-Length: 777
-> Content-Type: multipart/mixed; boundary=------------------------24379841295f2aa2
->
>> --------------------------24379841295f2aa2
>> Content-Disposition: attachment; name="request_payload"; filename="file35a478543d9a"
>> Content-Type: text/xml
>>
>> <tsRequest> <datasource name='letters and numbers' useRemoteQueryAgent='use-remote-query-agent-flag'> <project id='9d0152af-a190-44eb-9172-b1d31b37a971'/> </datasource></tsRequest>
>>
>> --------------------------24379841295f2aa2
>> Content-Disposition: attachment; name="tableau_datasource"; filename="test_datasource.csv"
>> Content-Type: Content-Type:application/octet-stream
>>
>> letters,LETTERS,numbers
>> a,A,1
>> b,B,2
>> c,C,3
>> d,D,4
>> e,E,5
>> f,F,6
>> g,G,7
>> h,H,8
>> i,I,9
>> j,J,10
>> k,K,11
>> l,L,12
>> m,M,13
>> n,N,14
>> o,O,15
>> p,P,16
>> q,Q,17
>> r,R,18
>> s,S,19
>> t,T,20
>> u,U,21
>> v,V,22
>> w,W,23
>> x,X,24
>> y,Y,25
>> z,Z,26
>>
>> --------------------------24379841295f2aa2--
<- HTTP/1.1 400 Bad Request
<- Date: Mon, 08 Mar 2021 21:06:50 GMT
<- Server: Tableau
<- Content-Type: application/json;charset=utf-8
<- Content-Length: 130
<- X-Tableau: Tableau Server
<- P3P: CP="NON"
<- X-UA-Compatible: IE=Edge
<- X-Content-Type-Options: nosniff
<- X-XSS-Protection: 1; mode=block
<- Referrer-Policy: no-referrer-when-downgrade
<- Content-Security-Policy-Report-Only: connect-src * https://*.tiles.mapbox.com https://api.mapbox.com; default-src blob:; font-src * data:; frame-src * data:; img-src * data: blob:; object-src data:; report-uri /vizql/csp-report; script-src * blob:; style-src * 'unsafe-inline'
<- Connection: close
解决方案
推荐阅读
- opencv - 使用 Opencv 进行 Python 多线程视频处理 - 停止视频后 setMouseCallback 不起作用
- c# - 添加具有对旧核心项目的核心引用的 nuget
- c++ - 来自 Boost.org 的 Boost Log 1.65.0 示例的链接错误
- exchangewebservices - EWS 请求在 Mac 上没有响应并出现错误
- arduino - 草图代码中可用的 Arduino 草图名称
- python - 在一个数据帧和另一个数据帧之间执行子字符串查找
- mysql - 如何在从站之间复制特定行
- html - 网格系统上的完整容器
- powershell - 替换两个特定字符串之间的行 - cmd 中的 sed 等效项
- c# - C# (Unity) -- 数据没有进入脚本