So basically what I am doing here is a double search for some info about a customer. I can do it in a single search, however it will take 5 times the duration of what is supposed to happen here.
First I search by the customer phone number and see the IDs of each of his accounts that are linked to his phone number. Then I initiate another For loop to search each account through another xmlhttprequest to see if he has an active account. The totalCount is used to see how many accounts the user has (how many nested arrays are in the first for loop request). Then the process should keep looping through the accounts of each user and once it finds the first active account then the whole process should return "1" in the corresponding excel adjacent cell.
But I am receiving:
error 9, subscript out of range
.
What should I correct in the For loops architecture?
For x = 1 To NumRows
Dim var As String: var = Cells(ActiveCell.Row, 2)
Dim RowNote As String: RowNote = ActiveCell.Row
Dim http As Object, html As New HTMLDocument, document As Object
Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "GET", "http://controlpanel.zoho/rest/Accounts/criteria/idlist?AccountPhone=" & var, False
http.send
Dim totalCount As Integer, count As Integer
totalCount = ParseJson(http.responseText)("totalCount")
For count = 1 To totalCount 'totalCount can be 1 sometimes
Dim userID As String
userID = ParseJson(http.responseText)("results")(count)("AccountId")
Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "GET", "http://controlpanel.zoho/rest/AccountDetails/" & userID, False
http.send
Dim status As String, jsonDate As Integer
status = ParseJson(http.responseText)("results")(1)("CustomerStatus")
If status = "LIVE_ACTIVE" Then 'can introduce Date condition to see if peolpe activated after a certain date
Sheet3.Cells(RowNote, 3).Value = 1
Else
count = count + 1
End If
Next count
Next x
End Sub
EDIT: This is a sample of the first JSON array for the first For loop:
URL e.g. http://controlpanel.zoho/rest/Accounts/criteria/idlist?AccountPhone=67545678
and the JSON:
{"totalCount":4,
"messages":[],
"results":[
{"Type":"FX","AccountId":14237},
{"Type":"FX","AccountId":17152},
{"Type":"FX","AccountId":17553},
{"Type":"FX","AccountId":17553}
],
"resultClass":"com.zoho.dao.dto.zohoAccountMarketTypeDTO"}
and this is a sample of the individual second JSON in the second For loop:
URL 2 e.g. http://controlpanel.zoho/rest/AccountDetails/17152
{"totalCount":1,
"messages":[],
"results":[
{"AccountAgrt":false,
"accountType":"FOLLOWER",
"CustomerId":9069,
"logins":81,
"CustomerStatus":"LIVE_ACTIVE",
"dateLastLogin":1510153414000,
"state":null}
],
"resultClass":"com.zoho.dao.dto.zohoAccountInfoDTO"}
String? it would make more sense for it to be aLong)If count >= totalCount Then Exit For