Chilkat Online Tools

SQL Server / Salesforce Platform APIs / Search for Records Suggested by Autocomplete and Instant Results

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    DECLARE @queryParams int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @queryParams OUT

    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'q', ''
    EXEC sp_OAMethod @queryParams, 'UpdateString', @success OUT, 'sobject', ''

    -- Adds the "Authorization: Bearer <access_token>" header.
    EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'QuickRequestParams', @resp OUT, 'GET', 'https://domain.com/services/data/v{{version}}/search/suggestions', @queryParams
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @queryParams
        RETURN
      END

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @queryParams


END
GO

Curl Command

curl -G -d "q="
	-d "sobject="
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
https://domain.com/services/data/v{{version}}/search/suggestions

Postman Collection Item JSON

{
  "name": "Search for Records Suggested by Autocomplete and Instant Results",
  "protocolProfileBehavior": {
    "disableBodyPruning": true
  },
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": ""
    },
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/search/suggestions?q&sobject",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "search",
        "suggestions"
      ],
      "query": [
        {
          "key": "type",
          "value": "",
          "description": "Required when the sobject value is feedItem. Including this parameter for all other sobject values doesn’t affect the query. Specifies that the type of Feed is questions. Valid value: question.",
          "disabled": true
        },
        {
          "key": "fields",
          "value": "",
          "description": "Optional. Used for creating lookup queries. Specify multiple fields using a comma-separated list. Specifies which lookup fields to be returned in the response.",
          "disabled": true
        },
        {
          "key": "dynamicFields",
          "value": "",
          "description": "Optional. Available in API version 48.0 and later. Used to return additional dynamic fields. Specify multiple options using a comma-separated list. For example, if dynamicFields=secondaryField then each suggested record in the results contains an additional field besides Id and Name (or Title) based on the next eligible field in the search layout.",
          "disabled": true
        },
        {
          "key": "groupId",
          "value": "",
          "description": "Optional. Specifies one or more unique identifiers of one or more groups that the question to return was posted to. Specify multiple groups using a comma-separated list. This parameter is only applicable when the parameter type equals question. Don’t use with the userId.",
          "disabled": true
        },
        {
          "key": "ignoreUnsupportedSObjects",
          "value": "",
          "description": "Optional. Specifies what to do if unsupported objects are included in the request. If false and an unsupported object is included, an error is returned. If true and an unsupported object is included, the object is ignored and no error is returned. See the Unsupported Objects section for reference. The default is false.",
          "disabled": true
        },
        {
          "key": "limit",
          "value": "",
          "description": "Optional. Specifies the maximum number of suggested records to return. If a limit isn’t specified, 5 records are returned by default. If there are more suggested records than the limit specified, the response body’s hasMoreResults property is true.",
          "disabled": true
        },
        {
          "key": "networkId",
          "value": "",
          "description": "Optional. Specifies one or more unique identifiers for the community(ies) that the question to return is associated to. Specify multiple communities using a comma-separated list. This parameter is only applicable when the parameter type equals question or parameter sobject equals user.",
          "disabled": true
        },
        {
          "key": "topicId",
          "value": "",
          "description": "Optional. Specifies the unique identifier of the single topic that the question to return was tagged as. This parameter is only applicable when the parameter type equals question.",
          "disabled": true
        },
        {
          "key": "userId",
          "value": "",
          "description": "Optional. Specifies one or more unique identifiers of one or more users who authored the question to return. Specify multiple users using a comma-separated list. This parameter is only applicable when the parameter type equals question. Don’t use with the groupId.",
          "disabled": true
        },
        {
          "key": "useSearchScope",
          "value": "",
          "description": "Optional. Available in API version 40.0 and later. The default value is false. If false, the objects specified in the request are used to suggest records. If true, in addition to the objects specified in the request, the user's search scope is used to suggest records. The search scope is the list of objects a user uses most frequently.\nIf the request doesn’t specify an object, use useSearchScope=true.\nIf useSearchScope=true and the user's search scope is empty, the default search scope is used to suggest records.\nOnly the first 10 objects are used to suggest records.\nObjects specified in the sobject parameter are prioritized over objects in the user's search scope.\nValues for the ignoreUnsupportedSObjects parameter aren’t applied to the objects in the search scope.",
          "disabled": true
        },
        {
          "key": "where",
          "value": "",
          "description": "Optional. A filter that follows the same syntax as the SOQL WHERE clause. URLs encode the expression.\nUse the clause for an object, or globally for all compatible objects. An example of an object-specific clause is: account.where=name%20LIKE%20%27Smith%25%27. An example of a global clause is: where=name%20LIKE%20%27Smith%25%27. The parameter must be lower case. Any object-specific where clauses override the global where clause. You can’t use this parameter for the Question object.",
          "disabled": true
        },
        {
          "key": "q",
          "value": null
        },
        {
          "key": "sobject",
          "value": null
        }
      ]
    },
    "description": "Returns a list of suggested records whose names match the user’s search string. The suggestions resource provides autocomplete results and instant results for users to navigate directly to likely relevant records, before performing a full search.\n\nhttps://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_search_suggest_records.htm"
  },
  "response": [
  ]
}