Salesforce:通过 R 中的 URL 下载报告 [英] Salesforce: Download Reports via URL in R

查看:40
本文介绍了Salesforce:通过 R 中的 URL 下载报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过 URL 下载 Salesforce 中可用的报告,例如

I try to download the reports available in Salesforce via the URL, e.g.

http://YOURInstance.my.salesforce.com/012389u13541?export=1&enc=UTF-8&xf=csv

在 R 中.

我已经进行了一些调查以通过 HTTR-GET 访问该报告,但是,直到今天还没有任何有意义的结果.不幸的是,R 正在下载 HTML 代码而不是所需的 csv 文件.我也试图实现这里建议的方法:

I already did some investigation to access the report via HTTR-GET, however, up until today without any meaningful outcomes. Unfortunately, R is downloading HTML-code instead of the desired csv file. I also tried to realize the approach suggested here:

https://salesforce.stackexchange.com/questions/47414/download-a-report-using-python

RForcecom"包允许通过 API 进行交互,但我无法弄清楚如何在 R 中实现上述解决方案.

The package "RForcecom" allows the interaction via an API, but I was not able to figure out how to realize above solution in R.

一般 GET 请求:

GET("http://YOUR_Instance.my.salesforce.com/012389u13541?export=1&enc=UTF-8&xf=csv")

我希望输出为 csv 格式,但我收到的报告数据为 html 源代码.

I expect the output to be in csv format, but I receive the report data as html source code.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3...
<html>
<head>
    <meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
...

你们中有人遇到过同样的问题并且可以提供指导吗?任何形式的帮助都非常感谢.提前致谢!

Did anyone of you guys encounter same issues and can provide guidance? Any kind of help is much appreciated. Thanks in advance!

更新和不工作的R-Snippet:

UPDATED and not-working R-Snippet:

library(RForcecom)
library(httr)
username='username'
password='password'
instanceURL <- "https://login.salesforce.com/"
session <- rforcecom.login(username, password, instanceURL)
sid=as.character(session['sessionID'])

url='http://YOURInstance.my.salesforce.com/012389u13541?export=1&enc=UTF-8&xf=csv'
getData=GET(url,add_headers('Content-Type'='application/json','Authorization'=paste0("Bearer ",sid),'X-PrettyPrint'='1'),set_cookies('sid'=sid))

推荐答案

我最近遇到了同样的问题,有一个神奇的参数需要添加到查询中:isdtp=p1

I recently struggled with the same issue, there's a magic parameter you need to add to the query : isdtp=p1

所以如果你尝试:http://YOURInstance.my.salesforce.com/012389u13541?export=1&enc=UTF-8&xf=csv&isdtp=p1

它应该直接将文件返回给您.

it should return you the file directly.

这篇关于Salesforce:通过 R 中的 URL 下载报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