B4J Question Problems to httpjob dont send parameters

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
hello all !
i am trying to make multiple httpjobs to an API, in Localhost works fine, if i upload to vps ( Digital Ocean ) i got some erros :

Code:
killed ? = null
ResponseError. Reason: Bad Request, Response: ["ERROR_LOGIN_PARAMETERS_MISSING","os parâmetros login, senha ou user_token estão faltando; ver documentação em seu navegador em http://100.Xxx.xxxx.xxx:1010/apirest.php/#ERROR_LOGIN_PARAMETERS_MISSING"]
ResponseError. Reason: Bad Request, Response: ["ERROR_SESSION_TOKEN_MISSING","o parâmetro session_token está faltando ou vazio; ver documentação em seu navegador em http://100.Xxx.xxxx.xxx:1010/apirest.php/#ERROR_SESSION_TOKEN_MISSING"]
sending msg to zap
zap enviado ? {
    "success": false,
    "error": "Sem contato para enviar"
}
Zap ? = ok
ResponseError. Reason: Bad Request, Response: ["ERROR_SESSION_TOKEN_MISSING","o parâmetro session_token está faltando ou vazio; ver documentação em seu navegador em http://100.Xxx.xxxx.xxx:1010/apirest.php/#ERROR_SESSION_TOKEN_MISSING"]
killed ? = null
zap = ok

this is the function that is calling multiple httpjob resumable :
B4X:
Sub actionopenchamado_Click (Params As Map)

    If (UserCode <> "") Then
        
        Log("open chamado : ")

        Wait For( Manager.LGPI_InitSession) Complete (tmpSession As String)
        Log("session = "&tmpSession)

        If (tmpSession <> "") Then

            Dim SelectedOption As String = ws.EvalWithResult($"return $('#tecnicosLista').find(":selected").val();"$, Null).Value
            Dim tmpchamadoTitle As String = chamadot.GetVal.Value
            Dim tmpchamadoData As String = chamadod.GetVal.Value
            
            Log("SelectedOption = "&SelectedOption)

            Wait For( Manager.LGPI_CreateTicket(tmpSession,tmpchamadoTitle,tmpchamadoData,UserId,SelectedOption,EntityId)) Complete (tmpTicket As String)

            Dim tparser As JSONParser
            tparser.Initialize(tmpTicket)
            Dim root As Map = tparser.NextObject
            Dim chamadoid As Int = root.Get("id")
            Dim chamadomessage As String = root.Get("message")


            Dim chamadoHtml As String = $"
            <div class="card" id="card${chamadoid}">
                <div class="card-body">
                    <h4 class="card-title">[${chamadoid}] ${tmpchamadoTitle}</h4>
                    <h6 id="statusChamado${chamadoid}" style="color: var(--green);">ABERTO</h6>
                    <p class="card-text">${tmpchamadoData}<br/><br/></p>
                    <button class="btn btn-primary disabled" Type="button">Abrir Chat</button>
                    <button id="closechamado:${chamadoid}" class="btn btn-danger" Type="button">Fechar Chamado</button>
                </div>
            </div>
            "$
            
            areachamados.SetHtml(chamadoHtml&areachamados.GetHtml.Value)
            
            ws.Eval("$('#modalChamados').modal('hide');",Null)
            
            ws.Eval($"Toastify({
              text: "Chamado aberto, breve será atendido !",
              duration: 3000,
              destination: "",
              newWindow: true,
              close: true,
              gravity: "bottom", // `top` or `bottom`
              position: "right", // `left`, `center` or `right`
              stopOnFocus: true, // Prevents dismissing of toast on hover
              style: {
                background: "linear-gradient(to right, #00b09b, #96c93d)",
              },
              onClick: function(){} // Callback after click
            }).showToast();
            "$,Null)
            
            chamadot.SetVal("")
            chamadod.SetVal("")
            
            ws.Flush
            
            Log("chegou aqui !")

            Wait For( Manager.LGPI_KillSession(tmpSession) ) Complete (tmpKill As String)
            Log("killed ? = "&tmpKill)

            Wait For( Manager.ZapMsg("Chamado Criado [id] : "&chamadoid&".",SelectedOption) ) Complete (tmpzap As String)
            Log("zap = "&tmpzap)
            '    LocalDB.CriarChamado(chamadoid,UserCode)

        Else
            
            ws.Eval("$('#modalChamados').modal('hide');",Null)
            
            ws.Eval($"Toastify({
              text: "Houve um erro ao abrir o chamado.",
              duration: 3000,
              destination: "",
              newWindow: true,
              close: true,
              gravity: "bottom", // `top` or `bottom`
              position: "right", // `left`, `center` or `right`
              stopOnFocus: true, // Prevents dismissing of toast on hover
              style: {
                background: "linear-gradient(to right, #CC0000,#FF0000)",
              },
              onClick: function(){} // Callback after click
            }).showToast();
            "$,Null)
            
            chamadot.SetVal("")
            chamadod.SetVal("")
            
            ws.Flush
            
        End If

    End If

