Sample code for 30+ languages & platforms
DataFlex

MercadoLibre - GET Request with Authorization Bearer Access Token

See more MercadoLibre Examples

Demonstrates how to send an HTTPS GET request to MercadoLibre with an "Authorization: Bearer $ACCESS_TOKEN" header.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoHttp
    Handle hoJsonToken
    String sResponseStr
    String sTemp1
    Boolean bTemp1

    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(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    // First get our previously obtained OAuth2 access token.
    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonToken
    If (Not(IsComObjectCreated(hoJsonToken))) Begin
        Send CreateComObject of hoJsonToken
    End
    Get ComLoadFile Of hoJsonToken "qa_data/tokens/mercadolibre.json" To iSuccess
    If (iSuccess = False) Begin
        Showln "Failed to load JSON access token."
        Procedure_Return
    End

    // This adds the "Authorization: Bearer $ACCESS_TOKEN" header field.
    Get ComStringOf Of hoJsonToken "access_token" To sTemp1
    Set ComAuthToken Of hoHttp To sTemp1

    // Use your seller ID.
    Get ComSetUrlVar Of hoHttp "SELLER_ID" "577815702" To iSuccess

    Get ComQuickGetStr Of hoHttp "https://api.mercadolibre.com/questions/search?seller_id={$SELLER_ID}&api_version=4" To sResponseStr
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln sResponseStr


End_Procedure