ATEZ API: NCTS-TR, Tariff: TELOTEC-API

This commit is contained in:
2024-12-10 10:53:38 +01:00
parent f83bc4c417
commit c5dec0266a
18 changed files with 824 additions and 1506 deletions

View File

@@ -0,0 +1,227 @@
{
"$schema": "http://json-schema.org/draft-06/schema#",
"$ref": "#/definitions/Welcome6",
"definitions": {
"Welcome6": {
"type": "object",
"additionalProperties": false,
"properties": {
"content": {
"type": "array",
"items": {
"$ref": "#/definitions/Content"
}
},
"pageable": {
"$ref": "#/definitions/Pageable"
},
"totalPages": {
"type": "integer"
},
"totalElements": {
"type": "integer"
},
"last": {
"type": "boolean"
},
"number": {
"type": "integer"
},
"size": {
"type": "integer"
},
"numberOfElements": {
"type": "integer"
},
"sort": {
"$ref": "#/definitions/Sort"
},
"first": {
"type": "boolean"
},
"empty": {
"type": "boolean"
}
},
"required": [
"content",
"empty",
"first",
"last",
"number",
"numberOfElements",
"pageable",
"size",
"sort",
"totalElements",
"totalPages"
],
"title": "Welcome6"
},
"Content": {
"type": "object",
"additionalProperties": false,
"properties": {
"guaranteeAmountCurrency": {
"$ref": "#/definitions/GuaranteeAmountCurrency"
},
"guaranteeAmount": {
"type": "number"
},
"guaranteeUsageStatus": {
"$ref": "#/definitions/GuaranteeUsageStatus"
},
"lrnDate": {
"anyOf": [
{
"type": "string",
"format": "date-time"
},
{
"type": "null"
}
]
},
"grn": {
"type": "string"
},
"id": {
"type": "string",
"format": "uuid"
},
"lrn": {
"type": "string"
},
"mrnDate": {
"anyOf": [
{
"type": "string",
"format": "date-time"
},
{
"type": "null"
}
]
},
"mrn": {
"type": "string"
},
"status": {
"$ref": "#/definitions/Status"
},
"trailer": {
"type": "string"
},
"tractor": {
"anyOf": [
{
"type": "null"
},
{
"type": "string"
}
]
}
},
"required": [
"grn",
"guaranteeAmount",
"guaranteeAmountCurrency",
"guaranteeUsageStatus",
"id",
"lrn",
"lrnDate",
"mrn",
"mrnDate",
"status",
"tractor",
"trailer"
],
"title": "Content"
},
"Pageable": {
"type": "object",
"additionalProperties": false,
"properties": {
"pageNumber": {
"type": "integer"
},
"pageSize": {
"type": "integer"
},
"sort": {
"$ref": "#/definitions/Sort"
},
"offset": {
"type": "integer"
},
"paged": {
"type": "boolean"
},
"unpaged": {
"type": "boolean"
}
},
"required": [
"offset",
"pageNumber",
"pageSize",
"paged",
"sort",
"unpaged"
],
"title": "Pageable"
},
"Sort": {
"type": "object",
"additionalProperties": false,
"properties": {
"sorted": {
"type": "boolean"
},
"empty": {
"type": "boolean"
},
"unsorted": {
"type": "boolean"
}
},
"required": [
"empty",
"sorted",
"unsorted"
],
"title": "Sort"
},
"GuaranteeAmountCurrency": {
"type": "string",
"enum": [
"TRY",
"EUR"
],
"title": "GuaranteeAmountCurrency"
},
"GuaranteeUsageStatus": {
"type": "string",
"enum": [
"IN_USE",
"RELEASED"
],
"title": "GuaranteeUsageStatus"
},
"Status": {
"type": "string",
"enum": [
"CTRINFDEP",
"CC007C",
"CTR_DEC",
"WRT_NOT",
"ARR_ADV",
"TRANSIT_CLOSE",
"GUAINF",
"MRN_NOTIFIED"
],
"title": "Status"
}
}
}

View File

