Querying New Relic with GraphQL in Python

Viewed 181

I just started using GraphQL with New Relic and I'm having troubles trying to pass variables to the GraphQL query. I need to retrieve the NR Synthetics monitors GUID's based on their names, for which I thought of searching for the entity and then get the guid from the query response. This is my piece of code containing the query:

    query = '''
    query($query: String!) {
      actor {
        entitySearch(query: $query) {
          results {
            entities {
              guid
            }
          }
        }
      }
      variables { query: "name LIKE \u0027MYMONITORNAME\u0027" }
    }'''

Then I call the NR API:

    my_response = requests.get(
    url=my_url,
    headers=header,
    json={"query": query}
)

And I get this back:

{'errors': [{'locations': [{'column': 30, 'line': 12}], 'message': 'syntax error before: "\\"name LIKE \'MYMONITORNAME\'\\""'}]}

I've tried many escape sequences, double quotes/single quotes/no quotes combinations but can't seem to nail the right format. Any guidance would be much appreciated.

Thanks in advance, Sebastian

0 Answers
Related