Sub Get_Memento_Lib(LibId As String, oHttpRequest As WinHttpRequest, oConverter As Converter, oRecordset As DAO.Recordset)
Const Token As String = "?token=xxxxxxxxxxx"
Dim JsonObj As Dictionary
Dim oDictionary As Dictionary
Dim oCollection As Collection
Dim oCollection2 As Collection
Dim oHeader As Collection
Dim url As String
Dim i As Long
Dim j As Long
Dim tmpstr As String
Dim FieldName As String
Dim tmpDate As Date
Dim Feld As DAO.Field2
Dim Item As Variant
Dim Item2 As Variant
url = Mementoserver & LibId & Token
Call oHttpRequest.Open("GET", url)
Call oHttpRequest.send
If oHttpRequest.responseText = "" Then
MsgBox "NOk"
Exit Sub
End If
Set JsonObj = oConverter.ParseJson(oHttpRequest.responseText)
If JsonObj.Exists("fields") Then
Set oCollection = JsonObj.Item("fields")
Set oHeader = New Collection
For i = 1 To oCollection.Count
oHeader.Add oCollection(i), CStr(oCollection(i).Item("id"))
Next
Else
MsgBox "NOk"
Exit Sub
End If
url = Mementoserver & LibId & "/entries" & Token & "&fields=all&pageSize=100000"
Call oHttpRequest.Open("GET", url)
Call oHttpRequest.send
If oHttpRequest.responseText = "" Then
MsgBox "NOk"
Exit Sub
End If
Set JsonObj = oConverter.ParseJson(oHttpRequest.responseText)
If JsonObj.Exists("entries") Then
Set oCollection = JsonObj.Item("entries")
For i = 1 To oCollection.Count
If oCollection.Item(i).Item("status") = "active" Then
Set oCollection2 = oCollection(i).Item("fields")
oRecordset.AddNew
oRecordset("ID") = oCollection(i).Item("id")
For j = 1 To oCollection2.Count
Set oDictionary = oHeader.Item(CStr(oCollection2.Item(j).Item("id")))
FieldName = CStr(oDictionary.Item("name"))
On Error Resume Next
Set Feld = Nothing
Set Feld = oRecordset.Fields(FieldName)
If Feld Is Nothing Then
'Debug.Print FieldName
Else
tmpstr = ""
Select Case oDictionary.Item("type")
Case "date"
oRecordset(CStr(oDictionary.Item("name"))) = CDate(Left(oCollection2.Item(j).Item("value"), 10))
Case "entries"
For Each Item In oCollection2.Item(j).Item("value")
If tmpstr = "" Then
tmpstr = """" & Item & """"
Else
tmpstr = tmpstr & ";" & """" & Item & """"
End If
Next
oRecordset(CStr(oDictionary.Item("name"))) = tmpstr
'Case "calc"
Case "file"
Case "js"
tmpstr = oCollection2.Item(j).Item("value")
oRecordset(CStr(oDictionary.Item("name"))) = tmpstr
Case Else
tmpstr = oCollection2.Item(j).Item("value")
oRecordset(CStr(oDictionary.Item("name"))) = oCollection2.Item(j).Item("value")
End Select
End If
Next
oRecordset.Update
End If
Next
End If
Set JsonObj = Nothing
Set oCollection = Nothing
Set oCollection2 = Nothing
End Sub