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) Walmart Partner API Authentication (Generate a Signature for a Request)

Demonstrates how to generate a signature for a Walmart Partner REST API call.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Boolean iSuccess
    String sConsumerId
    String sBaseUrl
    String sPrivateEncodedStr
    String sHttpMethod
    Handle hoDt
    Boolean iBLocal
    Integer iTimeStampVal
    Handle hoSbStringToSign
    Variant vPrivKey
    Handle hoPrivKey
    Handle hoRsa
    String sSignatureString
    String sTemp1
    Boolean bTemp1

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

    Move "b68d2a72...." To sConsumerId
    Move "https://marketplace.walmartapis.com/v2/feeds" To sBaseUrl
    // This is your Base64 encoded private key
    Move "MIICeAIBADANBgkqhkiG9w0BAQEFAA......" To sPrivateEncodedStr
    Move "GET" To sHttpMethod

    // We need a timestamp in decimal string form representing the number of milliseconds since Jan 01 1970 UTC.
    Get Create (RefClass(cComCkDateTime)) To hoDt
    If (Not(IsComObjectCreated(hoDt))) Begin
        Send CreateComObject of hoDt
    End
    // Set bLocal = True for a timestamp in the local timezone.  Set bLocal = False for a UTC timestamp.
    Move False To iBLocal
    // This gets the timestamp in seconds, not milliseconds.
    Get ComGetAsUnixTime Of hoDt iBLocal To iTimeStampVal

    // Build the string to sign.
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbStringToSign
    If (Not(IsComObjectCreated(hoSbStringToSign))) Begin
        Send CreateComObject of hoSbStringToSign
    End
    Get ComAppend Of hoSbStringToSign sConsumerId To iSuccess
    Get ComAppend Of hoSbStringToSign (character(10)) To iSuccess
    Get ComAppend Of hoSbStringToSign sBaseUrl To iSuccess
    Get ComAppend Of hoSbStringToSign (character(10)) To iSuccess
    Get ComAppend Of hoSbStringToSign sHttpMethod To iSuccess
    Get ComAppend Of hoSbStringToSign (character(10)) To iSuccess
    Get ComAppendInt Of hoSbStringToSign iTimeStampVal To iSuccess
    // We add three zero's so that the timestamp value is in milliseconds.
    // We don't care about accuracy down to less than a second.
    // All the server cares about is that the request was signed at the current date/time
    // within some reasonable margin of error (to account for systems having clocks
    // that may be slightly different).
    Get ComAppend Of hoSbStringToSign "000" + (character(10)) To iSuccess

    Get Create (RefClass(cComChilkatPrivateKey)) To hoPrivKey
    If (Not(IsComObjectCreated(hoPrivKey))) Begin
        Send CreateComObject of hoPrivKey
    End
    // Load the private key into a private key object.
    // Note: Technically the private key is not PEM because it lacks the header/footer strings
    // used for PEM.  However, the LoadPem method will still accept it and load it correctly.
    Get ComLoadPem Of hoPrivKey sPrivateEncodedStr To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoPrivKey To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatRsa)) To hoRsa
    If (Not(IsComObjectCreated(hoRsa))) Begin
        Send CreateComObject of hoRsa
    End
    Get pvComObject of hoPrivKey to vPrivKey
    Get ComImportPrivateKeyObj Of hoRsa vPrivKey To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRsa To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // We want a base64 signature string.
    Set ComEncodingMode Of hoRsa To "base64"

    Get ComGetAsString Of hoSbStringToSign To sTemp1
    Get ComSignStringENC Of hoRsa sTemp1 "SHA256" To sSignatureString
    Get ComLastMethodSuccess Of hoRsa To bTemp1
    If (bTemp1 <> True) Begin
        Get ComLastErrorText Of hoRsa To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Signature String: " sSignatureString


End_Procedure

 

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