0

I am trying to generate a token in Excel VBA to add data to a table on our server.

I am using the following code to generate my token:

Dim tokenHTTP As Object
Set tokenHTTP = CreateObject("MSXML2.ServerXMLHTTP")
Dim tokenJSON As String
tokenJSON = "[{""f"" : ""json"", ""username"" : ""username"", ""password"" : ""password"", ""client"" : ""requestip"", ""expiration"" : 1}]"
Dim tokenURL As String
tokenURL = "https://myserver/arcgis/tokens/generateToken"    
tokenHTTP.Open "POST", tokenURL, False    
tokenHTTP.setRequestHeader "Content-type", "application/json"
tokenHTTP.send (tokenJSON)

The response is a link to the token usage page.

Can anyone help me with this?

3
  • Can you please clarify exactly what your question is? For example, which part of the above code is not working? Jul 11, 2017 at 3:32
  • @StephenLead I believe my json string is incorrect
    – preardon
    Jul 11, 2017 at 8:10
  • 1
    Do you need the double set of quotes? Also, this is a GET not a POST right?
    – enolan
    Jul 11, 2017 at 15:34

2 Answers 2

0

I'm not a VBA user so I can't help with those aspects. But as noted in your comment, your JSON string looks incorrect so you should start there.

There's no need for the [], the quotes around the entire object, or the double-quotes on the parameters. Try something like this:

tokenJSON = {
  "f": "json",
  "username": "username", 
  "password": "password",
  "client": "requestip",
  "expiration": 1
}

(I've put it on separate lines to make it more readable, but the line breaks are not required.)

A tip is to use the site http://json.parser.online.fr/ to validate your JSON - this indicates that the above code is valid:

enter image description here

And as noted in the other comment you may need to check whether this is a GET or a POST.

0

I ended up solving my own question...

The token login parameters must be formatted as a query string:

f=json&username=username&password=password&client=requestip&expiration=1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.