Re: Getting 20014 - Authentication failed error

Anonymous
Not applicable

Getting 20014 - Authentication failed error

Hi Guys,

I just started using Marketo API. Created simple client for accessing leads. I have followed the documentation to create my request. SOAP request is as follows.

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header>
        <ns1:AuthenticationHeader xmlns:ns1="http://www.marketo.com/mktows/">
            <mktowsUserId>
               XXXXXXXXXXXXXX
            </mktowsUserId>
            <requestSignature>
                XXXXXXXXXXXXXX
            </requestSignature>
            <requestTimestamp>
                2013-05-03T14:24:11-08:00
            </requestTimestamp>
        </ns1:AuthenticationHeader>
    </soapenv:Header>
    <soapenv:Body>
        <ns1:paramsGetLead xmlns:ns1="http://www.marketo.com/mktows/">
            <leadKey>
                <keyType>EMAIL</keyType>
                <keyValue>testuser1700@gmail.com</keyValue>
            </leadKey>
        </ns1:paramsGetLead>
    </soapenv:Body>
</soapenv:Envelope>  

The mktowsUserId and URL Endpoint are correct, I have checked it. I am using following code to generate signature

    public static String calculateHMAC(String data, String timeStamp, String key)
    throws java.security.SignatureException
    {
        String result;
        try {
            
            SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), HMAC_SHA1_ALGORITHM);
        
            Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
            mac.init(signingKey);
        
            String signatureData = timeStamp.concat(data);
                        
            byte[] rawHmac = mac.doFinal(signatureData.getBytes());
        
            result = DatatypeConverter.printBase64Binary(rawHmac);            
        
        } catch (Exception e) {
        throw new SignatureException("Failed to generate HMAC : " + e.getMessage());
        }
        return result;
    }

 

I am not sure what is wrong, Could you guys please check my request and signature generation method are correct or not?

Thanks.

 

 

Tags (1)
2 REPLIES 2
Anonymous
Not applicable

Re: Getting 20014 - Authentication failed error

I was able to resolve it. I was doing Base64 encoding, but It requires Hex encoding.

Thanks.

 

Anonymous
Not applicable

Re: Getting 20014 - Authentication failed error

Easier to debug if you send the full src.  You could try the following to see if the request goes through

byte[] rawHmac = mac.doFinal(signatureData.getBytes());
 
// HHMAC bytes as HEX encoded string
char[] hexChars = Hex.encodeHex(rawHmac);
result = new String(hexChars);