Unable to add filter in the api to get specific response .

Sachin Gavhane
Giga Guru

Hi Everyone, 

Below is my query 

Api : https://api.mgmt.cloud.xyz.com/form-service/api/custom/resource-actions?page=0&size=20&%24orderby=na...

Method: Get

Response received is the JSON response for page 0 [ as we have mentioned page in api]

Response is as follows: 
________________________________________________________________________________________
_______________________________________________________________________________________

var response ={
    "content": [
        {
            "id": "Deployment.custom.12test",
            "name": "12Test",
       }
       
       {
            "id": "Deployment.custom.uniom",
            "name": "uniom",
       }
       
      {
            "id": "Deployment.custom.ging",
            "name": "ging",
       }
           
    ],
    "pageable":
       {
        "pageNumber": 0,
        "pageSize": 20,
        "paged": true,
        "unpaged": false
    },
    "totalElements": 184,
    "totalPages": 10,
    "numberOfElements": 20,
    "first": true,
    "empty": false
};
 
_____________________________________________________________________________________________________
________________________________Response  End______________________________________________________ 

I have received response for page0 as mentioned in api , and here if you see in the page 0 response it is mentioned that there are total 10 pages and 184 elements.

My requirement is : I dont need all elements here , I need specific element.
I need response for the specific element , lets say I need response only for the "id": "Deployment.custom.ging",

can i apply id specific filter in the api itself? 
I tried but unable to add id specific filter in the api itself.

After getting the response , i can apply filter to extract specific id, but i dont know  on which page i will get my required id so need to traverse with the response of each page.

hence i was looking for a optimal solution where in i can apply filter in the api itself to get the specific response as per the required id.

can someone pls help me in this.
Also along with the solu if someone can provide sample script to achieve this is highly appreciable.

let me know if anyother information needed from my end for this query

Thanks


 
1 REPLY 1

Edward Rosario
Mega Sage
Mega Sage

Hi Sachin,
I'm not too experienced in this area, but I was trying a few things. try this,

fetch('https://api.mgmt.cloud.xyz.com/form-service/api/custom/resource-actions?page=0&size=20&%24orderby=na...')
.then(response => response.json())
.then(data => {
// Filter the response to get only the element with id "Deployment.custom.ging"
const specificElement = data.find(element => element.id === "Deployment.custom.ging");

console.log(specificElement);
})
.catch(error => console.error('Error:', error));