SQL Server Fatturazione Elettronica Aruba IT: Create Transmission Request List

Back to Index

Creazione richiesta di trasmissione “Comunicazioni Finanziarie” in formato zip.

Documentation: https://fatturazioneelettronica.aruba.it/apidoc/docs.html#_createtransmissionrequestlist

CURL Command

curl -X POST  https://testws.fatturazioneelettronica.aruba.it/services/ClientRequest/CreateTransmissionRequestList?username=Utente&password=Password \
-H 'Accept: application/json' \
-H 'Content-Type: application/json;charset=UTF-8' \
-d '{
  "userName" : "Utente",
  "password" : "Password",
  "userID" : "Utente",
  "comunicationType" : "LI",
  "dataFile" : "dGVzdA=="
}'

SQL Server Example

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @rest int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Rest', @rest OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    --  URL: https://testws.fatturazioneelettronica.aruba.it/services/ClientRequest/CreateTransmissionRequestList?username=Utente&password=Password
    DECLARE @bTls int
    SELECT @bTls = 1
    DECLARE @port int
    SELECT @port = 443
    DECLARE @bAutoReconnect int
    SELECT @bAutoReconnect = 1
    EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'testws.fatturazioneelettronica.aruba.it', @port, @bTls, @bAutoReconnect
    IF @success <> 1
      BEGIN

        EXEC sp_OAGetProperty @rest, 'ConnectFailReason', @iTmp0 OUT
        PRINT 'ConnectFailReason: ' + @iTmp0
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        RETURN
      END

    --  See the Online Tool for Generating JSON Creation Code
    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'userName', 'Utente'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'password', 'Password'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'userID', 'Utente'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'comunicationType', 'LI'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'dataFile', 'dGVzdA=='

    EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Content-Type', 'application/json;charset=UTF-8'
    EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Accept', 'application/json'

    DECLARE @sbRequestBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbRequestBody OUT

    EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbRequestBody
    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @rest, 'FullRequestSb', @success OUT, 'POST', '/services/ClientRequest/CreateTransmissionRequestList?username=Utente&password=Password', @sbRequestBody, @sbResponseBody
    IF @success <> 1
      BEGIN
        EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbRequestBody
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END
    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @respStatusCode OUT
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Status Code = ' + @respStatusCode

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @rest, 'ResponseHeader', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Response Body:'
        EXEC sp_OAMethod @sbResponseBody, 'GetAsString', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @rest
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @sbRequestBody
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END

    DECLARE @jsonResponse int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jsonResponse OUT

    EXEC sp_OAMethod @jsonResponse, 'LoadSb', @success OUT, @sbResponseBody

    --  See the Online Tool for Generating JSON Parse Code
    DECLARE @errorCode nvarchar(4000)

    DECLARE @errorDescription nvarchar(4000)

    DECLARE @requestID nvarchar(4000)

    DECLARE @i int

    DECLARE @count_i int

    DECLARE @fileName nvarchar(4000)

    EXEC sp_OAMethod @jsonResponse, 'StringOf', @errorCode OUT, 'errorCode'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @errorDescription OUT, 'errorDescription'
    EXEC sp_OAMethod @jsonResponse, 'StringOf', @requestID OUT, 'requestID'
    SELECT @i = 0
    EXEC sp_OAMethod @jsonResponse, 'SizeOfArray', @count_i OUT, 'requestIDList'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jsonResponse, 'I', @i
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @fileName OUT, 'requestIDList[i].fileName'
        EXEC sp_OAMethod @jsonResponse, 'StringOf', @requestID OUT, 'requestIDList[i].requestID'
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @rest
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @sbRequestBody
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jsonResponse


END
GO

Sample JSON Response Body

{
  "errorCode": "",
  "errorDescription": "",
  "requestID": "YWWCED5QWHU7AQGL",
  "requestIDList": [
    {
      "fileName": "ITADFSREETDSD_LI_0001.xml",
      "requestID": "4LMW5CCCBLXKS522"
    },
    {
      "fileName": "ITADFSREETDSD_LI_0002.xml",
      "requestID": "62LXGBLXJCDEAX3M"
    },
    {
      "fileName": "ITADFSREETDSD_LI_0003.xml",
      "requestID": "GBJDXIYJSWMRKQBP"
    }
  ]
}