Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public with sharing class AccountToFACustomer{
- public class Response {
- public integer code {get; set;}
- public String body {get; set;}
- public boolean success {get; set;}
- public Response (integer code, String body){
- this.code = code;
- this.body = body;
- this.success = (code == 200 || code == 201);
- }
- }
- public class CustomerResponse{
- public string uuid {get; set;}
- public string link {get; set;}
- public string location {get; set;}
- }
- public Response CreateCustomer(){
- Response resp;
- string endpoint = 'https://apistaging.website.net/customer/';
- string token = 'Token XXXXXXX';
- string method = 'POST';
- HttpRequest req = new HttpRequest();
- HttpResponse res = new HttpResponse();
- Http h = new http();
- req.setEndpoint(endpoint);
- req.setMethod(method);
- req.setHeader('Authorization', token);
- req.setHeader('Content-Type', 'application/json');
- req.setHeader('Accept-Type', 'application/json');
- req.setBody(
- '{"name":"'+ Account.Name +'",' +
- '"email":"'+ Account.Email__c + '",'+
- '"phone":"'+ Account.Phone +'",'+
- '"website":"'+ Account.Website +'",'+
- '"location":{'+
- '"name":"Account No: '+ Account.Sage_ID__c +'",'+
- '"streetName":"'+ Account.BillingStreet +'",'+
- '"locality":"'+ Account.BillingCity +'",'+
- '"postcode":"'+ Account.BillingState +'",'+
- '"country":"'+ Account.BillingCountry +'" }}'
- );
- try{
- res = h.send(req);
- resp = new Response(res.getStatusCode(), res.getBody());
- }
- catch(System.CalloutException e) {
- System.debug('Callout error: '+ e);
- return resp;
- }
- return resp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement