B4J Question Problems with a UI Application, calling a Rest API

imbault

Well-Known Member
Licensed User
Longtime User
Hi smart people,

I have a problem when I call a Rest API using HttpJob, the Wait For goes immediatly to the following line: no execution

I use the same API in a Non-UI Application, where I add a StartMessageLoop before calling the getAllIoTemplates function and a StopMessageLoop at the end of the getAllIoTemplates function : in this case no problem....

Libraries used:
OkHttp V1.22
JOKHttpUtils2 V2.92
JHTTP V1.11 ( I think it's useless)

Here is the code :
code fragment:
Sub Button1_Click
    getIoTemplateId
End Sub



Sub getAllIoTemplates
    Dim job As HttpJob
    'TemplateId Global Variable , RAZ to ""
    TemplateId = ""

    'Get all templates
    Dim ci As String
    ci="https://api.safetyculture.io/templates/search"
    ci = ci & "?field=name"
    
    job.Initialize("", Me)
    job.Download(ci)
    job.GetRequest.SetHeader("authorization", "Bearer " & cIOToken)
    Wait For (job) JobDone(job As HttpJob)
    If job.Success Then
        Log(job.GetString)
    Else
        xui.Msgbox2Async("Pb pour accèder à l'API iAuditor : /templates/search" & CRLF &  "Maybe check Bearer","CEE to iAuditor","","","",Null)
    End If
    job.release
End Sub

Any help or suggestion will be greatly appreciated

Patrick
 

imbault

Well-Known Member
Licensed User
Longtime User
It should be Authorization with upper case in the header

Thank you helping, Enrique, but unfortunately, this is not the case, see bellow the same call with SOAPUI:

1603551609133.png
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Okey next suggestion would be to add the content-type there is a special method for that in httpjob getrequest

Content-Type:application/json
 
Upvote 0

imbault

Well-Known Member
Licensed User
Longtime User
Okey next suggestion would be to add the content-type there is a special method for that in httpjob getrequest

Content-Type:application/json
Enrique, in my first message, I said the same function works perfectly in a NON-UI B4J Application
(anywas, I tried adding

job.GetRequest.SetHeader("Content-Type", "application/json")
job.GetRequest.SetContentType("application/json")
job.GetRequest.SetContentEncoding("text/plain")

And same behaviour...
 
Upvote 0

imbault

Well-Known Member
Licensed User
Longtime User
Sorry, problem solved.

the problem was in initialisation of parameters :

B4X:
    'Setup App Parameters
    If File.Exists(file.DirAssets,IOToken_File) Then
        cIOToken = File.ReadString(file.DirAssets, IOToken_File)
    End If
File.Exists doesn't suppprt File.DirAssets, in B4J...

While It should supports it. Another story, I guess....

My apologies for this thread

Patrick
 
Upvote 0
Top