Err code 500 with API using google app script lang

script code in google app script lang with err in the last line (fetch func):
const API_KEY = “BQ…Lv”

function MyTest(){

let query = query{ bitcoin{ blocks{ count } } } ;

let opts = {
method: “POST”,
headers: {“Content-Type”: “application/json”, “X-API-KEY”: API_KEY},
body: JSON.stringify(query)
};

let response = UrlFetchApp.fetch(‘https://graphql.bitquery.io’, opts)

}

err mes:
Exception: Request failed for https://graphql.bitquery.io returned code 500. Truncated server response: {“errors”:[{“message”:"undefined method size' for nil:NilClass","backtrace":["/app/lib/util/requests_complexity.rb:10:in pre_calculate_complexity… (use muteHttpExceptions option to examine full response)

help pls thanks

@srob2 thanks for bringing it to our notice. This seems to be an error on our side. Will get back to you soon with the fix.

@srob2 Here’s how we should use it:

let opts = {
    method: "post",
    muteHttpExceptions:true,
    headers: {
      "Content-Type": "application/json",
      "X-API-KEY": API_KEY,
    },
    payload: JSON.stringify({
      "query":query  
      ,"variables" : "{}"
  })
  };

set the query in the payload parameter and it works

it works. thx

here is err in help info i used.
fix it pls

1 Like