Unable to create HTTP client. Make sure LibreOffice is configured to allow HTTP requests

Guys I am trying to insert and run a Macro that calls a website but I keep getting this as a resonse even when I try running a simple test script? I have looked and searched for any HTTP settings within Libre to no avail. Any help or guidance in the right direction would be appreciated. Thank you

Sub TestHTTPClient()
Dim httpClient As Object
Dim httpResponse As Object
Dim url As String

' Specify the URL to test
url = "https://www.google.com"

' Create HTTP client
On Error Resume Next
Set httpClient = CreateUnoService("com.sun.star.util.HTTPClient")
On Error GoTo 0

If httpClient Is Nothing Then
    MsgBox "Unable to create HTTP client. Make sure LibreOffice is configured to allow HTTP requests."
    Exit Sub
End If

' Send HTTP GET request
On Error Resume Next
Set httpResponse = httpClient.SendRequest("GET", url)
On Error GoTo 0

If httpResponse Is Nothing Then
    MsgBox "Error sending HTTP request."
    Exit Sub
End If

' Display response status code
MsgBox "Response Status Code: " & httpResponse.StatusCode

End Sub

Did you use some sort of AI to generate that code? Please don’t omit that information. Because the AIs generate garbage. There is no com.sun.star.util.HTTPClient in LibreOffice.

Mike yes I have been trying to put together a complicated script to query two contracts but it was not working.
So I asked ChatGPT for a simple script to test why I couldn’t make a HTTP connection to the contract on the web.
What should I do now to at least test if Libre will make the connection?
Then I can go back to reviewing the proper script macro in Basic.
Problem is what I am trying to do is above my general ability level.

Perhaps you could start with showing what code you first tried before you went down the ChatGPT rabbit hole. And perhaps describe what you hope to return from the website.

Rob thank you I will do that then. Does it matter that this other code is mainly through ChatGTP but wi5h some input from me?

but at least generates something …

and probably get requests over some long legacy of guilty silence or vagueness ? :wink:

Given the quality of chatgpt coding we have already seen, that might be a waste of time. If the links @fpy has provided don’t help, perhaps come back with specific questions. You might also, as mentioned before, tell what is the task you need to undertake that you think needs a macro with http connectivity.

You write that as if it is better to generate a nonsensical answer to one’s question, waste the questioner’s time trying to make the answer work, waste time of others who try to help the questioner when they turn to the Ask site seeking for clarification… and now that non-existent service name has appeared here on the Ask LibreOffice site, adding to the noise of the Internet.

No idea what could that mean. Possibly you hint on something, but not everyone could guess.

<meta_debate>

just illustrated by the 2 Ask LibreOffice posts I linked.
one with zero answer,
the other one so open that it may be not so far from AI generated one :wink:

interesting topic …
even when there are blessed marked solutions, filtering them out to figure out what to do with them remains a lot of work :wink:

</meta_debate>

It would probably be smarter to use a decent programming language and the documentation available there, instead of letting “ChatGPT” write Basic-code-poems for you!

Or call the almighty curl command line tool from LO. :slightly_smiling_face:

Please stop trying to put equality between useful answers that might need more work, and nonsense that is 100% wrong. No answer is infinitely better than garbage made up answer. When people don’t know an answer, they may try to point to a direction that might be useful (explaining that it is a possibility), or keep silent, but won’t invent names of non-existent services. Period, no “debate”.

1 Like

pm sent…

Rob or anyone who might help.
Ok so here goes what I am trying to achieve is a spreadsheet with a list of the optOut addresses and the Balance Amount of WFLR in each address and an aggregated total balance.

The BASIC script should first connect via http somehow to gather optOut addresses from 20.optOutAddresses in the original contract by running a loop starting at “0” and ending when an error message “(error) : (-32000) execution reverted “ is returned (approximately 220 addresses) instead of a valid address that starts with “0x”
and then next query the balance of WFLR for each opt-out address in the new contract at 2.balanceOf

Original contract DistributionToDelegators (0x9c7A4C83842B29bB4A082b0E689CB9474BD938d0) - Flare Explorer

New contract

The script so far as provided mostly by AI is as follows but it does not work and I am not clever enough to identify and rectify so I am appealing to this forum for help.

I have Libre Office Calc version Version: 7.6.4.1 (X86_64) / LibreOffice Community
Build ID: e19e193f88cd6c0525a17fb7a176ed8e6a3e2aa1
CPU threads: 8; OS: Windows 10.0 Build 19045; UI render: Skia/Raster; VCL: win
Locale: en-AU (en_AU); UI: en-GB
Calc: threaded

I have installed the getrest.oxt extension

