Saved Queries

Getting saved queries for an entity (Saved Searches for an entity)

Retrieves all saved queries for a given entity. You can provide comma separated list of entities to get queries across them, such as Account or Opportunity.

cURL Command

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

Example Response Payload

{
  "items": [
    {
      "_entity": "Account",
      "name": "All Accounts",
      "description": null,
      "queryUuid": "59783e65-0513-4169-9fae-db9d7d1b105c",
      "savedSearchNumber": "59783e65-0513-4169-9fae-db9d7d1b105c",
      "access": "Public",
      "enabled": "Y",
      "isDefault": true,
      "isUpdatable": false,
      "user": null,
      "userName": "SEED_DATA_FROM_APPLICATION",
      "keywords": null,
      "sort": [
        {
          "attribute": "_score",
          "direction": "descending"
        }
      ],
      "q": null,
      "keywordsFields": [
        "PartyUniqueName",
        "PrimaryAddress",
        "PrimaryContact",
        "PrimaryIndustry",
        "Owner"
      ],
      "aggregations": {
        "PrimaryIndustry": {
          "ignore": true,
          "terms": {
            "attribute": "PrimaryIndustry",
            "maxNumberOfBuckets": 5,
            "other": false,
            "missing": false,
            "localize": true
          }
        },
        "Owner": {
          "ignore": true,
          "terms": {
            "attribute": "Owner",
            "maxNumberOfBuckets": 5,
            "other": false,
            "missing": false,
            "localize": true
          }
        },
        "SalesProfileType": {
          "ignore": true,
          "terms": {
            "attribute": "SalesProfileType",
            "maxNumberOfBuckets": 5,
            "other": false,
            "missing": false,
            "localize": true
          }
        }
      },
      "fields": [
        "PartyId",
        "PartyUniqueName",
        "PrimaryAddress",
        "PrimaryContact",
        "PrimaryIndustry",
        "Owner"
      ],
      "excludeFields": null,
      "applicationData": {
        "461e5791-9f15-4cd1-b5cd-19e8480cbce4": {
          "isListView": true,
          "listLayoutFields": [
            "PartyUniqueName",
            "PrimaryAddress",
            "PrimaryContact",
            "PrimaryIndustry",
            "Owner"
          ],
          "listLayoutFieldWidths": [
            {
              "attribute": "PartyUniqueName",
              "width": 328
            },
            {
              "attribute": "PrimaryAddress",
              "width": 381
            },
            {
              "attribute": "PrimaryContact",
              "width": 218
            },
            {
              "attribute": "PrimaryIndustry",
              "width": 200
            },
            {
              "attribute": "Owner",
              "width": 160
            },
            {
              "attribute": "_actions",
              "width": 76
            }
          ]
        }
      },
      "highlights": {
        "pre": [
          "<b>"
        ],
        "post": [
          "</b>"
        ],
        "fields": [
          "PartyUniqueName",
          "PrimaryAddress",
          "PrimaryContact",
          "PrimaryIndustry",
          "Owner"
        ]
      }
    }
  ],
  "totalResults": 4,
  "count": 1,
  "hasMore": true,
  "limit": 1,
  "offset": 0,
  "links": [
    {
      "rel": "self",
      "href": "https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries?onlyData=true&limit=1&language=en&entity=Account&applications=461e5791-9f15-4cd1-b5cd-19e8480cbce4&metaModelUuid=36d1d9e6-94d0-4409-9042-ba718fa1448a",
      "kind": "collection",
      "name": "self"
    },
    {
      "rel": "canonical",
      "href": "https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries?onlyData=true&limit=1&language=en&entity=Account&applications=461e5791-9f15-4cd1-b5cd-19e8480cbce4&metaModelUuid=36d1d9e6-94d0-4409-9042-ba718fa1448a",
      "kind": "collection",
      "name": "canonical"
    },
    {
      "rel": "parent",
      "href": "https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05",
      "kind": "item",
      "name": "parent"
    },
    {
      "rel": "next",
      "href": "https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries?metaModelUuid=36d1d9e6-94d0-4409-9042-ba718fa1448a&onlyData=true&offset=1&limit=1&language=en&entity=Account&applications=461e5791-9f15-4cd1-b5cd-19e8480cbce4",
      "kind": "collection",
      "name": "next"
    }
  ]
}

