# How to use a custom query filter in JAVA SDK

**URL:** <https://community.cumulocity.com/t/how-to-use-a-custom-query-filter-in-java-sdk/1354>\
**Category:** Forum\
**Tags:** cumulocity\
**Created:** [June 19, 2023, 8:36am UTC](https://community.cumulocity.com/t/how-to-use-a-custom-query-filter-in-java-sdk/1354 "2023-06-19T08:36:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam123](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/sam123/32/14460_2.png) [@Sam123](https://community.cumulocity.com/u/Sam123)\
**Post date:** [June 19, 2023, 8:36am UTC](https://community.cumulocity.com/t/how-to-use-a-custom-query-filter-in-java-sdk/1354/1 "2023-06-19T08:36:37Z")

</div>

#### _ **Product/components** used and **version/fix** level:_

Cumulocity Production

#### _Detailed explanation of the problem:_

Hi, I have a class called CustomQueryParam which returns a instance of custom query filter. I have tried this with others and it works perfectly fine, so i was wondering if I can similarly use a custom query filter in this way.

```auto
package com.solenis.report.SolenisUserDeviceDailyReport.utils;

import com.cumulocity.sdk.client.Param;
import com.cumulocity.sdk.client.QueryParam;

public class CustomQueryParam extends QueryParam {
    private static final Param QUERY_PARAM = new Param() {
        @Override
        public String getName() {
            return "creationTime";
        }
    };

    private static final CustomQueryParam INSTANCE = new CustomQueryParam();

    public static CustomQueryParam getInstance() {
        return INSTANCE;
    }
    private CustomQueryParam() {
        super(QUERY_PARAM, "query=creationTime.date ge "+CustomUtil.getDateWithTime());
    }
}

```

Now I am calling this in my inventory filter call like this:

```auto
InventoryFilter deviceFilter = new InventoryFilter().byFragmentType("c8y_IsDevice");
Iterable<ManagedObjectRepresentation> mObjColl = inventoryApi.getManagedObjectsByFilter(deviceFilter).get(2000, CustomQueryParam.getInstance()).allPages();

```

But i am getting this exception:

`Caused by: com.cumulocity.sdk.client.SDKException: Illegal characters used in URL.`

Can you please tell me how can I achieve this?

Best Regards,  
Samanyu

---

<div class="post-metadata">

**Author:** ![Holger\_von\_Thomsen](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/holger_von_thomsen/32/28221_2.png) [@Holger\_von\_Thomsen](https://community.cumulocity.com/u/Holger_von_Thomsen)\
**Post date:** [June 19, 2023, 9:15am UTC](https://community.cumulocity.com/t/how-to-use-a-custom-query-filter-in-java-sdk/1354/2 "2023-06-19T09:15:02Z")

</div>

Hi Samanyu,

even I have never worked with C8Y, I will try to sort it out a little bit:

Most likely the issue is with the line “super(QUERY\_PARAM, …);”, the second parameter might be causing this issue here.  
Can you please check if the syntax of the “query=…” part is correct?  
When this gets appended to URL after a question mark, it is not allowed to contain any blanks as this will break the URL.

Regards,  
Holger

---

<div class="post-metadata">

**Author:** ![Harald\_Meyer](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/harald_meyer/32/1959_2.png) [@Harald\_Meyer](https://community.cumulocity.com/u/Harald_Meyer)\
**Post date:** [June 19, 2023, 11:30am UTC](https://community.cumulocity.com/t/how-to-use-a-custom-query-filter-in-java-sdk/1354/3 "2023-06-19T11:30:49Z")

</div>

Can you do a quick check and URL encode the custom query part using  
[https://docs.oracle.com/javase/8/docs/api/java/net/URLEncoder.html#encode-java.lang.String-java.lang.String-](https://docs.oracle.com/javase/8/docs/api/java/net/URLEncoder.html#encode-java.lang.String-java.lang.String-)

---

<div class="post-metadata">

**Author:** ![Sam123](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/sam123/32/14460_2.png) [@Sam123](https://community.cumulocity.com/u/Sam123)\
**Post date:** [June 19, 2023, 12:22pm UTC](https://community.cumulocity.com/t/how-to-use-a-custom-query-filter-in-java-sdk/1354/4 "2023-06-19T12:22:54Z")

</div>

Hi Holger,

The syntax is correct, I first tried it in postman then only I tried with SDK. Is there any way I can see the url anywhere. I can do getSelf() but it is failing at .get(2000,).

Thanks & Regards,  
Samanyu

---

<div class="post-metadata">

**Author:** ![Korbinian\_Butz](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/korbinian_butz/32/10473_2.png) [@Korbinian\_Butz](https://community.cumulocity.com/u/Korbinian_Butz)\
**Post date:** [June 19, 2023, 12:52pm UTC](https://community.cumulocity.com/t/how-to-use-a-custom-query-filter-in-java-sdk/1354/5 "2023-06-19T12:52:33Z")

</div>

With adding `logging.level.root=DEBUG` to your application.properties you’ll get a verbose output - including the URLs sent to the platform. Or you can set a breakpoint and debug the URL in your IDE.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/system/32/31990_2.png) [@system](https://community.cumulocity.com/u/system)\
**Post date:** [December 16, 2023, 1:22pm UTC](https://community.cumulocity.com/t/how-to-use-a-custom-query-filter-in-java-sdk/1354/8 "2023-12-16T13:22:04Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
