Jump to content

Webservices da AT - VBA


Recommended Posts

Bom dia,

Gostaria de perguntar se alguém sabe como usar o webservices da AT em VBA, eu teitei usando o seguinte código, mas sem sucesso.

VBA.png

VBA- Code

Sub WebServicesAT()

    Dim ReqSend As String

    Dim XMLHttp As New MSXML2.XMLHttp

    XMLHttp.Open "POST", "https://servicos.portaldasfinancas.gov.pt:701/sgdtws/documentosTransporte", False
    
    ReqSend = "<?xml version=""1.0"" encoding=""utf-8""?><S:Envelope xmlns:S=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/"">"
    ReqSend = ReqSend & "<env:Header>"
    ReqSend = ReqSend & "<wss:Security xmlns:wss=""http://schemas.xmlsoap.org/ws/2002/12/secext"">"
    ReqSend = ReqSend & "<wss:UsernameToken>"
    ReqSend = ReqSend & "<wss:Username>599999993/0037</wss:Username>"
    ReqSend = ReqSend & "<wss:Password>8SRf4It0OLyb8/Zg53ASIg=="
    ReqSend = ReqSend & "</wss:Password>"
    ReqSend = ReqSend & "<wss:Nonce>BAupQbszS3vVWeuYcDVwJIk3eCqYk/Da/YvJEAxN7DW3a90DdTpwEprg1YMsC4y7iI8Re/CEuP8H"
    ReqSend = ReqSend & "6f+1AHtK8OCgMdylaCY60jMt94oEAmyJBs8LMCzRIHHvCY6ZmnJHT+++flujyffySKb+72akR3iV"
    ReqSend = ReqSend & "mPGagRMIY0X4IzLEsQhkXvRO49LpeKNmWNOxmbtDpY1WJKOIa3dkn16GmCFcDRidX6mJISDSSyYS"
    ReqSend = ReqSend & "kewJzoRvD7sXOeqkI/97IBgr4j5YxIy8yo8wbakaTqwy1xQkJXA52GTxDa25uRLsMaDW21JzzNcZ"
    ReqSend = ReqSend & "aDqu0MZH8+j1b8EXqgfBIT0Mkod763y8SjS0Sg=="
    ReqSend = ReqSend & "</wss:Nonce>"
    ReqSend = ReqSend & "<wss:Created>UCq0H5Kf+GNMJSeva2KgzKaP4epqno0M9teeRN0Y49A="
    ReqSend = ReqSend & "</wss:Created>"
    ReqSend = ReqSend & "</wss:UsernameToken>"
    ReqSend = ReqSend & "</wss:Security>"
    ReqSend = ReqSend & "</env:Header>"
    ReqSend = ReqSend & "<S:Body>"
    ReqSend = ReqSend & "<ns0:envioDocumentoTransporteRequestElem xmlns:ns0=""https://servicos.portaldasfinancas.gov.pt/sgdtws/documentosTransporte/"">"
    ReqSend = ReqSend & "<TaxRegistrationNumber>599999993</TaxRegistrationNumber>"
    ReqSend = ReqSend & "<CompanyName>Bladsdsd</CompanyName>"
    ReqSend = ReqSend & "<CompanyAddress>"
    ReqSend = ReqSend & "<Addressdetail>Rua das couves</Addressdetail>"
    ReqSend = ReqSend & "<City>Cidade Empresa</City>"
    ReqSend = ReqSend & "<PostalCode>1000-100</PostalCode>"
    ReqSend = ReqSend & "<Country>PT</Country>"
    ReqSend = ReqSend & "</CompanyAddress>"
    ReqSend = ReqSend & "<DocumentNumber>11</DocumentNumber>"
    ReqSend = ReqSend & "<MovementStatus>N</MovementStatus>"
    ReqSend = ReqSend & "<MovementDate>2022-11-17Z</MovementDate>"
    ReqSend = ReqSend & "<MovementType>GR</MovementType>"
    ReqSend = ReqSend & "<CustomerTaxID>599999993</CustomerTaxID>"
    ReqSend = ReqSend & "<CustomerAddress>"
    ReqSend = ReqSend & "<Addressdetail>Morada Cliente</Addressdetail>"
    ReqSend = ReqSend & "<City>Cidade Cliente</City>"
    ReqSend = ReqSend & "<PostalCode>1000-100</PostalCode>"
    ReqSend = ReqSend & "<Country>PT</Country>"
    ReqSend = ReqSend & "</CustomerAddress>"
    ReqSend = ReqSend & "<AddressTo>"
    ReqSend = ReqSend & "<Addressdetail>Morada Descarga</Addressdetail>"
    ReqSend = ReqSend & "<City>Cidade Descarga</City>"
    ReqSend = ReqSend & "<PostalCode>1000-100</PostalCode>"
    ReqSend = ReqSend & "<Country>PT</Country>"
    ReqSend = ReqSend & "</AddressTo>"
    ReqSend = ReqSend & "<AddressFrom>"
    ReqSend = ReqSend & "<Addressdetail>Morada Carga</Addressdetail>"
    ReqSend = ReqSend & "<City>Cidade Carga</City>"
    ReqSend = ReqSend & "<PostalCode>1000-100</PostalCode>"
    ReqSend = ReqSend & "<Country>PT</Country>"
    ReqSend = ReqSend & "</AddressFrom>"
    ReqSend = ReqSend & "<MovementEndTime>2022-12-17T15:37:17.846Z</MovementEndTime>"
    ReqSend = ReqSend & "<MovementStartTime>2022-12-17T14:37:17.846Z</MovementStartTime>"
    ReqSend = ReqSend & "<VehicleID>10-10-AA</VehicleID>"
    ReqSend = ReqSend & "<Line>"
    ReqSend = ReqSend & "<ProductDescription>Produto1</ProductDescription>"
    ReqSend = ReqSend & "<Quantity>1</Quantity>"
    ReqSend = ReqSend & "<UnitOfMeasure>KG</UnitOfMeasure>"
    ReqSend = ReqSend & "<UnitPrice>1.1</UnitPrice>"
    ReqSend = ReqSend & "</Line>"
    ReqSend = ReqSend & "</ns0:envioDocumentoTransporteRequestElem>"
    ReqSend = ReqSend & "</S:Body>"
    ReqSend = ReqSend & "</S:Envelope>"
    
    XMLHttp.send ReqSend
    MsgBox XMLHttp.responseXML
    
End Sub

 

Obrigado

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.