Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. public with sharing class AccountToFACustomer{
  2.  
  3. public class Response {
  4. public integer code {get; set;}
  5. public String body {get; set;}
  6. public boolean success {get; set;}
  7.  
  8. public Response (integer code, String body){
  9. this.code = code;
  10. this.body = body;
  11. this.success = (code == 200 || code == 201);
  12. }
  13. }
  14.  
  15. public class CustomerResponse{
  16. public string uuid {get; set;}
  17. public string link {get; set;}
  18. public string location {get; set;}
  19. }
  20.  
  21.  
  22. public Response CreateCustomer(){
  23.  
  24. Response resp;
  25.  
  26. string endpoint = 'https://apistaging.website.net/customer/';
  27. string token = 'Token XXXXXXX';
  28. string method = 'POST';
  29.  
  30. HttpRequest req = new HttpRequest();
  31. HttpResponse res = new HttpResponse();
  32. Http h = new http();
  33.  
  34. req.setEndpoint(endpoint);
  35. req.setMethod(method);
  36. req.setHeader('Authorization', token);
  37. req.setHeader('Content-Type', 'application/json');
  38. req.setHeader('Accept-Type', 'application/json');
  39.  
  40.  
  41. req.setBody(
  42. '{"name":"'+ Account.Name +'",' +
  43. '"email":"'+ Account.Email__c + '",'+
  44. '"phone":"'+ Account.Phone +'",'+
  45. '"website":"'+ Account.Website +'",'+
  46. '"location":{'+
  47. '"name":"Account No: '+ Account.Sage_ID__c +'",'+
  48. '"streetName":"'+ Account.BillingStreet +'",'+
  49. '"locality":"'+ Account.BillingCity +'",'+
  50. '"postcode":"'+ Account.BillingState +'",'+
  51. '"country":"'+ Account.BillingCountry +'" }}'
  52. );
  53.  
  54. try{
  55.  
  56. res = h.send(req);
  57. resp = new Response(res.getStatusCode(), res.getBody());
  58. }
  59. catch(System.CalloutException e) {
  60. System.debug('Callout error: '+ e);
  61. return resp;
  62. }
  63. return resp;
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement