If I "declare" a request in one swoop like this, it works:
payload := strings.NewReader(`query {
node(id: "gid://shopify/BulkOperation/2000000011111") {
... on BulkOperation {
url
partialDataUrl
}
}
}`)
However, the gid
field is changing, so I cannot hard-code it like above. So I did the following (queryId
is a variable):
s := `query {
node(id: "` queryId `") {
... on BulkOperation {
url
partialDataUrl
}
}
}`
client := &http.Client{}
req, err := http.NewRequest(method, url, strings.NewReader(s))
And the result is not correct, compared to when I hard code it. Seems like the gid
was not added in properly, resulting in empty reponse.
The original Python code is:
data_query = '''
query {
node(id: "%s") {
... on BulkOperation {
url
partialDataUrl
}
}
}
''' % bulkopr_id
CodePudding user response:
Discover the problem: Shopify needs a little time to prepare the query result. In my code I call the API too quickly after it was generated, therefore the result is empty. Simply put time.Sleep(3*time.Second)
and the response will not be empty.