AdminApi/GraphQL from Excel

superette
New Member
1 0 0

Hi

I'm trying to make a request from Excel to the AdminApi.

This works fine when I use REST. 

Public Sub XmlHttpTest()
            
            Dim XmlHttp As New MSXML2.XMLHTTP60 'Tools > Reference : Microsoft XML, v 6.0
            Dim MyUrl As String
            Dim ApiKeyOrUser As String
            Dim Password As String
            
            MyUrl = "https://{myshop}.myshopify.com/admin/api/2021-04/products/{productId}/variants/{productVariantId}.json"
            XmlHttp.Open "GET", MyUrl, False
            
            ApiKeyOrUser = "key"
            Password = "password"
            XmlHttp.setRequestHeader "Authorization", "Basic " + EncodeBase64(ApiKeyOrUser + ":" + Password) 'b64-fn not included
            XmlHttp.send
            
            MsgBox (XmlHttp.responseText)
End Sub

 

But now I like to use GraphQL  but this code gives me a "Bad Request" response.

 

Public Sub XmlHttpGraphQL()

            Dim XmlHttp As New MSXML2.XMLHTTP60 'Tools > Reference : Microsoft XML, v 6.0
            Dim Url As String
            Dim ApiKeyOrUser As String
            Dim Password As String
            Dim JSON As String

            Url = " https://{myshop}.myshopify.com/admin/api/2021-04/graphql.json"
            XmlHttp.Open "POST", Url, False
            
            ApiKeyOrUser = "key"
            Password = "password"
            XmlHttp.setRequestHeader "Authorization", "Basic " + EncodeBase64(ApiKeyOrUser + ":" + Password) 'b64-fn not included
            XmlHttp.setRequestHeader "Content-type", "application/json"
            JSON = "query simple{shop{name}}"
            XmlHttp.send (JSON)

            MsgBox (XmlHttp.responseText)
End Sub

 

Anyone any idea? Thanks in advance.

0 Likes