B4J Question Create a json string for PostString

codie01

Active Member
Licensed User
Longtime User
Hi All,

I have an API call to make as follows:

PUT /v1/{location_id}/items/{item_id}/fees/{fee_id}

My Code is as follows:

B4X:
        Dim j As HttpJob
        j.Initialize("j", Me)
        j.PostString("https://connect.squareup.com/v1/" & myLocation & "/items/" & itemToken & "/fees/", ABMShared.feeTaxID)
        j.GetRequest.SetHeader("Authorization", myBearer)
        j.GetRequest.SetContentType("application/json")
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Log(j.JobName)
        End If
        j.Release

The logged error I am getting back from the job is:

ResponseError. Reason: Bad Request, Response: {"type":"bad_request","message":"invalid json"}

The issue is ABMShared.feeTaxID {fee_id} is not in json format, I have tried to wrap it in brackets but is does not work.

Thanks for some guidance in advance.
 

MarkusR

Well-Known Member
Licensed User
Longtime User
i think poststring run the action so it is called last after http header.
B4X:
PutString (Link As String, Text As String) As String
Sends a PUT request with the given data as the post data.

invalid json
if you return a object (as json) from web api you know what you can send to it
if it is a input for a function.
 
Upvote 0

codie01

Active Member
Licensed User
Longtime User
Hi Mark, Thanks but that's what I have above In need to wrap ABMShared.feeTAXID with json some how.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
see lib json
JSONGenerator
JSONParser

me thought its your web API
example what i mean, the input/output will be json or xml.

B4X:
void testin(a as myclass)
{
}

myclass testout()
{
  myclass a = new myclass
 return a
}
 
Last edited:
Upvote 0

codie01

Active Member
Licensed User
Longtime User
Thanks Mark Solved it.

If the PostString does not require json change this:

B4X:
j.PostString("https://connect.squareup.com/v1/" & myLocation & "/items/" & itemToken & "/fees/", ABMShared.feeTaxID)

to this leaving the Text String blank "" :
B4X:
j.PutString("https://connect.squareup.com/v1/" & myLocation & "/items/" & itemToken & "/fees/" & ABMShared.feeTaxID,"")

Kind Regards,
Phil
 
Upvote 0
Top