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

DataFlex 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

 

 

 

(DataFlex) SugarCRM Authenticate

Demonstrates how to authenticate to the SugarCRM REST v10 API. This is how an OAuth2 access token is obtained.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoRest
    Boolean iSuccess
Req    Handle hoJsonReq
    Variant vSbReq
    Handle hoSbReq
    Variant vSbJson
    Handle hoSbJson
    Handle hoJson
    String sAccess_token
    Integer iExpires_in
    String sToken_type
    Boolean iScope
    String sRefresh_token
    Integer iRefresh_expires_in
    String sDownload_token
    String sTemp1
    Integer iTemp1

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End

    Get ComConnect Of hoRest "your.site.domain" 443 True True To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComAddHeader Of hoRest "Cache-Control" "no-cache" To iSuccess

    // The following code creates the JSON request body.
    // The JSON created by this code is shown below.
    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonReq
    If (Not(IsComObjectCreated(hoJsonReq))) Begin
        Send CreateComObject of hoJsonReq
    End
    Get ComUpdateString Of hoJsonReq "grant_type" "password" To iSuccess
    Get ComUpdateString Of hoJsonReq "client_id" "sugar" To iSuccess
    Get ComUpdateString Of hoJsonReq "client_secret" "CLIENT_SECRET" To iSuccess
    Get ComUpdateString Of hoJsonReq "username" "admin" To iSuccess
    Get ComUpdateString Of hoJsonReq "password" "password" To iSuccess
    Get ComUpdateString Of hoJsonReq "platform" "custom_api" To iSuccess

    // The JSON request body created by the above code:

    // {
    //   "grant_type": "password",
    //   "client_id": "sugar",
    //   "client_secret": "CLIENT_SECRET",
    //   "username": "admin",
    //   "password": "password",
    //   "platform": "custom_api"
    // }

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbReq
    If (Not(IsComObjectCreated(hoSbReq))) Begin
        Send CreateComObject of hoSbReq
    End
    Get pvComObject of hoSbReq to vSbReq
    Get ComEmitSb Of hoJsonReq vSbReq To iSuccess

    Get ComAddHeader Of hoRest "Content-Type" "application/json" To iSuccess

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbJson
    If (Not(IsComObjectCreated(hoSbJson))) Begin
        Send CreateComObject of hoSbJson
    End
    Get pvComObject of hoSbReq to vSbReq
    Get pvComObject of hoSbJson to vSbJson
    Get ComFullRequestSb Of hoRest "POST" "/rest/v10/oauth2/token" vSbReq vSbJson To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComResponseStatusCode Of hoRest To iTemp1
    If (iTemp1 <> 200) Begin
        Get ComResponseStatusCode Of hoRest To iTemp1
        Showln "Received error response code: " iTemp1
        Showln "Response body:"
        Get ComGetAsString Of hoSbJson To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get pvComObject of hoSbJson to vSbJson
    Get ComLoadSb Of hoJson vSbJson To iSuccess

    // The following code parses the JSON response.
    // A sample JSON response is shown below the sample code.

    Get ComStringOf Of hoJson "access_token" To sAccess_token
    Get ComIntOf Of hoJson "expires_in" To iExpires_in
    Get ComStringOf Of hoJson "token_type" To sToken_type
    Get ComIsNullOf Of hoJson "scope" To iScope
    Get ComStringOf Of hoJson "refresh_token" To sRefresh_token
    Get ComIntOf Of hoJson "refresh_expires_in" To iRefresh_expires_in
    Get ComStringOf Of hoJson "download_token" To sDownload_token

    // A sample JSON response body that is parsed by the above code:

    // {
    //   "access_token": "c6d495c9-bb25-81d2-5f81-533ef6479f9b",
    //   "expires_in": 3600,
    //   "token_type": "bearer",
    //   "scope": null,
    //   "refresh_token": "cbc40e67-12bc-4b56-a1d9-533ef62f2601",
    //   "refresh_expires_in": 1209600,
    //   "download_token": "cc5d1a9f-6627-3349-96e5-533ef6b1a493"
    // }

    Showln "Example Completed."


End_Procedure

 

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