Post Operations for Search

This topic lists some examples of using the POST method for searching.

Query a Stored query (Saved Search)

Below payload describes how to query based on a saved query.

cURL Command

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

Example Request Payload

{   "entity":"Account",
    "copiedFrom":"https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries/{queryUuid}"
}

Limit

Specifies a limit to constraint the list of data rows retrieved from elastic server.

cURL Command

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

Example Request Payload

{   "entity":"Account",
    "copiedFrom":"https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries/{queryUuid}",
    "limit":3
}

Offset

Specifies a starting index to start a search from.

cURL Command

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

Example Request Payload

{   "entity":"Account",
    "copiedFrom":"https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries/{queryUuid}",
    "limit":3,
    "offset":10
}

Links

To specify a set of links to display in data rows, please note that pagination links if any would be kept intact. Also do not confuse below payload for disabling pagination links as it is a transient query which does not generate pagination. But the same is not the case with query results preference.

cURL Command

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

Example Request Payload

{   "entity":"Account",
    "copiedFrom":"https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries/{queryUuid}",
    "limit":3,
    "offset":10,
    "links":["canonical"]
}

Exclude links

Specify a set of links to exclude. Pagination links if any are kept intact.

cURL Command

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

Example Request Payload

{   "entity":"Account",
    "copiedFrom":"https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries/{queryUuid}",
    "limit":3,
    "offset":10,
    "excludeLinks":["self","parent"]
}

No links

To disable all links from data rows. Pagination links are kept intact.

cURL Command

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

Example Request Payload

{   "entity":"Account",
    "copiedFrom":"https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries/{queryUuid}",
    "limit":3,
    "offset":10,
    "onlyData":true
}

Language

To specify a particular language to localize the search result.

cURL Command

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

Example Request Payload

{   "entity":"Account",
    "copiedFrom":"https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries/{queryUuid}",
    "limit":3,
    "offset":10,
    "language":"KO"
}

Sort

To specify a field to sort upon. Options are asc and desc.

cURL Command

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

Example Request Payload

{   "entity":"Account",
    "copiedFrom":"https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries/{queryUuid}",
    "limit":3,
    "offset":10,
    "sort": [{ "attribute":"PartyUniqueName","direction":"ascending"}]
}

Fields

To specify a list of fields to filter data. Please observe the use of *(asterisk).

cURL Command

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

Example Request Payload

{   "entity":"Account",
    "copiedFrom":"https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries/{queryUuid}",
    "limit":3,
    "offset":10,
    "fields":["PartyUniqueName","Primary*"]
}

Exclude fields

To exclude a set of fields from the search results. Please observe the use of *(asterisk).

cURL Command

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

Example Request Payload

{   "entity":"Account",
    "copiedFrom":"https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries/{queryUuid}",
    "limit":3,
    "offset":10,
    "excludeFields":["Primary*"]
}

Keywords

To specify a set of keyword to base the search upon

cURL Command

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

Example Request Payload

{   "entity":"Account",
    "limit":3,
    "keywords":"united,bengaluru"
}

Search with date bucket

Below sample describes a payload for searching with a date bucket. Please note that we only support equals operator for date. Also read about supported date buckets at Elastic Search REST: Date Buckets.

cURL Command

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

Example Request Payload

{  
    "entity" : "Account",
    "fields": ["PartyUniqueName","PrimaryAddress","CreationDate"],
    "q" : {"op": "$wi", "attribute": "CreationDate", "value1": "now-1y/y", "value2": "now"}
}

Search across entities

Keywords

To search across entities with a given keyword. Please note that sort, fields and exclude fields are not supported in this prototype.

cURL Command

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

Example Request Payload

{
    "keywords":"test",
    "offset":90,
    "limit":3
}

Cross Entity

To search on a given set of entities with given fields and exclude fields. Please note that keywords are global and not specific to entity. Also sort is not supported for cross entity searches.

cURL Command

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

Example Request Payload

