Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Delphi DLL Web API Examples

Primary Categories

AWS Translate
Activix CRM
Adyen
Amazon MWS
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Bluzone
CardConnect
ClickBank
Clickatell
Cloudfare
DocuSign
ETrade
Etsy
Facebook
GeoOp
GetHarvest
Jira
MYOB

Magento
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Okta OAuth/OIDC
OneLogin OIDC
PayPal
Peoplevox
Populi
QuickBooks
SOAP finkok.com
Shippo
Shopify
Stripe
SugarCRM
Trello
Twitter
VoiceBase
Vonage
Walmart
Walmart v3
Xero
eBay
effectconnect

 

 

 

(Delphi DLL) QuickBooks - Create an Account

Demonstrates how to send an JSON request to create a QuickBooks account.

Chilkat for Delphi Downloads

Chilkat non-ActiveX DLL for Delphi

Chilkat ActiveX DLL for Delphi

* The examples here use the non-ActiveX DLL.

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

...

procedure TForm1.Button1Click(Sender: TObject);
var
jsonToken: HCkJsonObject;
success: Boolean;
oauth1: HCkOAuth1;
rest: HCkRest;
bAutoReconnect: Boolean;
jsonRequest: HCkJsonObject;
requestBody: PWideChar;
sbPath: HCkStringBuilder;
numReplacements: Integer;
responseBody: PWideChar;
jsonResponse: HCkJsonObject;

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

// This example also assumes an OAuth1 access token was previously fetched.
// and saved in a JSON file.  See the Chilkat online examples at example-code.com
// for Quickbooks OAuth1 examples (in the Quickbooks and OAuth1 categories)
// 

// First get our previously obtained access token.
jsonToken := CkJsonObject_Create();
success := CkJsonObject_LoadFile(jsonToken,'qa_data/tokens/quickbooks.json');

oauth1 := CkOAuth1_Create();
CkOAuth1_putConsumerKey(oauth1,'QUICKBOOKS_CONSUMER_KEY');
CkOAuth1_putConsumerSecret(oauth1,'QUICKBOOKS_CONSUMER_SECRET');
CkOAuth1_putToken(oauth1,CkJsonObject__stringOf(jsonToken,'oauth_token'));
CkOAuth1_putTokenSecret(oauth1,CkJsonObject__stringOf(jsonToken,'oauth_token_secret'));

rest := CkRest_Create();

// Connect using TLS.
// A single REST object, once connected, can be used for many Quickbooks REST API calls.
// The auto-reconnect indicates that if the already-established HTTPS connection is closed,
// then it will be automatically re-established as needed.
bAutoReconnect := True;
success := CkRest_Connect(rest,'sandbox-quickbooks.api.intuit.com',443,True,bAutoReconnect);
if (success <> True) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

CkRest_SetAuthOAuth1(rest,oauth1,False);

jsonRequest := CkJsonObject_Create();
CkJsonObject_AppendString(jsonRequest,'AccountType','Credit Card');
CkJsonObject_AppendString(jsonRequest,'Name','Banana Republic');
requestBody := CkJsonObject__emit(jsonRequest);

// The company ID is the realmId
sbPath := CkStringBuilder_Create();
CkStringBuilder_Append(sbPath,'/v3/company/<companyID>/account');
numReplacements := CkStringBuilder_Replace(sbPath,'<companyID>',CkJsonObject__stringOf(jsonToken,'realmId'));

CkRest_AddHeader(rest,'Content-Type','application/json');
CkRest_AddHeader(rest,'Accept','application/json');
CkRest_putAllowHeaderFolding(rest,False);

responseBody := CkRest__fullRequestString(rest,'POST',CkStringBuilder__getAsString(sbPath),requestBody);
if (CkRest_getLastMethodSuccess(rest) <> True) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

// We should expect a 200 response if successful.
if (CkRest_getResponseStatusCode(rest) <> 200) then
  begin
    Memo1.Lines.Add('Request Header: ');
    Memo1.Lines.Add(CkRest__lastRequestHeader(rest));
    Memo1.Lines.Add('----');
    Memo1.Lines.Add('Response StatusCode = ' + IntToStr(CkRest_getResponseStatusCode(rest)));
    Memo1.Lines.Add('Response StatusLine: ' + CkRest__responseStatusText(rest));
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkRest__responseHeader(rest));
    Memo1.Lines.Add(responseBody);
    Exit;
  end;

jsonResponse := CkJsonObject_Create();
CkJsonObject_Load(jsonResponse,responseBody);
CkJsonObject_putEmitCompact(jsonResponse,False);
Memo1.Lines.Add(CkJsonObject__emit(jsonResponse));
Memo1.Lines.Add('Success.');

// A sample JSON response:

// {
//   "Account": {
//     "Name": "Banana Republic",
//     "SubAccount": false,
//     "FullyQualifiedName": "Banana Republic",
//     "Active": true,
//     "Classification": "Liability",
//     "AccountType": "Credit Card",
//     "AccountSubType": "CreditCard",
//     "CurrentBalance": 0,
//     "CurrentBalanceWithSubAccounts": 0,
//     "CurrencyRef": {
//       "value": "USD",
//       "name": "United States Dollar"
//     },
//     "domain": "QBO",
//     "sparse": false,
//     "Id": "97",
//     "SyncToken": "0",
//     "MetaData": {
//       "CreateTime": "2016-10-25T05:07:12-07:00",
//       "LastUpdatedTime": "2016-10-25T05:07:12-07:00"
//     }
//   },
//   "time": "2016-10-25T05:07:11.714-07:00"
// }

CkJsonObject_Dispose(jsonToken);
CkOAuth1_Dispose(oauth1);
CkRest_Dispose(rest);
CkJsonObject_Dispose(jsonRequest);
CkStringBuilder_Dispose(sbPath);
CkJsonObject_Dispose(jsonResponse);

end;

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.