title: Is there a way to fetch data from a graphql API in apps script?
body: <p>I'm trying to fetch data from a graphql API through apps script.</p>
  
  <p>There is a question using POST to fetch graphql data (<a href="https://stackoverflow.com/questions/47741501/providing-query-string-to-fetch-from-a-graphql-api">Providing query string to fetch from a GraphQL API</a>), but the url I need to fetch only allows GET.</p>
  
  <p>The code I wrote is below:</p>
  
  <pre><code>function main() {
    var ss = SpreadsheetApp.getActiveSheet();
    url = "https://coletum.com/api/graphql?query={answer(formId:7787){answer{nomeDaEmpresa107176,cnpj107177,inscricaoEstadual107178,telefone107179},metaData{userId,userName,source,friendlyId,createdAt,createdAtDevice,createdAtCoordinates,updatedAt,updatedAtCoordinates}}}&amp;token=k4foipsju5ckosk4w8o0w084cc8oos0"
  
    var response = UrlFetchApp.fetch(url,{method: 'GET', headers: { 'Content-Type': 'application/json'} })
  
    var lists = JSON.parse((response.getContentText()));
  
    Logger.log(lists);
  }
  </code></pre>
  
  <p>If I paste the url into a browser all works fine:</p>
  
  <pre><code>{
    data: {
      answer: [
        {
          answer: {
            nomeDaEmpresa107176: "LAVORO",
            cnpj107177: "26.693.198/0001-20",
            inscricaoEstadual107178: 12341234,
            telefone107179: "(66) 1234-1234"
          },
          metaData: {
            userId: 9938,
            userName: "Mendes",
            source: "web_private",
            friendlyId: "1.202279",
            createdAt: "2019-05-10T00:14:54+00:00",
            createdAtDevice: "2019-05-10T00:14:54+00:00",
            createdAtCoordinates: {
              longitude: -52.20797,
              latitude: -12.58536
            },
            updatedAt: null,
            updatedAtCoordinates: {
              longitude: null,
              latitude: null
            }
          }
        },
        {
          answer: {
            nomeDaEmpresa107176: "RURAL",
            cnpj107177: "26.693.198/0001-20",
            inscricaoEstadual107178: 1234,
            telefone107179: "(66) 1234-1234"
          },
          metaData: {
            userId: 9938,
            userName: "Mendes",
            source: "web_private",
            friendlyId: "1.202280",
            createdAt: "2019-05-10T00:15:15+00:00",
            createdAtDevice: "2019-05-10T00:15:15+00:00",
            createdAtCoordinates: {
              longitude: -52.20797,
              latitude: -12.58536
            },
            updatedAt: null,
            updatedAtCoordinates: {
              longitude: null,
              latitude: null
            }
          }
        },
        {
          answer: {
            nomeDaEmpresa107176: "PRIMAVERA MÁQUINAS",
            cnpj107177: "26.693.198/0001-20",
            inscricaoEstadual107178: 12341234,
            telefone107179: "(66) 1234-1234"
          },
          metaData: {
            userId: 9938,
            userName: "Mendes",
            source: "web_private",
            friendlyId: "1.202281",
            createdAt: "2019-05-10T00:15:51+00:00",
            createdAtDevice: "2019-05-10T00:15:51+00:00",
            createdAtCoordinates: {
              longitude: -52.20797,
              latitude: -12.58536
            },
            updatedAt: null,
            updatedAtCoordinates: {
              longitude: null,
              latitude: null
            }
          }
        },
        {
          answer: {
            nomeDaEmpresa107176: "SINAGRO",
            cnpj107177: "26.693.198/0001-20",
            inscricaoEstadual107178: 1234,
            telefone107179: "(66) 98412-1030"
          },
          metaData: {
            userId: 9938,
            userName: "Mendes",
            source: "web_private",
            friendlyId: "1.202633",
            createdAt: "2019-05-10T20:54:02+00:00",
            createdAtDevice: "2019-05-10T20:54:02+00:00",
            createdAtCoordinates: {
              longitude: -52.20629,
              latitude: -12.59418
            },
            updatedAt: null,
            updatedAtCoordinates: {
              longitude: null,
              latitude: null
            }
          }
        }
      ]
    }
  }
  </code></pre>
  
  <p>But using Url Fetch in apps script I got the error:</p>
  
  <pre><code>"Invalid Argument: https://coletum.com/api/graphql?query={answer(formId:7787){answer{nomeDaEmpresa107176,cnpj107177,inscricaoEstadual107178,telefone107179},metaData{userId,userName,source,friendlyId,createdAt,createdAtDevice,createdAtCoordinates,updatedAt,updatedAtCoordinates}}}&amp;token=k4foipsju5ckosk4w8o0w084cc8oos0 (line 5, file "Código")"
  </code></pre>
  
  <p>What do I have to do for my code to work?</p>