Saving a query

Below is sample payload to store a query. You must enter the saved preference, name, and preference type query results.

cURL Command

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

Example Request Payload

{
  "entity": "Lead",
  "name": "Sample My Open Leads",
  "access": "Private",
  "fields": [
    "LeadId",
    "Rank",
    "Name",
    "CustomerAccount",
    "DealAmount",
    "StatusCode",
    "CreationDate",
    "CurrencyCode",
    "TimezoneCode"
  ],
  "keywords": null,
  "q": {
    "op": "$and",
    "criteria": [
      {
        "op": "$in",
        "attribute": "StatusCode",
        "values": [
          "QUALIFIED",
          "UNQUALIFIED"
        ]
      },
      {
        "op": "$eq",
        "attribute": "RecordSet",
        "value": "MYLEADS"
      }
    ]
  },
  "sort": [
    {
      "attribute": "Name",
      "direction": "ascending",
      "attribute_lv": "Name"
    }
  ],
  "language": "en",
  "keywordsFields": [
    "Rank",
    "Name",
    "CustomerAccount",
    "StatusCode"
  ],
  "excludeFields": null,
  "highlights": {
    "pre": [
      "<b>"
    ],
    "post": [
      "</b>"
    ],
    "fields": [
      "Rank",
      "Name",
      "CustomerAccount",
      "DealAmount",
      "StatusCode",
      "CreationDate"
    ]
  },
  "skipInValidFields": true,
  "applicationData": {
    "461e5791-9f15-4cd1-b5cd-19e8480cbce4": {
      "isListView": true,
      "listLayoutFields": [
        "Rank",
        "Name",
        "CustomerAccount",
        "DealAmount",
        "StatusCode",
        "CreationDate"
      ],
      "listLayoutFieldWidths": [
        {
          "attribute": "Rank",
          "width": 72
        },
        {
          "attribute": "Name",
          "width": 288
        },
        {
          "attribute": "CustomerAccount",
          "width": 370
        },
        {
          "attribute": "DealAmount",
          "width": 184
        },
        {
          "attribute": "StatusCode",
          "width": 173
        },
        {
          "attribute": "CreationDate",
          "width": 205
        },
        {
          "attribute": "_actions",
          "width": 76
        }
      ]
    }
  }
}

Getting a Saved Search based on the Saved Search Number

Below is an example to get a particular Saved Search for a given entity based on the Saved Search number.

cURL Command

https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries/59783e65-0513-4169-9fae-db9d7d1b105c?metaModelUuid=81f4c054-90c6-45a0-a096-beec3ad68d42&entity=Account&savedSearchNumber=889937479

Example Response Payload

{   
    "name":"Parser",
    "entity":"Account",
    "keywords":"parser",
    "sort": [{ "attribute":"PartyUniqueName","direction":"ascending"}],
    "fields":["PartyUniqueName","PrimaryAddress"],
    "q":{"op": "$all" , "attribute": "PartyUniqueName", "value": "Technologies United"},
    "excludeFields" : ["PrimaryIndustry"],
    "aggregations":{
        "CreationDate":{
            "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"}
                ]
            }
        }
    },
    "keywordsFields":["PrimaryIndustry"]
}

Updating a query

To update a saved query. Please note that name is mandatory.

cURL Command

https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries/59783e65-0513-4169-9fae-db9d7d1b105c?metaModelUuid=81f4c054-90c6-45a0-a096-beec3ad68d42&entity=Account

Example Request Payload

{   
    "name":"demo json parser",
    "entity":"Account",
    "keywords":"parser",
    "sort": [{ "attribute":"PartyUniqueName","direction":"ascending"}],
    "fields":["PartyUniqueName","PrimaryAddress"],
    "q":{"op": "$all" , "attribute": "PartyUniqueName", "value": "Technologies United"},
    "excludeFields" : ["PrimaryIndustry"],
    "aggregations":{
        "CreationDate":{
            "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"}
                ]
            }
        }
    },
    "keywordsFields":["PrimaryIndustry"]
}