Terms Aggregation

For term aggregations, a list of include terms and excluded terms can be specified. If not, a max number of buckets can be specified. Ignore indicates if the query should exclude the filters for that attribute while calculating aggregations.

cURL Command

https://servername.fa.us2.oraclecloud.com /crmRestApi/searchResources/11.13.18.05/custom-actions/queries?

Example Request Payload

{   
    "entity":"Account",
    "fields": ["PrimaryIndustry","PartyUniqueName","Owner"],
    "limit":1,
    "aggregations":{
        "PrimaryIndustry":{
            "ignore": true,
            "terms":{
                "attribute": "PrimaryIndustry",
                "maxNumberOfBuckets" : 5,
                "other": true,   
                "missing": true,
                "localize": true
            }
        }
    }
}

Example Response Payload

{
    "items": [
        {
            "Owner": {
                "PrimaryPhone": null,
                "PartyId": 100010037920358,
                "PartyName": "ToddAR BeelerAR",
                "PrimaryEmail": {
                    "ContactPointId": 300100031421212,
                    "EmailAddress": "sendmail-test-discard@oracle.com",
                    "OverallPrimary": true
                }
            },
            "PrimaryIndustry": null,
            "PartyId": 100100013674961,
            "PartyUniqueName": "Hype Orcl (Stamford, US)",
            "_entity": "Account",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/entities/Account/100100013674961?metaModelUuid=687c0ae3-dd32-4202-bd38-82a4103faac3",
                    "kind": "item",
                    "name": "canonical"
                }
            ]
        }
    ],
    "aggregations": [
        {
            "PrimaryIndustry": {
                "other": 37,
                "missing": 3048,
                "buckets": [
                    {
                        "key": 1900,
                        "count": 17,
                        "localizedKey": "High Technology"
                    },
                    {
                        "key": 1300,
                        "count": 12,
                        "localizedKey": "Communications"
                    },
                    {
                        "key": 2500,
                        "count": 8,
                        "localizedKey": "Professional Services"
                    },
                    {
                        "key": 1500,
                        "count": 7,
                        "localizedKey": "Education & Research"
                    },
                    {
                        "key": 2700,
                        "count": 7,
                        "localizedKey": "Retail"
                    }
                ]
            }
        }
    ],
    "count": 1,
    "hasMore": true,
    "limit": 1,
    "offset": 0,
    "totalResults": 3136
}

Range Aggregations

Range Aggregation By Date

Below is a sample payload to create a range aggregation according to date.

cURL Command

https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries?

Example Request Payload

{   
    "entity":"Account",
    "limit":1,
    "fields":["PartyUniqueName","CreationDate"],
    "aggregations":{
        "CreationDate":{
            "ignore":true,
            "range":{
                "attribute":"CreationDate",
                "ranges":[
                    {"key": "ThisQuarter", "from": "now/M-3M", "to": "now"},
                    {"key": "NextQuarter", "from": "now", "to": "now/M+3M"},
                    {"key": "ThisYear", "from": "now/y", "to": "now/y+1y"},
                    {"key": "LastQuarter", "from": "now/M-6M", "to": "now/M-3M"},
                    {"key": "LastYear", "from": "now/y-1y", "to": "now/y"}
                ]
            }
        }
    }
}

Example Response Payload

{
    "items": [
        {
            "PartyId": 300100169111795,
            "PartyUniqueName": "Apple (Cupertino, US)",
            "CreationDate": "2018-12-08T11:56:31.910+0000",
            "_entity": "Account",
            "links": [
                {
                    "rel": "canonical",
                    "href": "https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/entities/Account/300100169111795?onlyData=false&language=US",
                    "kind": "item",
                    "name": "canonical"
                }
            ]
        }
    ],
    "aggregations": [
        {
            "CreationDate": {
                "buckets": [
                    {
                        "key": "LastYear",
                        "count": 0
                    },
                    {
                        "key": "ThisYear",
                        "count": 509
                    },
                    {
                        "key": "LastQuarter",
                        "count": 0
                    },
                    {
                        "key": "ThisQuarter",
                        "count": 0
                    },
                    {
                        "key": "NextQuarter",
                        "count": 0
                    }
                ]
            }
        }
    ],
    "count": 1,
    "hasMore": true,
    "limit": 1,
    "offset": 0,
    "totalResults": 509
}

Range Aggregation by Numbers

Below is a sample payload to create a range aggregation according to numbers.

cURL Command

https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries?

Example Request Payload

{   
    "entity":"Opportunity",
    "limit":1,
    "fields":["*"],
    "aggregations":{
        "PrimaryRevenue.WinProb":{
            "ignore":true,
            "range":{
                "attribute":"PrimaryRevenue.WinProb",
                "ranges":[
                    {"key": "0 to 20", "from": 0, "to": 20},
                    {"key": "20 to 40", "from": 20, "to": 400},
                    {"key": "40 to 60", "from": 40, "to": 60},
                    {"key": "60 to 80", "from": 60, "to": 80},
                    {"key": "gt 80", "from": 80}
                ]
            }
        }
    }
}

Highights

Highlights help a user to explore the set of data that was retrieved when a search was initiated. It highlights the operators that resulted in a row being queried.

cURL Command

https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries?

Example Request Payload

{   "entity":"Account",
    "limit":2,
    "fields": ["PartyUniqueName","PrimaryAddress","CreationDate"],
    "sort": [{ "attribute":"PartyUniqueName","direction":"ascending"}],
    "keywords":"united",
    "highlights" : {
        "pre": ["<em>"],
        "post": ["<em>"],
        "fields":["PartyUniqueName"]
    }
}

Example Response Payload

{
            "PartyId": 300100169110365,
            "PartyUniqueName": "Pinnacle Technologies (London, GB)",
            "CreationDate": "2018-12-08T11:54:06.196+0000",
            "PrimaryAddress": {
                "CountryCode_localizedValue": "United Kingdom",
                "PostalCode": "SE1 4HJ",
                "State": "Battersea",
                "Address1": "10 Battersea Park",
                "CountryCode": "GB",
                "CurrencyCode": "USD",
                "OverallPrimary": true,
                "City": "London",
                "FormattedAddress": "10 Battersea Park,LONDON,Battersea,SE1 4HJ,UNITED KINGDOM",
                "PartySiteId": 300100169110369,
                "IdentifyingAddressFlag": true
            },
    ...
    "count": 8,
    "hasMore": false,
    "limit": 10,
    "offset": 0,
    "totalResults": 8
}