Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Passing the Graphql schema as JSON request body in REST

Bimal
Tera Contributor

Hi ,

I want to pass the Graphql schema as the JSON request body in REST Message.

This is my Grapql Query 

query listComponents($inputListComponentsInput) {
  serviceslistComponents(input$input) {
    pageInfo {
      totalCount
      pageSize
      totalPages
      currentPage
      previousPage
      nextPage
    }
    items {
      service_long_idcomponentId
      service_namecomponentName
      service_idcomponentCode
      service_descdescription
      division
    }
  }
}
Variables :
{
    "input": {
        "filter": {
            "componentIds": {
                "in": []
            },
            "active": {
                "eq": true
            },
            "lifeCycleStatus": {
                "ne": "Retired"
            },
            "componentName": {
                "contains": ""
            }
        },
        "pagination": {
            "size": 3000,
            "page": 1
        }
    }
}
1 REPLY 1

Martin105
Tera Contributor

You just need to wrap it:

like this:

{ "query": `{ places (orderBy: title_ASC,first: 100){ id title perex images { height src width } } }`, }

 

There a single property "query" that will contain your graphql query. You can do it as multiline string or I found this nice service: https://datafetcher.com/graphql-json-body-converter

 

{
"query": "query listComponents($input: ListComponentsInput) { services: listComponents(input: $input) { pageInfo { totalCount pageSize totalPages currentPage previousPage nextPage } items { service_long_id: componentId service_name: componentName service_id: componentCode service_desc: description division } }}Variables :{ \"input\": { \"filter\": { \"componentIds\": { \"in\": [] }, \"active\": { \"eq\": true }, \"lifeCycleStatus\": { \"ne\": \"Retired\" }, \"componentName\": { \"contains\": \"\" } }, \"pagination\": { \"size\": 3000, \"page\": 1 } }}"
}