# Use SecurityToken in SOAP header

To make API V3 SOAP calls, a SecurityToken is needed in the header of the SOAP message. The SecurityToken can be retrieved via the Login call and can be used for several hours. The access to the different API functions is based on the App integration rights and the subscription settings. The login call authentication is based on the two keys provided by the platform. See: Generating application security keys.

# Example of SOAP Header

This example shows the SOAP Header for the call GetInboxDocumentStatus.

<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP:Header>
        <Authentication xmlns="http://api.everbinding.nl/v3_1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <SecurityToken>o2S1qTusL29hp3IgMKWsn2I5CFV2MwHjAGZ3AmDlAzD3AwIuAGp1Amp2AwD2Lmp1ATH0VvkiLKI0nS9ho25wMG0vZGRlAwR1ZmHkZPVfo2S1qTusqTygMKA0LJ1jCFVkAQp1Awp1AmpkVvkiLKI0nS9mnJqhLKE1pzIsoJI0nT9xCFWVGHSQYIAVDGRvYT9uqKEbK3MypaAco249VwRhZPVfo2S1qTusqT9eMJ49VxMOFmuQqRuTLKImEIqZL2qEA0kZn0SRL1HmHmuuEaIlVvkiLKI0nS9mnJqhLKE1pzH9VaSGn3byZxW3I0yQpzuUIT1krGMVF0uSHTIHoIuEWGARVt==</SecurityToken>
        </Authentication>
    </SOAP:Header>
    <SOAP:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <GetInboxDocumentStatus xmlns="http://api.everbinding.nl/v3_1/">
            <ExternalId>XCNIN95987</ExternalId>
        </GetInboxDocumentStatus>
    </SOAP:Body>
</SOAP:Envelope>

# Example of SOAP Handler in Java

Changing the SOAP Header before sending can be done in java by adding a SOAPHandler to the used Service. This can be done with a HandlerResolver.

public class HeaderHandler implements SOAPHandler<SOAPMessageContext> {
    private String securityToken;
    @Override
    public boolean handleMessage(SOAPMessageContext smc) {
        Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
        if (outboundProperty) {
            SOAPMessage message = smc.getMessage();
            try {
                SOAPEnvelope envelope = smc.getMessage().getSOAPPart().getEnvelope();
                SOAPHeader header = envelope.getHeader();
                header.detachNode();
                header = envelope.addHeader();
                SOAPElement security =
                        header.addChildElement("Authentication", "h", "http://api.everbinding.nl/v3_1/");
                security.addAttribute(new QName("xmlns"), "http://api.everbinding.nl/v3_1/");
                SOAPElement securityTokenElement =
                        security.addChildElement("SecurityToken");
                securityTokenElement.addTextNode(securityToken);
            } catch (SOAPException | DOMException e) {
                e.printStackTrace();
            }
        }
        return outboundProperty;
    }

# Example of SOAPHandler in .net c#

The Class EConnectServiceSoapClient is generated with the WSDL.

class Program
{
    public static EConnectServiceSoapClient client = new EConnectServiceSoapClient();
    
    public static  Authentication GetToken()
    {
        var login = client.Login(new Login()
        {
           ConsumerKey = "",
            ConsumerSecret = ""
        });
        return new Authentication() { SecurityToken = login.SecurityToken };
    }

    static void Main(string[] args)
    {
        var token = GetToken();
        var inboxdocs = client.GetInboxDocuments(token, new GetInboxDocuments()
        {
            EConnectPartyId = "XCNL10019"
        });
    }
}
© 2024 eConnect International B.V.