Search code examples
wso2wso2-data-services-serverwso2-micro-integratordataservice

Pass query parameters to wso2 dss service


I want to get categories from a table by passing limit and offset.

I added this query into the dss like below.

<resource method="GET" path="permission-categories?offset={offset}&limit={limit}">
    <call-query href="getPermissionCategories">
        <with-param name="offset" query-param="offset" />
        <with-param name="limit" query-param="limit" />
    </call-query>
</resource>


<query id="getPermissionCategories" useConfig="usage-profile-datasource">
    <sql>SELECT * FROM permission_category limit :limit offset :offset</sql>
     <param name="limit" optional="false" sqlType="INTEGER"/>
     <param name="offset" optional="false" sqlType="INTEGER"/>
    <result outputType="json">
        {"outpust-result":{
        "Resources":[{
        "id": "$id",
        "permissionCategory":"$permission_category"
        }]
        }
        }
    </result>
</query>

I invoked this dss service from WSO2 Micro Integrator.

<call>
    <endpoint>
        <http method="GET" uri-template="https://{uri.var.integratorHost}:{uri.var.integratorServicePort}/services/test-dataservice-v2/permission-categories?offset={query.param.offset}&amp;limit={query.param.limit}"/>
      </endpoint>
 </call>

But When I invoked this dss service I'm getting this error.

INCOMPATIBLE_PARAMETERS_ERROR


Solution

  • Your resource path seems incorrect path="permission-categories?offset={offset}&limit={limit}" as you don't have to specify the query params in the path. Check the following example.

    <resource method="GET" path="student2">
      <call-query href="ReadStudents2">
        <with-param name="limit" query-param="limit" />
        <with-param name="offset" query-param="offset" />
      </call-query>
    </resource>
    
    <query id="ReadStudents2" useConfig="default">
      <sql>SELECT id, name FROM students LIMIT :limit OFFSET :offset</sql>
      <param name="limit" paramType="SCALAR" sqlType="INTEGER" />
      <param name="offset" paramType="SCALAR" sqlType="INTEGER" />
      <result outputType="xml" useColumnNumbers="true" element="GroupElement" rowName="id">
        <element name="Id" column="1" xsdType="string" requiredRoles="" />
        <element name="Name" column="2" xsdType="string" requiredRoles="" />
      </result>
    </query>
    

    Invoke like.

    curl --location --request GET 'http://localhost:8290/services/RESTDataService/student2?limit=1&offset=2' \
    --header 'Accept: application/json'