Delphi DLL
Delphi DLL
Update an Inventory Listing using OAuth1 Authentication
See more Etsy Examples
Updates an inventory listing. This example uses OAuth1 authentication instead of providing an api_key=MY_ETSY_KEYSTRING query parameter.Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, OAuth1, Rest, JsonObject;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
rest: HCkRest;
json: HCkJsonObject;
oauth1: HCkOAuth1;
autoReconnect: Boolean;
tls: Boolean;
jsonText: PWideChar;
jsonResponseText: PWideChar;
jsonResponse: HCkJsonObject;
begin
success := False;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
rest := CkRest_Create();
// See this example for getting an OAuth1 token for Etsy
json := CkJsonObject_Create();
success := CkJsonObject_LoadFile(json,'qa_data/tokens/etsy.json');
if (success = False) then
begin
Memo1.Lines.Add('Failed to load previously fetched Etsy OAuth1 access token.');
Exit;
end;
oauth1 := CkOAuth1_Create();
CkOAuth1_putConsumerKey(oauth1,'app_keystring');
CkOAuth1_putConsumerSecret(oauth1,'app_shared_secret');
CkOAuth1_putToken(oauth1,CkJsonObject__stringOf(json,'oauth_token'));
CkOAuth1_putTokenSecret(oauth1,CkJsonObject__stringOf(json,'oauth_token_secret'));
CkOAuth1_putSignatureMethod(oauth1,'HMAC-SHA1');
CkOAuth1_GenNonce(oauth1,16);
autoReconnect := True;
tls := True;
success := CkRest_Connect(rest,'openapi.etsy.com',443,tls,autoReconnect);
if (success = False) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
// Tell the REST object to use the OAuth1 object.
success := CkRest_SetAuthOAuth1(rest,oauth1,True);
jsonText := '[{"product_id":1999949999,"property_values":[],"offerings":[{"offering_id":9999905883,"price":"36.23","quantity":1}]}]';
CkRest_AddQueryParam(rest,'products',jsonText);
CkRest_AddHeader(rest,'Content-Type','application/x-www-form-urlencoded');
jsonResponseText := CkRest__fullRequestFormUrlEncoded(rest,'PUT','/v2/listings/228827035/inventory');
if (CkRest_getLastMethodSuccess(rest) = False) then
begin
Memo1.Lines.Add(CkRest__lastErrorText(rest));
Exit;
end;
jsonResponse := CkJsonObject_Create();
CkJsonObject_Load(jsonResponse,jsonResponseText);
CkJsonObject_putEmitCompact(jsonResponse,False);
Memo1.Lines.Add(CkJsonObject__emit(jsonResponse));
Memo1.Lines.Add('Response status code: ' + IntToStr(CkRest_getResponseStatusCode(rest)));
CkRest_Dispose(rest);
CkJsonObject_Dispose(json);
CkOAuth1_Dispose(oauth1);
CkJsonObject_Dispose(jsonResponse);
end;