{
    "keywords":"united",
    "offset":0,
    "entities":
    {  
        "Account":{
            "fields":["PartyUniqueName","PrimaryAddress"]
        },
        "Contact":{
            "fields":["PartyName","JobTitle"]
        }
    },
    "onlyData":true
}

Query a top-level nested entity

This example show how you can search for a nested entity at the top-level.

cURL Command

https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries?
Example Request Payload
{
    "entity": "Activity",
    "limit": 10,
    "offset": 0,
    "fields": ["ActivityId"],
    "nestedEntities": {
        "ListOfContacts": {
            "limit": 10,
            "offset":0,
            "sort":[{ "attribute":"ListOfContacts.ContactId.PartyNumber","direction":"ascending"}]
        },
        "ListOfResourcesForTheTeam":{
             
        }
    },
    "q": {
        "op": "$or",
        "innerQuery":true,
        "criteria": [
            {
                "op": "$eq",
                "attribute": "ListOfContacts.ContactId.PrimaryAddress.State",
                "value":"CA"
            },
            {
                "op":"$eq",
                "attribute":"ListOfContacts.ContactId.PrimaryAddress.City",
                "value":"WESTMINSTER"
            }
        ]
    }
}

Query a child-level nested entity

This example show how you can search for a nested entity at the child-level.

cURL Command

https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries?
Example Request Payload
{
    "entity": "CRMProductGroup",
    "nestedEntities": {
        "ListOfProductGroupRelations.RelatedProductGroup.ListOfProductGroupRoots": {
            "limit": 10,
            "offset": 0
        }
    },
    "limit": 1,
    "offset": 2,
    "q": {
        "op": "$and",
        "innerQuery": true,
        "criteria": [
            {
                "op": "$eq",
                "attribute": "ListOfProductGroupRelations.RelatedProductGroup.ListOfProductGroupRoots.UsageCode",
                "value": "BASE"
            },
            {
                "op": "$eq",
                "attribute": "ListOfProductGroupRelations.RelatedProductGroup.ListOfProductGroupRoots.ActiveFlag",
                "value": false
            }
        ]
    }
}

Query a child-level nested under a first-level list

This example show how you can search for a nested entity at the first-level list.

cURL Command

https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries?
Example Request Payload
{
    "entity": "Account",
    "limit": 1,
    "offset": 1,
    "nestedEntities": {
        "ListOfAddresses.ListOfPartySiteUses": {
            "limit": 1,
            "offset": 0
        }
    },
    "q": {
        "op": "$and",
        "innerQuery": true,
        "criteria": [
            {
                "op": "$eq",
                "attribute": "ListOfAddresses.ListOfPartySiteUses.SiteUseType",
                "value": "BILL_TO"
            }
        ]
    },
    "fields": [
        "PartyId"
    ]
}

Perform global search across multiple entities

This example show how you can perform a global search with multiple entities.

Note:

If you have fields that are common between entities, then the results will include extra fields across entities.

cURL Command

https://servername.fa.us2.oraclecloud.com/crmRestApi/searchResources/11.13.18.05/custom-actions/queries?
Example Request Payload
{
    "offset": 0,
    "entities": {
        "Account": {
            "nestedEntities": {
                "ListOfContacts": {
                    "limit": 4
                }
            },
            "fields": [
                "NumberOfContacts"
            ],
            "q": {
                "op": "$and",
                "innerQuery": true,
                "criteria": [
                    {
                        "op": "$pr",
                        "attribute": "ListOfContacts"
                    },
                    {
                        "op": "$gt",
                        "attribute": "NumberOfContacts",
                        "value": 10
                    }
                ]
            }
        },
        "Contact": {
            "fields":["PartyId"],
            "nestedEntities": {
                "ListOfPhones": {
                    "limit": 4
                }
            },
            "q": {
                "op": "$and",
                "innerQuery": true,
                "criteria": [
                    {
                        "op": "$eq",
                        "attribute": "ListOfPhones.PhoneType",
                        "value": "WORK"
                    }
                ]
            }
        }
    },
    "onlyData": true
}