Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The data required for this operation is not yet available #221

Open
rickleliveld opened this issue Jan 12, 2022 · 2 comments
Open

The data required for this operation is not yet available #221

rickleliveld opened this issue Jan 12, 2022 · 2 comments

Comments

@rickleliveld
Copy link

Hello,

When I try to retrieve data via a URL I receive a message: The data required for this operation is not yet available (error -2147483638 (8000000a).

This only happens when I run the macro for the first time.
When I click debug and run the macro again, it does get data from the URL cleanly.

It seems that the data is not yet available so he cannot retrieve it. I've already tried making the code wait for 10 seconds or 1 minute, but that doesn't solve the problem.

Any idea?

 With http
        .Open "GET", "https://api.rentman.net/projectequipment?limit=5&offset=0&sort=-modified, false"
        .setRequestHeader "Content-type", "application/json"
        .setRequestHeader "Accept", "application/json"
        .setRequestHeader "Authorization", "Bearer " & authKey
        .send
    End With

Application.Wait (Now + TimeValue("0:00:01"))

Set JSON = ParseJson(http.responseText)
i = 2
For Each Item In JSON("data")
sht.Cells(i, 1).Value = Item("id")
sht.Cells(i, 2).Value = Item("modified")
sht.Cells(i, 5).Value = Item("equipment_group")
i = i + 1
Next

(text translated via Google translate)

@houghtonap
Copy link

Your issue is not a VBA-JSON issue, it has to do with the fact you are calling the Http open method asynchronously. The wait time probably is not long enough however, you should be calling ParseJson in the callback routine rather than the way it is coded. Alternately, your code is basically synchronous, so just add false after the url in the Http open call and the call will be synchronous.

But wait you are saying, I have False after the Url!? Well no, that comma false is inside the quotes for the Url, thus the async parameter is True by default.

See Microsoft's documentation
https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms757849(v=vs.85)

@rickleliveld
Copy link
Author

Hi Andrew,

Wow, thanks for your quick response. It works and I'm very happy with that, thnxs!

There is just another problem now. When I run the macro for the 2nd time, it doesn't refresh the data.
I probably need to build somewhere that it has to wait for the responsetext?

Can you help me with that? What should I do?

Sincerely,
Rick Leliveld

(text translated by Google)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants