2015-06-16 66 views
0

我需要將UnlashedApi與salesforce集成。我正在嘗試製作標註。但是,越來越像如何將解鎖的api與salesforce集成?

09:44:27:938 USER_DEBUG [17]|DEBUG|{"Description":"(403) Forbidden.: Authentication denied - signature mismatch. Username: \u0027 [email protected]\u0027; OrganisationId: \u002757babb16-e109-461d-b993-87b6bd214557\u0027; Signature: \u0027******\u0027; Url: \u0027/Customers/\u0027","DebugInformation":null} 

此錯誤是我的代碼片段:

HttpRequest req = new HttpRequest(); 
    req.setMethod('GET'); 
    req.setHeader('content-type', ' application/json'); 
    req.setHeader('Accept',' application/json '); 
    req.setHeader('api-auth-id','57babb16-e109-461d-b993-87b6bd214557'); 
    req.setHeader('auth-signature-method','HMAC-SHA256'); 
    req.setHeader('api-auth-signature','1SMZNxnb9Tetc7MtDDxgOFUsB8zL2cGl2477ODH5AqEgpRt4N3tljd27omilAbyQGr3PqVPZstYIZKPC503w=='); 
    req.setEndpoint('https://api.unleashedsoftware.com/Customers/'); 
    Http http = new Http(); 
    try { 
     HTTPResponse res = http.send(req); 
     res.getbody(); 
     System.debug(res.toString()); 
     System.debug(res.getbody()); 
     System.debug('STATUS:'+res.getStatus()); 
     System.debug('STATUS_CODE:'+res.getStatusCode()); 

    } catch(System.CalloutException e) { 
    }  

我怎樣才能解決這個問題,得到的迴應?

回答

0
 string ApiId = 'API-ID'; 
     string ApiKey = 'API KEY'; 
     Blob blobSignature = Crypto.generateMac('HMACSHA256', Blob.valueOf(''), Blob.valueOf(ApiKey)); 
     String base64 = EncodingUtil.base64Encode(blobSignature); 
     system.debug('>>>>>>>>> HASH ' + base64); 

     HttpRequest req = new HttpRequest(); 

     req.setEndpoint('https://api.unleashedsoftware.com/Products'); 
     req.setMethod('GET'); 
     req.setHeader('Content-Type', 'application/json'); 
     req.setHeader('Accept','application/json'); 
     req.setHeader('api-auth-id',ApiId); 
     req.setHeader('api-auth-signature',base64); 
     Http http = new Http(); 
     HTTPResponse res = http.send(req); 
     system.debug('>>>>>>>>>>>>>>>> RESOPNSE ' + res.getBody()); 
     system.debug('>>>>>>>>>>>>>>>> STATUS ' + res.getstatus()); 
     system.debug('>>>>>>>>>>>>>>>> STATUSCODE ' + res.getstatuscode());