' Function to parse JSON response and extract WFLR amounts
Function ParseResponse(jsonResponse As String) As Double
    ' Convert JSON response to a dictionary object
    Dim json As Object
    json = ParseJSON(jsonResponse)
    
    ' Initialize WFLR value
    Dim wflrValue As Double
    wflrValue = 0
    
    ' Assuming the JSON response is a dictionary with keys as addresses and values as WFLR amounts
    Dim address As Variant
    For Each address In json.Keys()
        wflrValue = wflrValue + json(address)
    Next address
    
    ' Return total WFLR value
    ParseResponse = wflrValue
End Function

Sub QueryContracts()
    Dim optOutAddresses() As String
    Dim totalWFLR As Double
    Dim index As Integer
    
    ' Initialize total WFLR and index
    totalWFLR = 0
    index = 0
    
    ' Loop to gather optOut addresses from the original contract
    Do
        ' Construct URL for the original contract
        Dim url As String
        url = "https://flare-explorer.flare.network/address/0x9c7A4C83842B29bB4A082b0E689CB9474BD938d0/read-contract?20.optOutAddresses[" & index & "]"
        
        ' Make HTTP GET request using GetRest extension
        Dim optOutJsonResponse As String
        optOutJsonResponse = GetRest(url)
        
        ' Parse JSON response to get optOut address
        Dim optOutAddress As String
        optOutAddress = ParseResponse(optOutJsonResponse)
        
        ' Check if optOut address is valid
        If optOutAddress <> "" Then
            ' Add optOut address to array
            ReDim Preserve optOutAddresses(index)
            optOutAddresses(index) = optOutAddress
            
            ' Increment index for next optOut address
            index = index + 1
        Else
            ' Exit loop if no more optOut addresses found
            Exit Do
        End If
    Loop
    
    ' Query balance of WFLR for each optOut address in the new contract
    For Each optOutAddress In optOutAddresses
        ' Construct URL for the new contract
        Dim newContractUrl As String
        newContractUrl = "https://flare-explorer.flare.network/token/0x1D80c49BbBCd1C0911346656B529DF9E5c2F783d/read-contract?2.balanceOf=" & optOutAddress
        
        ' Make HTTP GET request using GetRest extension
        Dim balanceJsonResponse As String
        balanceJsonResponse = GetRest(newContractUrl)
        
        ' Parse JSON response to get balance of WFLR
        Dim balance As Double
        balance = ParseResponse(balanceJsonResponse)
        
        ' Add balance to total WFLR
        totalWFLR = totalWFLR + balance
    Next optOutAddress
    
    ' Output total WFLR to cell A1 in the current sheet
    ThisComponent.Sheets(0).getCellByPosition(0, 0).Value = "Total WFLR: " & Format(totalWFLR, "0.00")
End Sub

why would it have to be in BASIC ?

maybe let’s try to (re)start on stable ground, not sure though what is your actual level in programming or tooling …

have you an understanding for example of this :

fpy Stable ground sounds like a good place to start. I am not a coder or developer of any sort but I have compiled a whole array of spreadsheets but only one with an API call so my understanding is not very good in this area.
I know what I want and how and where to connect to in achieving my aim but I do not know the HOW. That’s why I turned to AI for assistance. The language does not have to be BASIC as it could be anything that will work from within Libre Office Calc. I have read through a lot of the posts and links but my base grounding on the syntax in constructing macros leaves me scratching my head somewhat.
I am most certainly open to suggestions or directions if you or anyone can help. Thanks

thing is, the know HOW, often makes reconsider the “where to” :wink:

To get more familiar with this flare API, you can play with
https://flare-explorer.flare.network/graphiql
from the link I referenced above, seems the balance or balancemulti function might go towards what you want to do … ?

and for calc, try WEBSERVICE() like roughly shown in the sheet attached
flare.ods (8.3 KB)

Maybe also check other existing tools like
https://docs.flare.network/dev/tools/

1 Like

Thank you for taking the time to have a look and advise. i will explore these avenues firstly.

Thank you for your help but after looking through these links and other reading and videos I think this might just be beyond my capabilities, unfortunately. I will keep trying in the background but could you maybe just advise me of the broad outline of what I need to do ie Which language is best BASIC etc, which function do I use WEBSERVICE() or getRest.oxt to make the web connections?

At this point, try to ping the providers to get a (first free) subscription and see what is actually available

Otherwise, seems even manual interactions (like the 20.optOut form you mentionned) are limited.
Couldn’t get a csv either
https://flare-explorer.flare.network/csv-export?address=0x9c7A4C83842B29bB4A082b0E689CB9474BD938d0&type=transactions