@@ -0,0 +1,86 @@
<?xml version="1.0"?>
<xsd:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="Welcome6">
<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="unbounded" name="content" type="Content" />
<xsd:element name="pageable" type="Pageable" />
<xsd:element name="totalPages" type="xsd:int" />
<xsd:element name="totalElements" type="xsd:int" />
<xsd:element name="last" type="xsd:boolean" />
<xsd:element name="number" type="xsd:int" />
<xsd:element name="size" type="xsd:int" />
<xsd:element name="numberOfElements" type="xsd:int" />
<xsd:element name="sort" type="Sort" />
<xsd:element name="first" type="xsd:boolean" />
<xsd:element name="empty" type="xsd:boolean" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Content">
<xsd:sequence>
<xsd:element name="guaranteeAmountCurrency" type="GuaranteeAmountCurrency" />
<xsd:element name="guaranteeAmount" type="xsd:double" />
<xsd:element name="guaranteeUsageStatus" type="GuaranteeUsageStatus" />
<xsd:element name="lrnDate" type="xsd:anyType" />
<xsd:element name="grn" type="xsd:string" />
<xsd:element name="id" type="xsd:string" />
<xsd:element name="lrn" type="xsd:string" />
<xsd:element name="mrnDate" type="xsd:anyType" />
<xsd:element name="mrn" type="xsd:string" />
<xsd:element name="status" type="Status" />
<xsd:element name="trailer" type="xsd:string" />
<xsd:element name="tractor" type="xsd:anyType" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Pageable">
<xsd:sequence>
<xsd:element name="pageNumber" type="xsd:int" />
<xsd:element name="pageSize" type="xsd:int" />
<xsd:element name="sort" type="Sort" />
<xsd:element name="offset" type="xsd:int" />
<xsd:element name="paged" type="xsd:boolean" />
<xsd:element name="unpaged" type="xsd:boolean" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Sort">
<xsd:sequence>
<xsd:element name="sorted" type="xsd:boolean" />
<xsd:element name="empty" type="xsd:boolean" />
<xsd:element name="unsorted" type="xsd:boolean" />
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType name="GuaranteeAmountCurrency">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="TRY" />
<xsd:enumeration value="EUR" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="GuaranteeUsageStatus">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="IN_USE" />
<xsd:enumeration value="RELEASED" />
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="Status">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="CTRINFDEP" />
<xsd:enumeration value="CC007C" />
<xsd:enumeration value="CTR_DEC" />
<xsd:enumeration value="WRT_NOT" />
<xsd:enumeration value="ARR_ADV" />
<xsd:enumeration value="TRANSIT_CLOSE" />
<xsd:enumeration value="GUAINF" />
<xsd:enumeration value="MRN_NOTIFIED" />
</xsd:restriction>
</xsd:simpleType>
<xsd:element minOccurs="0" maxOccurs="unbounded" name="content" type="Content" />
<xsd:element name="pageable" type="Pageable" />
<xsd:element name="totalPages" type="xsd:int" />
<xsd:element name="totalElements" type="xsd:int" />
<xsd:element name="last" type="xsd:boolean" />
<xsd:element name="number" type="xsd:int" />
<xsd:element name="size" type="xsd:int" />
<xsd:element name="numberOfElements" type="xsd:int" />
<xsd:element name="sort" type="Sort" />
<xsd:element name="first" type="xsd:boolean" />
<xsd:element name="empty" type="xsd:boolean" />
</xsd:schema>

View File

@@ -0,0 +1,62 @@
Public Class cATEZ_ncts_api
Shared API_KEY = "2a6fe6bf-6547-4d56-b14a-8a18f94f9e94"
Public Shared Sub query_declarations(startDate As Date, endDate As Date)
' This example assumes the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.
Dim http As New Chilkat.Http
Dim success As Boolean
Dim queryParams As New Chilkat.JsonObject
queryParams.UpdateString("startDate", startDate.ToString("yyyy-MM-ddTHH:mm:ss"))
queryParams.UpdateString("endDate", endDate.ToString("yyyy-MM-ddTHH:mm:ss"))
queryParams.UpdateInt("page", 0)
queryParams.UpdateInt("size", 10000)
http.SetRequestHeader("API-KEY", API_KEY)
Dim resp As Chilkat.HttpResponse = http.QuickRequestParams("GET", "https://transcode.singlewindow.io/api/tds/integrations/verag/declarations", queryParams)
If (http.LastMethodSuccess = False) Then
Debug.WriteLine(http.LastErrorText)
Exit Sub
End If
Debug.WriteLine(resp.StatusCode)
Debug.WriteLine(resp.BodyStr)
'Dim SS = VERAG_PROG_ALLGEMEIN.cNCTS_ATEZ_query_declaration_response.root.LoadFromFile("")
'For Each c In SS.properties.content
'Next
End Sub
Public Shared Sub get_ie015_xml_by_mrn(MRN As String)
' This example assumes the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.
Dim http As New Chilkat.Http
Dim success As Boolean
'http.SetRequestHeader("API-KEY", "{{API-KEY}}")
http.SetRequestHeader("API-KEY", API_KEY)
Dim sbResponseBody As New Chilkat.StringBuilder
success = http.QuickGetSb("https://transcode.singlewindow.io/api/tds/integrations/verag/declarations/messages/ie015-by-mrn/" & MRN, sbResponseBody)
If (success = False) Then
Debug.WriteLine(http.LastErrorText)
Exit Sub
End If
Debug.WriteLine("Response status code = " & http.LastStatus)
Debug.WriteLine(sbResponseBody.GetAsString())
End Sub
End Class

