Getting Syntax Error

Blockquote
That makes no sense. Looks like you just don’t know what you’re doing, not learning. First learn, then do it, from there you see “mistakes” and have few founded doubts, and won’t say “I have no clue what I’m doing”. Where did you get this code that you have no clue how it works?

We all learn in different ways I am learning by making the mistakes (which it clearly seems like I have done) .

I wrote most of the code myself and found some examples on the internet of how to do the rest.

This is how I learn, write code that I think is correct, and then ask for help from peers. Isnt that what this forum is all about… helping each other out.

I am just trying to get some help and would appreciate people not being rude. if that’s too much to ask

I would suggest that you start with one of the Examples that ships with Xojo:
image

Examples - Communication - Internet - Web Services

Good luck.

2 Likes

Well… I don’t see myself being rude. Just as you I’m having questions on how you are leaning or not, and if there’s a better way to do it.

Not saying that’s your case, but in times of ChatGPT, sometimes I’m seeing “learners” using codes like yours, using incomplete, not functional, old syntax code, and they just know what they are doing either, that’s why I asked.

Currently it is difficult to separate genuine learning attempts, from lazy people trying to cheat. As it is not your case, simply do not get offended and just keep going. :wink:

We have all been there. Learning just enough to get started but not really knowing what the problem is.

Interesting. Never even crossed my mind that ChatGPT could help. Did not think it would know about XOJO code.

All good my friend I am just trying to understand how things work and why my code is not working… I often find it easier to examine code from someone else and try to figure out what is happening from there, rather than do it all myself because then I get into these problems where I don’t really know if its working or not.

Yes I think that’s the thing here is I know enough to get started but not enough to be able to diagnose further and I find it easier sometimes to learn from how others do it rather then spending hours fumbling around and getting frustrated with it

Just keep going. To update your code you should not use Text, use URConnection instead of HTTPSocket, no deprecated Xojo.* functions, I would opt for using JSONItem for your JSON/Dictionary needs.

This is what confuses me, I don’t know what you mean Text … do you mean not using Text Boxes

I have changed it to JSONItem and will keep testing it now

image

https://documentation.xojo.com/api/deprecated/text.html

Also change those Dim to Var just to look/feel current code instead of legacy.

Don’t confuse the newbie. Textfield.Text is something different than the Text above.

https://documentation.xojo.com/api/user_interface/desktop/desktoptextfield.html#desktoptextfield-text

ChatGPT can barely be used for Xojo. It keeps confusing Xojo with Visual Basic. For explaining concepts ChatGPT is excellent.

Both Text and Xojo.Data.GenerateJSON are deprecated. Unfortunately, you have chosen an old example to start from. Actually, anything in the old Xojo.* namespace should be avoided.

Your example is using Dictionary instead of the deprecated Xojo.Core.Dictionary, which is why you’re getting the exception. Dictionary is not compatible with Xojo.Data.GenerateJSON.

Some years ago, Xojo decided to namespace everything under Xojo.*. They also introduced the Text data type. It was largely considered a failed experiment. They rewrote String to incorporate the best of Text and redid the Xojo.* functions under other names. Then they deprecated all of that. Unfortunately, there’s still a lot of code floating about the internet that uses them.

The documentation site documentation.xojo.com is a good resource to investigate your questions, as are the many example projects contained in your xojo install.

1 Like

Look closer.

And at any point in time, how will these AI jobbies know the difference between useful code and code full of deprecated constructs, if the Internet is “full of old code” ??

Yes, don’t use the Text type, use String. I can’t help with JSON as I never use it.

Keep asking questions, though.

Ok I have made some changes to the code. I am now using Var instead of DIm and String instead of Text .

Also Using URLConnection instead of HTTPSocket

Some things are still not working correctly

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

Var request As New URLConnection



request.SetRequestContent("", "application/json")
request.RequestHeader("ApiIntegrationCode", integrationCode)
request.RequestHeader("UserName", apiUsername)
request.RequestHeader("Secret", apiPassword)


If TextField1.Text = "" Or TextField2.Text = "" Or TextField3.Text = "" Or TextField4.Text = "" Or TextField5.Text = "" Or TextField6.Text = "" Then
  MsgBox("Please fill in all fields.")
  Return
End If


Var  requestBody as New JSONItem
requestBody.Value("companyType") = 1
requestBody.Value("ownerResourceID") = 4
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

Var requestBodyJson As String = Xojo.Data.GenerateJSON(requestBody)

request.SetRequestContent(requestBodyJson, "application/json")
request.Post(apiEndpoint, AddressOf HandleResponse)

```Not sure if I am using the RequestHeader Method correctly here,   According to the Docs its valid so not sure if I am doing it wrong again. 

ALso There is no member for POST in URLConnection, what can I use instead of that I tried Send and it did not work 
![CleanShot 2023-04-18 at 20.01.34|537x500](upload://eF0BrTKd0WK1VMHGx0pkJr1vPtG.png)

Am I going about this the correct way

That’s because you’ve looked up the doc for Text. No point in updating that other than to say “This is deprecated, so there!”

Var requestBodyJson As String = Xojo.Data.GenerateJSON(requestBody)

This seems redundant.
You WANT a JSONItem, but Xojo.Data.GenerateJSON makes one from an existing array or dictionary.

Try removing that line, and then use the requestBody directly:

request.SetRequestContent(requestBody, "application/json")

SEND is the right thing to use, the first parameter can contain POST.
Probably like this:

request.send (“POST”,apiEndpoint)

but since you want to handle a response, you probably want to be sending a GET

(I wish I knew where this code originated)

I have mostly made it up with my very limited knowledge some of it was copied from an old VB code I had and then I made it more XOJOified so probably all completely wrong for what I am trying to do.

Basically, all I am trying to do is to take information entered in Text boxes and create a company via a web services API in my CRM.

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

Var request As New URLConnection
request.SetRequestContent("", "application/json")
If TextField1.Text = "" Or TextField2.Text = "" Or TextField3.Text = "" Or TextField4.Text = "" Or TextField5.Text = "" Or TextField6.Text = "" Then
  MsgBox("Please fill in all fields.")
  Return
End If


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

request.SetRequestContent(requestBody, "application/json")

request.send("POST",apiEndpoint)

I give up !!! :-). Still not working

I give up !!! :-). Still not working

I read the docs.

The error message is saying that you are not providing 2 strings.
I have no idea what integrationcode is defined as.

SetRequestContent wants 2 strings.
Your first parameter here is a JSONItem
Maybe try requestbody.ToString

I did read the docs and I thought was giving it 2 strings. which is why I said I give up, This is 2 strings isn’t it?

request.SetRequestContent("", "application/json")
request.RequestHeader("ApiIntegrationCode", integrationCode)
request.RequestHeader("UserName", apiUsername)
request.RequestHeader("Secret", apiPassword)

The integration code is a string
Var integrationCode As String = “abavcac1111”. <— not the real code. Its alphanumeric so I defined it as a string

I am confusing myself . Are these lines the same and is one of them redundant