Hi, I am using VBA-Web to pull in some data in a json format via REST.
Which works fine using
I get back a response which I can see in the immediate window such as
I am now trying to get this into a sheet so I can do some work on it but I have hit a brick wall with this.
I tried
Based off another forum thread I found but its throwing the error "Variable not defined" on
I am not sure what I should define item as to get this working, or if this even will work? am I totally off base with what I am trying to achieve?
Thanks for any advice on getting this working.
Which works fine using
Code:
Public Sub PullStaff()Dim Client As New WebClient
Dim Request As New WebRequest
Dim RequestResponse As WebResponse
WebHelpers.EnableLogging = True
Client.BaseUrl = "https://web.site/webservice/rest/server.php"
Request.Method = WebMethod.HttpGet
Request.ResponseFormat = WebFormat.Json
Request.AddQuerystringParam "wsfunction", "core_enrol_get_enrolled_users"
Request.AddQuerystringParam "moodlewsrestformat", "json"
Request.AddQuerystringParam "courseid", "1234"
Request.AddQuerystringParam "wstoken", "111111111111111"
Request.AddHeader "Authorization", "Token ..."
Request.AddQuerystringParam "options[0][name]", "userfields"
Request.AddQuerystringParam "options[0][value]", "id"
Request.AddQuerystringParam "options[1][name]", "userfields"
Request.AddQuerystringParam "options[1][value]", "fullname"
Request.AddQuerystringParam "options[2][name]", "userfields"
Request.AddQuerystringParam "options[2][value]", "email"
Request.AddQuerystringParam "options[3][name]", "userfields"
Request.AddQuerystringParam "options[3][value]", "username"
Set RequestResponse = Client.Execute(Request)
'Debug.Print RequestResponse.Content
End Sub
I get back a response which I can see in the immediate window such as
Code:
<-- Response - 10:30:22
200 OK
Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0
Connection: close
Date: Wed, 05 Dec 2018 10:30:22 GMT
Pragma: no-cache
Content-Length: 874
Content-Type: application/json
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Accept-Ranges: none
Server: Apache/2.2.15 (CentOS)
X-Powered-By: PHP/7.1.11
Access-Control-Allow-Origin: *
[{"id":1234,"username":"abc","fullname":"B Smoke","email":"smoke@website.com"},{"id":1235,"username":"def","fullname":"D Blain","email":"blain@website.com"},
I am now trying to get this into a sheet so I can do some work on it but I have hit a brick wall with this.
I tried
Code:
Dim i As Integer
i = 4
For Each item In RequestResponse
Sheets(1).Cells(i, 1).Value = item("id")
Sheets(1).Cells(i, 2).Value = item("fullname")
Sheets(1).Cells(i, 3).Value = item("email")
Sheets(1).Cells(i, 4).Value = item("username")
i = i + 1
Next
Based off another forum thread I found but its throwing the error "Variable not defined" on
Code:
For Each item In RequestResponse
I am not sure what I should define item as to get this working, or if this even will work? am I totally off base with what I am trying to achieve?
Thanks for any advice on getting this working.