Find categories by name
/km/api/v1/categories/findByName
This method returns a list of categories whose name matches with the passed in nameToken value. The method can be called to search for categories and products under a particular parent, in this case the parentId parameter is required. Alternatively the method can search for required or optional categories under a particular contentType by specifying the contentTypeId and the required parameters. The externalType parameter which can be either CATEGORY or PRODUCT is required for both search types. When caller sets the optional withNoChildren parameter to true, categories and products that have children will not be included in the response. When the caller sets the topLevelOnly parameter to true, the parentId search case is limited to the parent's immediate children on the content type search the results are limited to the root categories or products. Individual parameters are described in detail below.
If the user making this request is a contact only categories in the currently active view will be searched.
As mentioned the service takes in various request parameters. Please note this is applicable for both Products and Categories
- parentId : The parentId of the Category. If parentId is passed then the search will happen in that parent's context. Optional parameter.
- externalType : The externalType will determine if the caller is asking for Products and Categories. For categories set it to CATEGORY and for products set it to PRODUCT. Required parameter.
- contentTypeId : When this is passed the code will do the search under the passed in ContentType. Optional parameter.
- required : When this is set the code will do the search under the passed in ContentType which are marked as Required. Optional parameter.
- nameToken : The text query for the name of the Product or Category. Together with nameTokenSearchType, user can set it different ways to locate matching names. Required parameter.
- nameTokenSearchType : Name searching formats. It can be STARTS_WITH, ENDS_WITH and CONTAINS. Optional parameter.
- withNoChildren : When this is set to true the search will return Categories or Products with no children. Optional parameter.
- topLevelOnly : When this is set to true the search will only return Categories or Products that are at the immediate children level. Optional parameter.
- At lease one and only one from parentId and contentTypeId should be passed.
- Search is case insensitive, so nameToken=Aa or nameToken=aa or nameToken=AA will return same response.
- Do not pass any wildcard characters,use the nameTokenSearchType instead.
- For name matching, name in request locale will be used. Caller can override request locale using Accept-Lang header. If name does not exists in request locale, name in repository's default locale will be used.
This resource supports the withParents request parameter.
When the withParents request parameter is set to true, for each category returned the parent categories of that category will be included, ordered from the root category to the immediate parent of each returned category.
Possible Errors:
- OK-GEN0030 - When the following fields are in mismatch combination:
- both contentTypeId and parentId are not null and not empty.
- parentId is not null and not empty and required is true.
- OK-GEN0031 - When the following fields are NULL:
- both contentTypeId and parentId are null or empty.
- nameToken is null or empty.
- OKDOM-GEN0006 - when nameTokenSearchType has invalid enum value.
The example URI to get schema and catalog of the resource is as follows:
http://<IM_REST_API_HOST>/km/api/latest/categories/findByName?parentId={parent_record_id_of_my_category}&externalType=PRODUCT&nameToken=phone
http://<IM_REST_API_HOST>/km/api/latest/categories/findByName?contentTypeId={content_type_record_id}&externalType=PRODUCT&nameToken=phone&required=true
http://<IM_REST_API_HOST>/km/api/latest/categories/findByName?contentTypeId={content_type_record_id}&externalType=PRODUCT&nameToken=phone&required=false&nameTokenSearchType=STARTS_WITH
http://<IM_REST_API_HOST>/km/api/latest/categories/findByName?contentTypeId={content_type_record_id}&externalType=PRODUCT&nameToken=phone&required=false&nameTokenSearchType=STARTS_WITH&topLevelOnly=true
http://<IM_REST_API_HOST>/km/api/latest/categories/findByName?contentTypeId={content_type_record_id}&externalType=PRODUCT&nameToken=phone&required=false&nameTokenSearchType=STARTS_WITH&topLevelOnly=true&withParents=true
Request
- application/json
- application/xml
-
contentTypeId(optional): string
The Id of the ContentType
-
externalType: string
The Category or Product identifier
-
nameToken: string
The Category or Product name to search on
-
nameTokenSearchType(optional):
The Category or Product name to search. Valid values are CONTAINS, STARTS_WITH, ENDS_WITH. If nothing is passed it will be defaulted to CONTAINS.Allowed Values:
[ "STARTS_WITH", "ENDS_WITH", "CONTAINS" ]
-
parentId(optional): string
The Category or Product Parent identifier
-
required(optional): boolean
Identifies that the search is for a required category or not
-
topLevelOnly(optional): boolean
Limits the search to immediate children Category or Product
-
withNoChildren(optional): boolean
Identifies that the search should return Category or Product that contains no children.
Response
- application/json
- application/xml
200 Response
object
ResultList CategoryKey
-
allOf
Collection Paging Resource
Title:
Collection Paging Resource
Oracle base collection resource schema definition. -
object
ResultList CategoryKey-allOf[1]
Collection Paging Resource
-
allOf
Base Collection Resource
Title:
Base Collection Resource
Oracle base collection resource schema definition. -
object
Collection Paging Resource-allOf[1]
Base Collection Resource
-
object
Singular Resource
Title:
Singular Resource
Oracle base singular resource schema definition. -
object
Base Collection Resource-allOf[1]
object
Singular Resource
object
-
count(optional):
integer
Number of resource instances returned in the current range.
-
hasMore(optional):
boolean
Boolean value that is set to true if more resources are available on the server than the subset returned in current page.
-
limit(optional):
integer
Actual paging size used by the server.
-
offset(optional):
integer
Offset value used in the current page.
-
totalResults(optional):
integer
Total count of the resource instances, including both the instances in the current range and the instances on the server that satisfy the request.
array
-
Array of:
object instanceLink
Metadata describing link description objects that MAY appear in the JSON instance representation.
object
-
href:
string
URI [RFC3986] or URI Template [RFC6570]. If the value is set to URI Template, then the "templated" property must be set to true.
-
mediaType(optional):
string
Media type, as defined by RFC 2046, describing the link target.
-
method(optional):
string
HTTP method for requesting the target of the link.
-
profile(optional):
string
Link to the metadata of the resource, such as JSON-schema, that describes the resource expected when dereferencing the target resource..
-
rel:
string
Name of the link relation that, in addition to the type property, can be used to retrieve link details. For example, href or profile.
-
templated(optional):
boolean
Boolean flag that specifies that "href" property is a URI or URI Template. If the property is a URI template, set this value to true. By default, this value is false.
object
-
object
Singular Resource
Title:
Singular Resource
Oracle base singular resource schema definition. -
object
CategoryKey-allOf[1]
object
-
childrenCount(optional):
integer
This field will return number of immediate children a category has.
This field will only be populated if childrenCount query parameter is passed in with value true.
Example URIs for the this parameter are as follows:
- http://<IM_REST_API_HOST>/km/api/categories/{id}?childrenCount=true&mode=KEY
- http://<IM_REST_API_HOST>/km/api/categories?childrenCount=true&mode=KEY
- http://<IM_REST_API_HOST>/km/api/categories?q=contentTypeRefKey eq 'FAQ'&childrenCount=true&mode=KEY
-
description(optional):
string
Description of the Category object
-
externalId(optional):
integer
The unique identifier used while integrating the repository data with the external system.
-
externalType(optional):
string
The type of the category used while integrating the repository data with the external system. Valid options are PRODUCT and CATEGORY.
-
name(optional):
string
The name of the category.
-
objectId(optional):
string
The hierarchichal position of the category
-
parents(optional):
array parents
This field will return all parents of category.
This field will only be populated if withParents query parameter is passed in with value true.
Example URIs for the this parameter are as follows:
- http://<IM_REST_API_HOST>/km/api/categories/{id}?withParents=true&mode=KEY
- http://<IM_REST_API_HOST>/km/api/categories?withParents=true&mode=KEY
- http://<IM_REST_API_HOST>/km/api/categories?q=contentTypeRefKey eq 'FAQ'&withParents=true&mode=KEY
- http://<IM_REST_API_HOST>/km/api/categories/{id}?childrenCount=true&withParents=true&mode=KEY
-
recordId(optional):
string
The unique record ID of the Category object.
-
referenceKey(optional):
string
The reference key for the Category object. Category objects support multiple languages. This field can be used to identify the associated objects for all languages.
-
responseLocale(optional):
string
This is a custom field that will get populated if a name is translated into the default locale when the translated name is not found.
array
This field will return all parents of category.
This field will only be populated if withParents query parameter is passed in with value true.
Example URIs for the this parameter are as follows:
- http://<IM_REST_API_HOST>/km/api/categories/{id}?withParents=true&mode=KEY
- http://<IM_REST_API_HOST>/km/api/categories?withParents=true&mode=KEY
- http://<IM_REST_API_HOST>/km/api/categories?q=contentTypeRefKey eq 'FAQ'&withParents=true&mode=KEY
- http://<IM_REST_API_HOST>/km/api/categories/{id}?childrenCount=true&withParents=true&mode=KEY
Examples
The following example shows how to find a list of categories that match the specified category name by submitting a get request on the REST resource using cURL.
curl GET http://<IM_REST_API_HOST>/km/api/latest/categories/findByName
Example of Response Header
The following shows an example of the response header.
-H "kmauthtoken: {\"siteName\":\"ORACLE_KNOWLEDGE\",\"integrationUserToken\":\"+eCJYkxKwj5HUaIiJYun0/TpatwT1LmtcsF05W33xnEojifV/AsLDj9RpN0lKuorTMNKeSE1tgC7svVL+BzntqDON4KiM1HFlpxvXEUCB0P2w0Xrs75McygqxdVaDSE9"}" \ -H "Accept: application/json"
Example of Response Body
The following example shows the contents of the response body in JSON format:
{ "items" : [ { "referenceKey" : "REFERENCEKEY_VALUE", "name" : "NAME_VALUE", "externalId" : 1428416790963, "externalType" : "EXTERNALTYPE_VALUE", "description" : "DESCRIPTION_VALUE", "links" : [ { "rel" : "canonical", "href" : "http://<IM_REST_API_HOST>/km/api/{version}/{resourceURI}", "mediaType" : "application/json, application/xml", "templated" : true, "method" : "GET", "profile" : "http://<IM_REST_API_HOST>/km/api/{version}/metadata-catalog/{resourceName}" } ] }, ], "hasMore" : false, "limit" : 20, "offset" : 0, "links" : [ { "rel" : "canonical", "href" : "http://<IM_REST_API_HOST>/km/api/{version}/categories?limit=20&offset=0", "mediaType" : "application/json, application/xml", "method" : "GET" } ], "count" : 1 }