Getting Syntax Error

Yeah, it’s not published there. Go look at Xojo’s GitHub repos.

1 Like

ADD a URLConnection object to your window:

Your code will then look like this: notice I now use the object, not a local variable

Var  apiUsername As String = "usernam"
Var  apiPassword As String = "Password"
Var  integrationCode As String = "Key"
Var apiEndpoint As String = "https://webservices16.autotask.net/atservicesrest/V1.0/Companies"

Var  requestBody as New JSONItem
requestBody.Value("companyType") = 1
requestBody.Value("ownerResourceID") = 29682885
requestBody.Value("companyName") =TextField1.Text
requestBody.Value("Phone") = TextField2.Text
requestBody.Value("WebAddress") = TextField3.Text
requestBody.Value("City") =  TextField4.Text
requestBody.Value("State") = TextField5.Text
requestBody.Value("CountryID") =  TextField6.Text


URLConnection1.SetRequestContent(requestBody.ToString, "application/json")
URLConnection1.RequestHeader("ApiIntegrationCode") = integrationCode
URLConnection1.RequestHeader("UserName") = apiUsername
URLConnection1.RequestHeader("Secret") = apiPassword

URLConnection1.send("POST",apiEndpoint)

Right click on the URLConnection1 object in the IDE
Add an event - choose ContentReceived

Then put your handling code in there, like this, noting that the response is in ‘content’, and that you can check the HTTPStatus too.
I dont know what API you are calling, and I don’t want to bother trying to connect, but are you sure that only a success will generate content that includes ItemID?
(Try creating the same account twice and actually look at the returned values, just in case it says ‘Already present’ ItemID= 34 or similar)

Thank you so much for everyones help. This is now mostly working . Except that I think my Event Handler for the error seems to be doing weird things

Var Dict as Dictionary 
dict = ParseJSON(content)

//debug content here


if Dict.HasKey("Itemid") Then 
  MessageBox("Customer Created Successfully") 
Else
  MessageBox("Error: " + Dict.Value("message"))
End if 

When I run this code Everyhting works (i.e the customer gets added to the CRM)… BUT I get the errors message rather than Customer Created Successfully. If you look below the ItemID is there so should give me the correct message

Case.
This is capital I, but the JSON has it as itemId … the first i is lowercase, and the second one is Capitalised

Ah thank you. I did not realise it was case sensitive.

Something so small.

Its all working now. Thank you so much for everyone’s help on this… I have learned a lot !!!

Ok now that this code is working well in Desktop I wanted to write it for Web. I noticed however that there is no URLConnection on Web. WHat the best way to convert this

There definitely IS URLConnection for Web!

There does not appear to be a control I can drag in like i can on the desktop. So I was not sure it was available