Запросы к GraphQL с помощью PowerShell - PullRequest
1 голос
/ 20 апреля 2020

Итак, я пытался запросить GraphQL из PowerShell. В cmd все выглядит идеально, но я не могу заставить его работать в PS, видите, у меня пока есть этот код:

$oAuth2TokenUrl = "https://api.cloudflare.com/client/v4/zones/0000/analytics/dashboard"
$accessKey = '1111' 

$Cloudflare_Oauth_Header = @{
    "Authorization" = "Bearer $accessKey";
}

$query = @'
{ "query": "query { viewer {
zones(filter: {zoneTag: 0000}) {
  httpRequests1mGroups(orderBy: [datetimeMinute_ASC], limit: 1000, filter: {datetime_geq: "2019-09-08T20:00:00Z", datetime_lt: "2019-09-08T20:02:00Z"}) {
    dimensions {datetimeMinute}
    sum {
      browserMap {
        pageViews
        uaBrowserFamily
      }
      bytes
      cachedBytes
      cachedRequests
      contentTypeMap {
        bytes
        requests
        edgeResponseContentTypeName
      }
      clientSSLMap {
        requests
        clientSSLProtocol
      }
      countryMap {
        bytes
        requests
        threats
        clientCountryName
      }
      encryptedBytes
      encryptedRequests
      ipClassMap {
        requests
        ipType
      }
      pageViews
      requests
      responseStatusMap {
        requests
        edgeResponseStatus
      }
      threats
      threatPathingMap {
        requests
        threatPathingName
      }
    }
    uniq {
      uniques
    }
  }
}
  } }" }
'@


$Cloudflare_zone = Invoke-RestMethod -Method Post -Headers $Cloudflare_Oauth_Header -ContentType "application/json; charset=utf-8" -Uri $oAuth2TokenUrl -Body $query 

И я получаю ошибку Invoke-RestMethod : The remote server returned an error: (501) Not Implemented. Но если я закручиваю в cmd, то возвращает то, что ожидается, и ошибка не отображается.

Пожалуйста, дайте мне знать, если вам нужно больше деталей.

...