如何将unleashed api与salesforce集成?

时间:2015-06-16 04:27:09

标签: continuous-integration

我需要将UnlashedApi与salesforce集成。我试图打出标注。但是,得到像

这样的错误
  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) {
   }    

这是我的代码段:

data-response-handler="responseHandler"

如何解决问题并获得回复?

1 个答案:

答案 0 :(得分: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() );