0

I am trying to use the Shopify GraphQL Admin API from Delphi. Came up with the following code:

procedure TestShopify;
var
  Client: TRESTClient;
  Request: TRESTRequest;
  Response: TRESTResponse;
  QueryJSON: string;
begin
  Client := TRESTClient.Create('https://<my shop>.myshopify.com/admin/api/2025-10/graphql.json');

  Request := TRESTRequest.Create(nil);

  Response := TRESTResponse.Create(nil);
  try
    Request.Client := Client;
    Request.Response := Response;
    Request.Method := rmPOST;

    Request.Params.Clear;
    Request.AddParameter('X-Shopify-Access-Token', '<app token from shopify>', pkHTTPHEADER);
    Request.AddParameter('Accept', 'application/json', pkHTTPHEADER);
    Request.AddParameter('Content-Type', 'application/json', pkHTTPHEADER);

    QueryJSON := '{"query": "{ shop { name myshopifyDomain } }"}';
    Request.Body.ClearBody;
    Request.AddBody(QueryJSON, ctNone);

    Request.Execute;
  finally
    Response.Free;
    Request.Free;
    Client.Free;
  end;
end;

Did try "different flavours" of the above code and the best I got was this error:

Project TestShopify.exe raised exception class EHTTPProtocolException with message 'HTTP/1.1 406 Not Acceptable'.

Note: I did try the above request with Postman from my computer and I get back the expected result.

7
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Nov 13 at 9:30
  • {"query": "{ shop { name myshopifyDomain } }"} is invalid JSON all along, it must be at least name: "myDomain". Sure you posted exactly the same with Postman? Commented Nov 13 at 12:12
  • And instead of ctNONE you might want to pass ctAPPLICATION_JSON. Commented Nov 13 at 12:19
  • Based on exception raised the handshake is refused by Shopify since you are connection using HTTP protocol. If you read TRESTClient documentation you can find next notice:: Important: To access REST APIs using the HTTPS protocol, you should download OpenSSL libraries provided by the Indy project. So you will have to use Indy based rest client to work over HTTPS protocol. Commented Nov 13 at 13:00
  • 1
    @AmigoJack the query shown is valid JSON. It is just a name/value pair where the value is a string. The syntax of that string is not JSON. shopify.dev/docs/api/usage/search-syntax Commented Nov 13 at 17:09

2 Answers 2

1

I've been using WinHttp do perform HTTP calls to Shopify:

procedure TForm1.Button1Click(Sender: TObject);
var
  r:IWinHttpRequest;
begin
  r:=CoWinHttpRequest.Create;
  r.Open('POST','https://'+MyShopName+'.myshopify.com/admin/api/2025-10/graphql.json',false);
  r.SetRequestHeader('X-Shopify-Access-Token',MyShopAccessToken);
  r.SetRequestHeader('Accept','application/json');
  r.SetRequestHeader('Content-Type','application/json');
  r.Send('{"query":"orders(first:100){edges{node{id name}}}"}');

  Button1.Caption:=IntToStr(r.Status);//check 200
  Memo1.Text:=r.ResponseText;
end;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I will give it a try. Was hoping to use the TRESTClient like I did it with so many other APIs
-1

You should be setting the content type when setting the body. At the moment you are setting it to ctNone.

Request.AddBody(QueryJSON, ctAPPLICATION_JSON);

EDIT: I have not tested this but based on some posts i read on the shopify forums 406 is thrown when shopify doesnt understand the content you sent it. This made me check how you are sending the body which made me see that you are not defining the content type. TRestRequest will send the content type you defined with the body. You are setting this to ctNone.

2 Comments

I commented that already.
This change doesn't work. The reason of sending ctNone is the following: - ctNone tells Delphi not to append a charset to the Content-Type. - The JSON body is provided as a raw string, which Shopify prefers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.