Skip to content

Instantly share code, notes, and snippets.

@chriswahl chriswahl/curl_example.txt
Last active Feb 14, 2020

Embed
What would you like to do?
An Introduction to GraphQL Queries and Mutations - Wahl Network
curl --location --request POST 'https://fun.example.com/api/graphql' \
--header 'authorization: Bearer token' \
--header 'content-type: application/json' \
--header 'accept: */*' \
--data-raw '{"operationName":"EC2InstancesListQuery","variables":{"first":20,"sortBy":"EC2_INSTANCE_ID","sortOrder":"ASC","filters":[{"field":"EC2_INSTANCE_NAME_OR_INSTANCE_ID","texts":["i-0764330c7bb59d8ed"]},{"field":"IS_ARCHIVED","texts":["0"]}]},"query":"query EC2InstancesListQuery($first: Int, $after: String, $sortBy: HierarchySortByField, $sortOrder: HierarchySortOrder, $filters: [Filter!]) {\n ec2InstancesList: awsNativeEc2InstanceConnection(first: $first, after: $after, sortBy: $sortBy, sortOrder: $sortOrder, filter: $filters) {\n edges {\n node {\n id\n instanceId\n instanceName\n vpcName\n region\n vpcId\n isRelic\n instanceType\n isExocomputeConfigured\n isIndexingEnabled\n isMarketplace\n effectiveSlaDomain {\n name\n ... on ClusterSlaDomain {\n fid\n cluster {\n id\n name\n __typename\n }\n __typename\n }\n ... on GlobalSla {\n id\n __typename\n }\n __typename\n }\n awsNativeAccount {\n id\n name\n status\n __typename\n }\n slaAssignment\n authorizedOperations {\n id\n operations\n __typename\n }\n effectiveSlaSourceObject {\n fid\n name\n objectType\n __typename\n }\n __typename\n }\n __typename\n }\n pageInfo {\n endCursor\n hasNextPage\n hasPreviousPage\n __typename\n }\n __typename\n }\n}\n"}'
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://fun.example.com/api/graphql"
method := "POST"
payload := strings.NewReader("{\"operationName\":\"EC2InstancesListQuery\",\"variables\":{\"first\":20,\"sortBy\":\"EC2_INSTANCE_ID\",\"sortOrder\":\"ASC\",\"filters\":[{\"field\":\"EC2_INSTANCE_NAME_OR_INSTANCE_ID\",\"texts\":[\"i-0764330c7bb59d8ed\"]},{\"field\":\"IS_ARCHIVED\",\"texts\":[\"0\"]}]},\"query\":\"query EC2InstancesListQuery($first: Int, $after: String, $sortBy: HierarchySortByField, $sortOrder: HierarchySortOrder, $filters: [Filter!]) {\\n ec2InstancesList: awsNativeEc2InstanceConnection(first: $first, after: $after, sortBy: $sortBy, sortOrder: $sortOrder, filter: $filters) {\\n edges {\\n node {\\n id\\n instanceId\\n instanceName\\n vpcName\\n region\\n vpcId\\n isRelic\\n instanceType\\n isExocomputeConfigured\\n isIndexingEnabled\\n isMarketplace\\n effectiveSlaDomain {\\n name\\n ... on ClusterSlaDomain {\\n fid\\n cluster {\\n id\\n name\\n __typename\\n }\\n __typename\\n }\\n ... on GlobalSla {\\n id\\n __typename\\n }\\n __typename\\n }\\n awsNativeAccount {\\n id\\n name\\n status\\n __typename\\n }\\n slaAssignment\\n authorizedOperations {\\n id\\n operations\\n __typename\\n }\\n effectiveSlaSourceObject {\\n fid\\n name\\n objectType\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n pageInfo {\\n endCursor\\n hasNextPage\\n hasPreviousPage\\n __typename\\n }\\n __typename\\n }\\n}\\n\"}")
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
}
req.Header.Add("authorization", "Bearer token")
req.Header.Add("content-type", "application/json")
req.Header.Add("accept", "*/*")
res, err := client.Do(req)
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("authorization", "Bearer token")
$headers.Add("content-type", "application/json")
$headers.Add("accept", "*/*")
$body = "{`"operationName`":`"EC2InstancesListQuery`",`"variables`":{`"first`":20,`"sortBy`":`"EC2_INSTANCE_ID`",`"sortOrder`":`"ASC`",`"filters`":[{`"field`":`"EC2_INSTANCE_NAME_OR_INSTANCE_ID`",`"texts`":[`"i-0764330c7bb59d8ed`"]},{`"field`":`"IS_ARCHIVED`",`"texts`":[`"0`"]}]},`"query`":`"query EC2InstancesListQuery($first: Int, $after: String, $sortBy: HierarchySortByField, $sortOrder: HierarchySortOrder, $filters: [Filter!]) {`\n ec2InstancesList: awsNativeEc2InstanceConnection(first: $first, after: $after, sortBy: $sortBy, sortOrder: $sortOrder, filter: $filters) {`\n edges {`\n node {`\n id`\n instanceId`\n instanceName`\n vpcName`\n region`\n vpcId`\n isRelic`\n instanceType`\n isExocomputeConfigured`\n isIndexingEnabled`\n isMarketplace`\n effectiveSlaDomain {`\n name`\n ... on ClusterSlaDomain {`\n fid`\n cluster {`\n id`\n name`\n __typename`\n }`\n __typename`\n }`\n ... on GlobalSla {`\n id`\n __typename`\n }`\n __typename`\n }`\n awsNativeAccount {`\n id`\n name`\n status`\n __typename`\n }`\n slaAssignment`\n authorizedOperations {`\n id`\n operations`\n __typename`\n }`\n effectiveSlaSourceObject {`\n fid`\n name`\n objectType`\n __typename`\n }`\n __typename`\n }`\n __typename`\n }`\n pageInfo {`\n endCursor`\n hasNextPage`\n hasPreviousPage`\n __typename`\n }`\n __typename`\n }`\n}`\n`"}"
$response = Invoke-RestMethod 'https://fun.example.com/api/graphql' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.