API Creditsafe

This commit is contained in:
2023-03-29 09:30:45 +02:00
parent 30f380d9af
commit ee2131a5c7
5 changed files with 28 additions and 19 deletions

View File

@@ -75,7 +75,7 @@ Public Class cCreditSafeAPI
Shared Function SendGetRequestWithAuthHeader(url As String, company As Company, method As String, authenticationToken As String) As String
Shared Function SendGetRequestWithAuthHeader(url As String, company As Company, acceptContentType As String, method As String, authenticationToken As String) As String
Try
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
@@ -113,11 +113,8 @@ Public Class cCreditSafeAPI
rest.AddHeader("Content-Type", "application/json")
rest.AddHeader("Authorization", "Bearer " & authenticationToken)
If company IsNot Nothing Then
rest.AddHeader("Accept", "application/vnd.hmrc.1.0+json")
Else
rest.AddHeader("Accept", "application/json+pdf")
End If
rest.AddHeader("Accept", acceptContentType)
Dim responseJson As String = rest.FullRequestNoBody(method, url)
@@ -155,7 +152,7 @@ Public Class cCreditSafeAPI
Dim myUrl As String = API_STRING & "/v1/companies"
Dim company = New Company(conpanyname, vatNo, country)
Dim jsonRespString = SendGetRequestWithAuthHeader(myUrl, company, "GET", token)
Dim jsonRespString = SendGetRequestWithAuthHeader(myUrl, company, "application/json", "GET", token)
'Dim test As String = "{""correlationId"":""9194edd0-1a4a-4520-a332-7306b7c027ca"",""totalSize"":1,""companies"":[{""id"":""AT-X-7256130"",""country"":""AT"",""regNo"":""FN 410356 s"",""vatNo"":[""ATU 68490714""],""safeNo"":""AT05607514"",""name"":""Imex Customs Service GmbH"",""address"":{""simpleValue"":""Autobahngrenze 15, 4975, Suben"",""street"":""Autobahngrenze 15"",""city"":""Suben"",""postCode"":""4975""},""status"":""active"",""officeType"":""headOffice"",""type"":""Ltd"",""dateOfLatestAccounts"":""2021-12-31T00:00:00.000000Z"",""dateOfLatestChange"":""2023-03-03T02:38:30.000Z""}]}"
@@ -188,8 +185,15 @@ Public Class cCreditSafeAPI
Dim index = companies.FindString("address", False)
Dim adressObj As Chilkat.JsonObject = compObj.ObjectOf("address")
Dim dateTime As New Chilkat.CkDateTime
Dim dt As New Chilkat.DtObj
Dim getAsLocal As Boolean = False
success = compObj.DateOf("dateOfLatestChange", dateTime)
Debug.WriteLine(dateTime.GetAsTimestamp(getAsLocal))
'Debug.WriteLine(adressObj.StringOf("simpleValue"))
Debug.WriteLine(compObj.StringOf("id") & " " & compObj.StringOf("phoneNo") & " " & compObj.StringOf("phoneNumbers[0]"))
'Debug.WriteLine(compObj.StringOf("id") & " " & compObj.StringOf("phoneNo") & " " & compObj.StringOf("phoneNumbers[0]"))
Dim R As DataRow = dataTable.NewRow
R("id") = compObj.StringOf("id")
@@ -202,7 +206,7 @@ Public Class cCreditSafeAPI
R("city") = adressObj.StringOf("city")
R("postCode") = adressObj.StringOf("postCode")
R("status") = compObj.StringOf("status")
R("dateOfLatestChange") = compObj.StringOf("dateOfLatestChange")
R("dateOfLatestChange") = dateTime.GetAsTimestamp(getAsLocal)
R("phoneNo") = compObj.StringOf("phoneNumbers[0]")
dataTable.Rows.Add(R)
@@ -214,9 +218,13 @@ Public Class cCreditSafeAPI
End Function
Shared Function companyCreditreport(id As String) As String
Shared Function companyCreditreport(id As String, Optional withPDF As Boolean = False) As String
Dim myUrl As String = API_STRING & "/v1/companies/" & id
Dim jsonRespString = SendGetRequestWithAuthHeader(myUrl, Nothing, "GET", token)
Dim acceptContentType = "application/json"
If withPDF Then
acceptContentType &= "+pdf"
End If
Dim jsonRespString = SendGetRequestWithAuthHeader(myUrl, Nothing, acceptContentType, "GET", token)
Dim json As New Chilkat.JsonObject
Dim success As Boolean = json.Load(jsonRespString)