Sample code for 30+ languages & platforms
Delphi DLL

Shopify Private Authentication for Private Apps

See more Shopify Examples

Shopify private authentication is for interacting with your own store through private applications. It uses HTTP "Basic" authentication with your Shopify private application key and secret key.

This example demonstrates how to send a private authenticated request using Chilkat Http, and then the same using Chilkat Rest.

Chilkat Delphi DLL Downloads

Delphi DLL
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, StringBuilder, Rest, HttpResponse, JsonObject;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
http: HCkHttp;
resp: HCkHttpResponse;
sbJson: HCkStringBuilder;
json: HCkJsonObject;
rest: HCkRest;
bTls: Boolean;
port: Integer;
bAutoReconnect: Boolean;

begin
success := False;

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

// First demonstrate sending a simple request using Shopify private authentication w/ the Chilkat Http API.
http := CkHttp_Create();

// To use HTTP Basic Authentication with any HTTP request, we simply set the Login, Password, and BasicAuth properties.
// Important: All HTTP requests using Basic authentication must be over SSL/TLS.
CkHttp_putLogin(http,'SHOPIFY_PRIVATE_API_KEY');
CkHttp_putPassword(http,'SHOPIFY_PRIVATE_API_SECRET_KEY');
CkHttp_putBasicAuth(http,True);

// Make sure to replace "chilkat" with your store name.
resp := CkHttpResponse_Create();
success := CkHttp_HttpNoBody(http,'GET','https://chilkat.myshopify.com/admin/products.json',resp);
if (success = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

// Examine the response code.
if (CkHttpResponse_getStatusCode(resp) <> 200) then
  begin
    Memo1.Lines.Add('Received error response code: ' + IntToStr(CkHttpResponse_getStatusCode(resp)));
    Memo1.Lines.Add('Response body:');
    Memo1.Lines.Add(CkHttpResponse__bodyStr(resp));
    Exit;
  end;

// Success.
Memo1.Lines.Add('Success.');

// Examine the JSON response 
sbJson := CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbJson);
json := CkJsonObject_Create();
CkJsonObject_LoadSb(json,sbJson);
CkJsonObject_putEmitCompact(json,False);
Memo1.Lines.Add(CkJsonObject__emit(json));

// -------------------------------------------------
// Now let's do the same using the Chilkat Rest API.
rest := CkRest_Create();

// Provide the private app credentials:
CkRest_SetAuthBasic(rest,'SHOPIFY_PRIVATE_API_KEY','SHOPIFY_PRIVATE_API_SECRET_KEY');

// Connect to the shopify server.
bTls := True;
port := 443;
bAutoReconnect := True;
// Make sure to replace "chilkat" with your store name.
success := CkRest_Connect(rest,'chilkat.myshopify.com',port,bTls,bAutoReconnect);
if (success = False) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

CkStringBuilder_Clear(sbJson);
success := CkRest_FullRequestNoBodySb(rest,'GET','/admin/products.json',sbJson);
if (CkRest_getLastMethodSuccess(rest) = False) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

if (CkRest_getResponseStatusCode(rest) <> 200) then
  begin
    Memo1.Lines.Add('Received error response code: ' + IntToStr(CkRest_getResponseStatusCode(rest)));
    Memo1.Lines.Add('Response body:');
    Memo1.Lines.Add(CkStringBuilder__getAsString(sbJson));
    Exit;
  end;

// Success...
CkJsonObject_LoadSb(json,sbJson);
Memo1.Lines.Add(CkJsonObject__emit(json));

CkHttp_Dispose(http);
CkHttpResponse_Dispose(resp);
CkStringBuilder_Dispose(sbJson);
CkJsonObject_Dispose(json);
CkRest_Dispose(rest);

end;