B4J Question HTTPJob returns error message.

LWGShane

Well-Known Member
Licensed User
Longtime User
I'm trying to interface with the DigitalOcean API using a HTTPJob, however, the URL (https://api.digitalocean.com/account) returns this:
B4X:
{"id":"not_found","message":"The resource you were accessing could not be found."}

I'm using an active Private Access Token and have no idea why it won't display my account info. Below is the code. (Thanks to @DonManfred for his open source DropBox API wrapper that showed me how to interface with APIs ;))

B4X:
Sub Process_Globals
    Private fx As JFX
    Private DoApiUrlV2 As String = "https://api.digitalocean.com/v2/"
    Public Bearer As String
    Public DropletLimit, FloatingIPLimit, Email, UUID, Verified, Status, StatusMessage As String
  
End Sub

Sub GetAccountInfo
    Log(DoApiUrlV2 & "account")
    Dim GetAcc As HttpJob
    GetAcc.Initialize("GetAccountInfo", Me)
    GetAcc.PostString(DoApiUrlV2 & "account", Null)  
    GetAcc.GetRequest.SetHeader("Authorization", "Bearer " & Bearer)  
    GetAcc.GetRequest.SetHeader("Content-Type", "application/json")
    GetAcc.GetRequest.SetContentType("application/json")
    GetAcc.GetRequest.SetContentEncoding("text/plain")
End Sub
Private Sub HandleGetAccountInfo (Job As HttpJob, Res As String)
    Dim Parser As JSONParser
    Parser.Initialize(Res)
    Dim Map As Map
    Map.Initialize
    Map = Parser.NextObject
    DropletLimit = Map.Get("droplet_limit")
    FloatingIPLimit = Map.Get("floating_ip_limit")
    Email = Map.Get("email")
    UUID = Map.Get("uuid")
    Verified = Map.Get("verified")
    Status = Map.Get("status")
    StatusMessage = Map.Get("status_message")
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
https://www.digitalocean.com/community/tutorials/how-to-use-the-digitalocean-api-v2

SS-2016-01-11_08.18.56.png
 
Upvote 0

LWGShane

Well-Known Member
Licensed User
Longtime User
You only use the export command if you're using CURL. I'm not using CURL as I'm doing everything with HTTP Requests. If the code I have works with DropBox, it should work with DigitalOcean.
 
Upvote 0

LWGShane

Well-Known Member
Licensed User
Longtime User
Maybe. But from the code you posted there is no line which set the bearer variable.

I set it in my Initialize Sub, so I don't have to set it each time I use a method.

I checked DropBox and they use CURL in their examples too, so DO and DB are pretty similar in terms of API functionally.
 
Upvote 0
Top