5

I need to create simple Report with Lead/Contact data. How can I do it via REST/SOAP API? REST is preferred.

5

Ask and you shall receive. See Introducing the Salesforce Reports and Dashboards REST API, and more specifically Get Report Data without Saving Changes to or Creating a Report (emphasis mine):

Get Report Data without Saving Changes to or Creating a Report

Run a report without creating a report or changing an existing one by making a POST request to the query resource. Get report data without filling up your org with unnecessary reports.

Example

Get report data using the query resource.

/services/data/v37.0/analytics/reports/query

Include report criteria as reportMetadata in the POST request body. This POST request gets data about Opportunities:

{
"reportMetadata" : {
    "aggregates" : [ "RowCount" ],
    "chart" : null,
    "crossFilters" : [ ],
    "currency" : null,
    "description" : null,
    "detailColumns" : [ "OPPORTUNITY_NAME", "TYPE", "LEAD_SOURCE", "AMOUNT", "CLOSE_DATE", "NEXT_STEP", "STAGE_NAME", "PROBABILITY", "FISCAL_QUARTER", "AGE", "CREATED_DATE", "FULL_NAME", "ROLLUP_DESCRIPTION", "ACCOUNT_NAME" ],
    "developerName" : "OpportunityReport",
    "division" : null,
    "folderId" : "00DD000000086ujMAA",
    "groupingsAcross" : [ ],
    "groupingsDown" : [ ],
    "hasDetailRows" : true,
    "hasRecordCount" : true,
    "historicalSnapshotDates" : [ ],
    "id" : "00OD0000001leVCMAY",
    "name" : "Matrix",
    "reportBooleanFilter" : null,
    "reportFilters" : [ ],
    "reportFormat" : "MATRIX",
    "reportType" : {
      "label" : "Opportunities",
      "type" : "Opportunity"
    },
    "scope" : "organization",
    "showGrandTotal" : true,
    "showSubtotals" : true,
    "sortBy" : [ ],
    "standardDateFilter" : {
      "column" : "CLOSE_DATE",
      "durationValue" : "CUSTOM",
      "endDate" : null,
      "startDate" : null
    },
    "standardFilters" : [ {
      "name" : "open",
      "value" : "all"
    }, {
      "name" : "probability",
      "value" : ">0"
    } ]
  }
}

The Report section of the documentation (specifically the PATCH Request Body section) goes into great detail about how to structure the JSON. It looks like the same structure.

Also, another useful endpoint listed in the Describe section of the documentation can help you inspect existing reports you want to mimic if you're stuck.

 /services/data/<latest API version>/analytics/reports/<report ID>/describe

Here is a basic example I got working for Lead data. Set the folderId to your own Organization Id.

{
    "reportMetadata": {
        "aggregates": ["RowCount"],
        "chart": null,
        "crossFilters": [],
        "currency": null,
        "description": null,
        "detailColumns": ["OWNER", "FIRST_NAME", "LAST_NAME", "TITLE", "COMPANY", "LEAD_SOURCE", "RATING", "STREET", "EMAIL"],
        "developerName": "LeadReport",
        "division": null,
        "folderId": "00D290000000SuCEAU",
        "groupingsAcross": [],
        "groupingsDown": [],
        "hasDetailRows": true,
        "hasRecordCount": true,
        "historicalSnapshotDates": [],
        "id": "",
        "name": "Matrix",
        "reportBooleanFilter": null,
        "reportFilters": [],
        "reportFormat": "MATRIX",
        "reportType": {
            "label": "Leads",
            "type": "LeadList"
        },
        "scope": "user",
        "showGrandTotal": true,
        "showSubtotals": true,
        "sortBy": [],
        "standardDateFilter": {
            "column": "CREATED_DATE",
            "durationValue": "CUSTOM",
            "endDate": null,
            "startDate": null
        },
        "standardFilters": []
    }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.