4

我正在尝试以编程方式检索 Salesforce 报告的结果。

经常引用的是这个关于从 web 端抓取结果的博客,但该方法不受支持:http ://sfdc-heretic.warped-minds.com/2006/04/10/progmatic-access-to-salesforcecom-reports/ .

我可以通过 REST api 获取报告列表:

require 'restforce'
restforce_client = Restforce.new(
    :refresh_token => <refresh token>,
    :client_id => <client id>,
    :client_secret => <client secret>
)
reports = restforce.query("SELECT Id,DeveloperName FROM Report")
reports.last.DeveloperName
 => "Rob_Test_Report"

我还尝试通过 Metadata SOAP API ReportFolder 对象进行检索:

require 'metaforce'
metaforce = Metaforce.new(
    :username => <username>,
    :password => <password>,
    :security_token => <security token>
)
report_folders = metaforce.list_metadata('ReportFolder')
report_folders.last.full_name
 => "RobTestReportFolder"

我可以看到文件夹。我还没有检索到内容,但即使我这样做了,我似乎只会获取报告本身的元数据(即过滤条件),而不是报告的结果。元数据 API 在这里讨论:https ://success.salesforce.com/questiondetail?qId=a1X30000000IQ8pEAG 。这个对吗?

几年前我看到了这个类似的问题,但不知道它是否正确或 API 中有任何更改: 如何使用 Apex 在 SalesForce 中以编程方式访问报告

是否可以通过支持的 Salesforce API 导出或提取报告结果?

4

2 回答 2

2

You cannot retrieve the results of a report without using the Analytics API, which as of the Summer '13 release will be available only as a pilot. If you want to participate in the pilot, let me know and I will submit your request.

Once in the Pilot, you use a REST endpoint passing in the Id of the report. You will have two endpoints-- a describereport endpoint and a runreport enndpoint. What is returned from describeReport is a JSON representation of the metadata for the report (describes the dimensions and facts and such) and from runReport a JSON representation of the data.

Once you have the data you can do with it what you will. The report data is only available at the summary level and for the pilot only summary and matrix reports are supported.

于 2013-05-08T17:29:28.193 回答
1

我不知道有任何编程方式可以做到这一点。Conga 应用程序可能是一种选择,但我相信他们从报告的元数据中获取过滤器并构建匹配的 SOQL 查询......

您提到的博客文章应该有效。您可能错过了在 cookie 中设置会话 ID 之类的东西。

黑客,容易出错,网络抓取的方式是使用类似于我对 Apex 所做的技巧:https ://salesforce.stackexchange.com/questions/4303/scheduled-reports-as-attachment 。从理论上讲,只要您拥有用户的会话 ID(无论是从登录会话传递还是从 SOAP 登录调用自己生成...),您就可以从任何其他 API 访问中提取类似的东西。

还请查看 metadaddy 对我的相关问题的回答:https ://salesforce.stackexchange.com/questions/4692/screen-scrape-salesforce-with-rest-get-call-from-apex

于 2013-05-06T21:13:39.447 回答