Delphi ActiveX Fatturazione Elettronica Aruba IT: Create Transmission Request

Back to Index

Creazione di una nuova richiesta per la trasmissione di tipo “Comunicazioni Finanziarie” (invio richiesta file singolo).

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

CURL Command

curl -X POST  https://testws.fatturazioneelettronica.aruba.it/services/ClientRequest/CreateTransmissionRequest?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=="
}'

Delphi ActiveX Example

var
rest: TChilkatRest;
success: Integer;
bTls: Integer;
port: Integer;
bAutoReconnect: Integer;
json: TChilkatJsonObject;
sbRequestBody: TChilkatStringBuilder;
sbResponseBody: TChilkatStringBuilder;
respStatusCode: Integer;
jsonResponse: TChilkatJsonObject;
errorCode: WideString;
errorDescription: WideString;
requestID: WideString;

begin
rest := TChilkatRest.Create(Self);

//  URL: https://testws.fatturazioneelettronica.aruba.it/services/ClientRequest/CreateTransmissionRequest?username=Utente&password=Password
bTls := 1;
port := 443;
bAutoReconnect := 1;
success := rest.Connect('testws.fatturazioneelettronica.aruba.it',port,bTls,bAutoReconnect);
if (success <> 1) then
  begin
    Memo1.Lines.Add('ConnectFailReason: ' + IntToStr(rest.ConnectFailReason));
    Memo1.Lines.Add(rest.LastErrorText);
    Exit;
  end;

//  See the Online Tool for Generating JSON Creation Code
json := TChilkatJsonObject.Create(Self);
json.UpdateString('userName','Utente');
json.UpdateString('password','Password');
json.UpdateString('userID','Utente');
json.UpdateString('comunicationType','LI');
json.UpdateString('dataFile','dGVzdA==');

rest.AddHeader('Content-Type','application/json;charset=UTF-8');
rest.AddHeader('Accept','application/json');

sbRequestBody := TChilkatStringBuilder.Create(Self);
json.EmitSb(sbRequestBody.ControlInterface);
sbResponseBody := TChilkatStringBuilder.Create(Self);
success := rest.FullRequestSb('POST','/services/ClientRequest/CreateTransmissionRequest?username=Utente&password=Password',sbRequestBody.ControlInterface,sbResponseBody.ControlInterface);
if (success <> 1) then
  begin
    Memo1.Lines.Add(rest.LastErrorText);
    Exit;
  end;
respStatusCode := rest.ResponseStatusCode;
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(rest.ResponseHeader);
    Memo1.Lines.Add('Response Body:');
    Memo1.Lines.Add(sbResponseBody.GetAsString());
    Exit;
  end;

jsonResponse := TChilkatJsonObject.Create(Self);
jsonResponse.LoadSb(sbResponseBody.ControlInterface);

//  See the Online Tool for Generating JSON Parse Code

errorCode := jsonResponse.StringOf('errorCode');
errorDescription := jsonResponse.StringOf('errorDescription');
requestID := jsonResponse.StringOf('requestID');

Sample JSON Response Body

{
  "errorCode": "",
  "errorDescription": "",
  "requestID": "XADI41PJUFSD3ZA7"
}