Onako na brzinu
Potrebne reference
WinHttpRequest.5.1,
Microsoft Scripting Runtime
Potrebno je preuzeti vba modul JsonConverter.bas sa sajta: [url=]https://github.com/VBA-tools/VBA-JSON[/url]
Code:
Public Function PurchaseInvoiceIds()
Dim http As Object
Dim strUrl As String
strUrl = "https://efaktura.mfin.gov.rs/api/publicApi/purchase-invoice/ids"
Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
With http
.Open "Post", strUrl, False
.setRequestHeader "ApiKey", "tvoj api key"
.setRequestHeader "Content-Type", "*/*"
.Send
If .Status = 200 Then
Dim strOdgovor As String
strOdgovor = http.ResponseText
Debug.Print strOdgovor
Debug.Print JsonConverter.ConvertToJson(strOdgovor, Whitespace:=2)
PurchaseInvoiceIds = JsonConverter.ConvertToJson(strOdgovor, Whitespace:=2)
Else
Debug.Print .Status
PurchaseInvoiceIds = ""
End If
End With
Set http = Nothing
On Error GoTo 0
Exit Function
End Function
Code:
Public Function PurchaseInvoiceById(ByVal IdEfak As LongPtr)
Dim http As Object
Dim strUrl As String
strUrl = "https://efaktura.mfin.gov.rs/a...pi/purchase-invoice?invoiceid=" & IdEfak
Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
With http
.Open "Get", strUrl, False
.setRequestHeader "ApiKey", "tvoj api key"
.setRequestHeader "Content-Type", "*/*"
.Send
If .Status = 200 Then
Dim strOdgovor As String
strOdgovor = http.ResponseText
Debug.Print strOdgovor
Debug.Print JsonConverter.ConvertToJson(strOdgovor, Whitespace:=2)
PurchaseInvoiceById = JsonConverter.ConvertToJson(strOdgovor, Whitespace:=2)
Else
Debug.Print .Status
PurchaseInvoiceById = ""
End If
End With
Set http = Nothing
On Error GoTo 0
Exit Function
End Function
Pozdrav