Sample code for 30+ languages & platforms
DataFlex

BrickLink OAuth1 using Chilkat REST

See more BrickLink Examples

Demonstrates sending an api.bricklink.com request with OAuth1 authentication using Chilkat REST.

Note: This example requires Chilkat v9.5.0.91 or greater (due to adjustments made within Chilkat to support bricklink OAuth1 needs).

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Variant vOauth1
    Handle hoOauth1
    Handle hoRest
    Variant vSbResponse
    Handle hoSbResponse
    Handle hoJson
    String sTemp1
    Integer iTemp1

    Move False To iSuccess

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

    Get Create (RefClass(cComChilkatOAuth1)) To hoOauth1
    If (Not(IsComObjectCreated(hoOauth1))) Begin
        Send CreateComObject of hoOauth1
    End

    Set ComConsumerKey Of hoOauth1 To "Your Consumer Key"
    Set ComConsumerSecret Of hoOauth1 To "Your Consumer Secret"
    Set ComToken Of hoOauth1 To "Your OAuth1 Token"
    Set ComTokenSecret Of hoOauth1 To "Your Token Secret"
    Set ComSignatureMethod Of hoOauth1 To "HMAC-SHA1"

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

    Get pvComObject of hoOauth1 to vOauth1
    Get ComSetAuthOAuth1 Of hoRest vOauth1 False To iSuccess

    Get ComConnect Of hoRest "api.bricklink.com" 443 True True To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponse
    If (Not(IsComObjectCreated(hoSbResponse))) Begin
        Send CreateComObject of hoSbResponse
    End
    Get pvComObject of hoSbResponse to vSbResponse
    Get ComFullRequestNoBodySb Of hoRest "GET" "/api/store/v1/orders?direction=in" vSbResponse To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComResponseStatusCode Of hoRest To iTemp1
    Showln "Response status code = " iTemp1

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get pvComObject of hoSbResponse to vSbResponse
    Get ComLoadSb Of hoJson vSbResponse To iSuccess
    Set ComEmitCompact Of hoJson To False
    Get ComEmit Of hoJson To sTemp1
    Showln sTemp1


End_Procedure