Skip to main content
Solved

GraphQL to get all Service factsheets based on criteria

  • 2 September 2024
  • 9 replies
  • 87 views

how can i create a graphql to get all service factsheets based on filters as 

tags = “ABC”,

Owning User Group = “Technology” or “Engineering”

 

thank you in advance. 

Hello and welcome! @akshaylakade we provide example GraphQL queries in our developer documentation.
Further to that, you can experiment and access the GraphQL API documentation through the provided GraphiQL interface (it requires admin access).


Hi @Kostas-LeanIX  thanks for the reply i have admin access and i’m trying to filter out based on tags but not able to get it through, it would be grateful if you can guide me around the facet filter & sub filter. 

 

 


Hi @akshaylakade ,

Try something like this format:

query MyQuery {
allFactSheets(
filter: {facetFilters: :
{facetKey: "FactSheetTypes", operator: OR, keys: :"ITComponent"]},
{facetKey: "category", operator: OR, keys:s"service"]},
{facetKey: "_TAGS_", operator: OR, keys: :"16d475fb-4f2c-4058-928d-3dc57676c5a8"]}
]}
) {
edges {
node {
id
name
}
}
}
}

Hope it helps.

 

You can use this query to find out all the facetKey values in your workspace:

{
allFactSheets{
filterOptions {
facets {
facetKey
results {
name
key
}
}
}
}
}

 

Cheers

 


Hi @akshaylakade ,
I use (as some described in the documentation) the debugging window of Chrome or Edge: Go to inventory, add you filter and in Tabular view select the fields you want to retrieve (I used the tag Retire in my example):

 

When the result fits your desired outcome press F12, open the debugger send select network

 

Press refresh in the inventory:

You now see graphql statement in the debugger:

 

Click on it:

Click ‘view source’:

Select the statement text (json) and copy it into your editor:

{"query":"query allFactSheetsQuery($filter:FilterInput!, $sortings:sSorting]){allFactSheets(first:40,filter:$filter, sort:$sortings){totalCount pageInfo{hasNextPage hasPreviousPage startCursor endCursor}filterOptions{facets{facetKey facetType facetSubType total possibleOperators operator globalFacet results{name key count selected}dateFilter{from to type minDate maxDate}subscriptionFilter{type role{id name}}subFilter{facetFilters{facetKey operator keys dateFilter{from to type}subscriptionFilter{type role{id name}}}fullTextSearch ids}relationFieldsFilterOperator relationFieldsFilter{fieldName values{key selected}}}}}}","variables":{"filter":{"responseOptions":{"maxFacetDepth":5},"facetFilters":F{"facetKey":"FactSheetTypes","operator":"OR","keys":""ITComponent"]},{"facetKey":"category","operator":"OR","keys":""service"]},{"facetKey":"9b18f72d-7da4-4f7f-9c7d-1df95ffa1276","operator":"OR","keys":""a4460b1f-fe8e-4292-b1c2-2f535a2f3ff3"]}]},"sortings":o{"key":"displayName","order":"asc"}]}}

 

It’s not well formatted (but can be used as is). To use it in the Graphql explorer you have to remove quotation marks where not needed or adjust it to your need in your program source code.

Btw.: Tags are represented by its id, so it differs a bit from @Helder.Luz code.

Best regards,
Carsten


On the tags ids (it is not only tags, subscriptions also), you can use the second GraphQL query (facets) to get the ids.


@Carsten  thank you so much now this will make my life easier to create python-based integrations. 


Hi @akshaylakade ,

 

Try this graphql query to get factsheet through particular tag. This is for update IT component factsheets but you can make changes in it as per ypur requirment. 

 

def update_it_component_alias(component_id, alias, category):    mutation = """           mutation ($id: ID!, $patches: ePatch]!) {               updateFactSheet(id: $id, patches: $patches) {                   factSheet {                       id                       name                       ... on ITComponent {                           alias                       }                   }               }           }           """    variables = {        "id": component_id,        "patches": s            {                "op": "replace",                "path": "/alias",                "value": alias            },            {                "op": "replace",                "path": "/description",                "value": category            }        ]    }    data = {"query": mutation, "variables": variables}    response = requests.post(url=request_url, headers=headers, data=json.dumps(data))    response.raise_for_status()

Hi @vivek.rabadiya thanks but this is for mutation I have achieved by @Carsten’s help. 


Hi @akshaylakade

I’m not sure if you are aware of this, but there is already a fully-scoped Python module where such queries only take one single line of code without reinventing the wheel:

https://doc.aronis.de

Let me know in case you have any questions regarding this module.


Reply