View File

@@ -0,0 +1,102 @@
Imports System.Text.RegularExpressions
Imports Newtonsoft.Json
Public Class cATEZ_Tariff
' Klasse zur Darstellung der Ergebnisse
Public Class cATEZ_TariffItem
Public Property Id As Integer
Public Property CommodityCode As String
Public Property Description As String
Public Property HeadingId As Integer
Public Property LanguageCode As String
Public Property Type As String
End Class
Public Shared Function GetTariffInfo_SingleOrEmpty(searchText As String, Optional countryCode As String = "DE", Optional languageCode As String = "DE", Optional measureType As String = "import", Optional ByRef result As List(Of cATEZ_TariffItem) = Nothing) As String
If GetTariffInfo(searchText, countryCode, languageCode, measureType, result) = "OK" Then
If result.Count > 1 Then
Return ""
Else
Return result(0).CommodityCode
End If
Else
Return ""
End If
End Function
Public Shared Function GetTariffInfo(searchText As String, Optional countryCode As String = "DE", Optional languageCode As String = "DE", Optional measureType As String = "import", Optional ByRef result As List(Of cATEZ_TariffItem) = Nothing) As String
If searchText = String.Empty Then Return "Error: Empty search String"
searchText = Regex.Replace(searchText, "[^\d]", "")
If searchText.Length > 8 Then searchText = searchText.Substring(0, 8)
' Chilkat HTTP-Objekt erstellen
Dim http As New Chilkat.Http()
' API-URL und Parameter definieren
Dim baseUrl As String = "https://tariff.singlewindow.io/api/v2-0/tariff-query/public/commodity-codes"
'Dim countryCode As String = "DE"
'Dim languageCode As String = "DE"
'Dim measureType As String = "import"
' Anfrage-URL mit Parametern erstellen
Dim url As String = $"{baseUrl}?countryCode={countryCode}&searchText={searchText}&languageCode={languageCode}&measureType={measureType}"
' HTTP-GET-Anfrage senden
Dim response As String = http.QuickGetStr(url)
' Fehlerüberprüfung
If http.LastMethodSuccess = False Then
Return $"Error: {http.LastErrorText}"
End If
' Statuscode überprüfen
Dim statusCode As Integer = http.LastStatus
If statusCode <> 200 Then
Return $"Error: HTTP Status {statusCode}"
End If
result = ProcessApiResponse(response)
' Antwort zurückgeben
If result.Count = 0 Then
Return "Error: 0 results"
End If
Return "OK"
End Function
Private Shared Function ProcessApiResponse(jsonResponse As String) As List(Of cATEZ_TariffItem)
' Deserialisiere die JSON-Antwort in eine Liste von Objekten
Dim items As List(Of Dictionary(Of String, Object)) = JsonConvert.DeserializeObject(Of List(Of Dictionary(Of String, Object)))(jsonResponse)
' Liste für deklarierbare Elemente erstellen
Dim declarableItems As New List(Of cATEZ_TariffItem)()
' Ergebnisse durchlaufen
For Each item As Dictionary(Of String, Object) In items
If item.ContainsKey("declarable") AndAlso CBool(item("declarable")) = True Then
Dim tariffItem As New cATEZ_TariffItem() With {
.Id = CInt(item("id")),
.CommodityCode = item("commodity_code").ToString(),
.Description = item("description").ToString(),
.HeadingId = CInt(item("heading_id")),
.LanguageCode = item("language_code").ToString(),
.Type = item("type").ToString()
}
declarableItems.Add(tariffItem)
End If
Next
Return declarableItems
End Function
Sub Example()
' Beispielaufruf der Funktion
Dim searchText As String = "6207220000"
Dim result As String = GetTariffInfo(searchText)
' Ergebnis ausgeben
Console.WriteLine(result)
End Sub
End Class