some examples of how functions are calling httpjob

B4X:
Sub LGPI_InitSession As ResumableSub
    Dim job As HttpJob
    Dim session_token As String = ""
    job.Initialize("", Me) 'note that the name parameter is no longer needed.
    job.Download("https://mydomain/apirest.php/initSession")
    job.GetRequest.SetHeader("Authorization","Basic BASIC64TOKEN==")
    job.GetRequest.SetHeader("App-Token","MYAPPTOKEN")
    Wait For JobDone(job As HttpJob)
    If job.Success Then
        Dim parser As JSONParser
        parser.Initialize(job.GetString)
        Dim root As Map = parser.NextObject
        session_token = root.Get("session_token")
        Log(session_token)
    End If
    job.Release
    Return session_token
End Sub

Sub LGPI_KillSession(sessionid As String) As ResumableSub
    
    Dim job As HttpJob
    job.Initialize("", Me) 'note that the name parameter is no longer needed.
    job.Download("https://mydomain/apirest.php/killSession")
    job.GetRequest.SetHeader("Authorization","Basic BASIC64TOKEN==")
    job.GetRequest.SetHeader("App-Token","MYAPPTOKEN")
    Wait For JobDone(job As HttpJob)
    If job.Success Then
        If (job.GetString.Contains("ERROR_SESSION_TOKEN_INVALID")) Then
            Log("KillSession = ERROR_SESSION_TOKEN_INVALID")
            job.Release
            Return "error"
        End If
        job.Release
        Return "ok"
    End If
    job.Release
End Sub


Sub LGPI_CreateTicket(t_session As String,t_name As String,t_content As String,t_requerente As Int,t_tecnico As Int,t_entidade As Int) As ResumableSub
    
    Dim t_json As String = $"{
        "input": {
            "name": "${t_name}",
            "content": "${t_content}",
            "status": "1",
            "urgency": 2,
            "entities_id": ${t_entidade},
            "users_id_lastupdater": ${t_tecnico},
            "users_id_recipient": ${t_requerente},
            "_users_id_requester": ${t_requerente},
            "_users_id_assign": ${t_tecnico},
            "status": 1,
            "priority": 2
        }
    }"$
    
    'Log("Json = "&t_json)
    Log("Session Token Create : "&t_session)
    
    Dim job As HttpJob
    job.Initialize("", Me) 'note that the name parameter is no longer needed.
    job.PostString("mydomain/apirest.php/Ticket/",t_json)
    job.GetRequest.SetContentType("application/json")
    job.GetRequest.SetHeader("session-token",t_session)
    job.GetRequest.SetHeader("App-Token","MYtoken")
    'job.GetRequest.SetHeader("Content-Type","application/json")
    Wait For JobDone(job As HttpJob)
    If job.Success Then
        Return job.GetString
    End If
    job.Release
    
End Sub
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…