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

PowerBuilder 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

 

 

 

(PowerBuilder) QuickBooks - Create an Employee

Demonstrates how to send an JSON request to create a QuickBooks employee

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
oleobject loo_JsonToken
integer li_Success
oleobject loo_Oauth1
oleobject loo_Rest
integer li_BAutoReconnect
oleobject loo_JsonRequest
oleobject loo_Addr
oleobject loo_Phone
string ls_RequestBody
oleobject loo_SbPath
integer li_NumReplacements
string ls_ResponseBody
oleobject loo_JsonResponse

// 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.
loo_JsonToken = create oleobject
li_rc = loo_JsonToken.ConnectToNewObject("Chilkat_9_5_0.JsonObject")
if li_rc < 0 then
    destroy loo_JsonToken
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_JsonToken.LoadFile("qa_data/tokens/quickbooks.json")

loo_Oauth1 = create oleobject
li_rc = loo_Oauth1.ConnectToNewObject("Chilkat_9_5_0.OAuth1")

loo_Oauth1.ConsumerKey = "QUICKBOOKS_CONSUMER_KEY"
loo_Oauth1.ConsumerSecret = "QUICKBOOKS_CONSUMER_SECRET"
loo_Oauth1.Token = loo_JsonToken.StringOf("oauth_token")
loo_Oauth1.TokenSecret = loo_JsonToken.StringOf("oauth_token_secret")

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat_9_5_0.Rest")

// 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.
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("sandbox-quickbooks.api.intuit.com",443,1,li_BAutoReconnect)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_JsonToken
    destroy loo_Oauth1
    destroy loo_Rest
    return
end if

loo_Rest.SetAuthOAuth1(loo_Oauth1,0)

// Create the following JSON:
// {
//   "SSN": "444-55-6666",
//   "PrimaryAddr": {
//     "Id": "50",
//     "Line1": "45 N. Elm Street",
//     "City": "Middlefield",
//     "CountrySubDivisionCode": "CA",
//     "PostalCode": "93242"
//   },
//   "GivenName": "John",
//   "FamilyName": "Meuller",
//   "PrimaryPhone": {
//     "FreeFormNumber": "408-525-1234"
//   }
// }
// 
loo_JsonRequest = create oleobject
li_rc = loo_JsonRequest.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JsonRequest.AppendString("SSN","444-55-6666")
loo_Addr = loo_JsonRequest.AppendObject("PrimaryAddr")
loo_Addr.AppendString("Id","50")
loo_Addr.AppendString("Line1","45 N. Elm Street")
loo_Addr.AppendString("City","Middlefield")
loo_Addr.AppendString("CountrySubDivisionCode","CA")
loo_Addr.AppendString("PostalCode","93242")
destroy loo_Addr
loo_JsonRequest.AppendString("GivenName","John")
loo_JsonRequest.AppendString("FamilyName","Meuller")
loo_Phone = loo_JsonRequest.AppendObject("PrimaryPhone")
loo_Phone.AppendString("FreeFormNumber","408-525-1234")
destroy loo_Phone

ls_RequestBody = loo_JsonRequest.Emit()

// The company ID is the realmId
loo_SbPath = create oleobject
li_rc = loo_SbPath.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_SbPath.Append("/v3/company/<companyID>/employee")
li_NumReplacements = loo_SbPath.Replace("<companyID>",loo_JsonToken.StringOf("realmId"))

loo_Rest.AddHeader("Content-Type","application/json")
loo_Rest.AddHeader("Accept","application/json")
loo_Rest.AllowHeaderFolding = 0

// If we want a URL such as this: https://sandbox-quickbooks.api.intuit.com/v3/company/193514465596199/employee?minorversion=4
// then the query params must be added here:
loo_Rest.AddQueryParam("minorversion","4")

ls_ResponseBody = loo_Rest.FullRequestString("POST",loo_SbPath.GetAsString(),ls_RequestBody)
if loo_Rest.LastMethodSuccess <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_JsonToken
    destroy loo_Oauth1
    destroy loo_Rest
    destroy loo_JsonRequest
    destroy loo_SbPath
    return
end if

// We should expect a 200 response if successful.
if loo_Rest.ResponseStatusCode <> 200 then
    Write-Debug "Request Header: "
    Write-Debug loo_Rest.LastRequestHeader
    Write-Debug "----"
    Write-Debug "Response StatusCode = " + string(loo_Rest.ResponseStatusCode)
    Write-Debug "Response StatusLine: " + loo_Rest.ResponseStatusText
    Write-Debug "Response Header:"
    Write-Debug loo_Rest.ResponseHeader
    Write-Debug ls_ResponseBody
    destroy loo_JsonToken
    destroy loo_Oauth1
    destroy loo_Rest
    destroy loo_JsonRequest
    destroy loo_SbPath
    return
end if

loo_JsonResponse = create oleobject
li_rc = loo_JsonResponse.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JsonResponse.Load(ls_ResponseBody)
loo_JsonResponse.EmitCompact = 0
Write-Debug loo_JsonResponse.Emit()
Write-Debug "Success."

// A sample JSON response:
// {
//   "Employee": {
//     "SSN": "XXX-XX-XXXX",
//     "PrimaryAddr": {
//       "Id": "97",
//       "Line1": "45 N. Elm Street",
//       "City": "Middlefield",
//       "CountrySubDivisionCode": "CA",
//       "PostalCode": "93242"
//     },
//     "BillableTime": false,
//     "domain": "QBO",
//     "sparse": false,
//     "Id": "59",
//     "SyncToken": "0",
//     "MetaData": {
//       "CreateTime": "2016-10-25T14:05:05-07:00",
//       "LastUpdatedTime": "2016-10-25T14:05:05-07:00"
//     },
//     "GivenName": "John",
//     "FamilyName": "Meuller",
//     "DisplayName": "John Meuller",
//     "PrintOnCheckName": "John Meuller",
//     "Active": true,
//     "PrimaryPhone": {
//       "FreeFormNumber": "408-525-1234"
//     }
//   },
//   "time": "2016-10-25T14:05:05.661-07:00"
// }
// 


destroy loo_JsonToken
destroy loo_Oauth1
destroy loo_Rest
destroy loo_JsonRequest
destroy loo_SbPath
destroy loo_JsonResponse

 

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