public class BrevoHandler { static Map results = new Map(); public static void getcontacts(){ HttpRequest req = new HttpRequest(); Http http = new Http(); // GET request to check if the contact exists req.setEndpoint('https://api.brevo.com/v3/contacts/' ); req.setMethod('GET'); req.setHeader('Content-Type', 'application/json'); req.setHeader('api-key', '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'); try { HttpResponse res = http.send(req); if (res.getStatusCode() == 200) { System.debug('Contact Already Exist in Brevo'); results.putAll((Map) JSON.deserializeUntyped(res.getBody())); } } catch(Exception e) { System.debug('API call failed with message: ' + e.getMessage()); } } public static void print(){ BrevoHandler.getcontacts(); System.debug('@@@@@@@'+results.Size()); } public static void createcontact(string email,string firstname,string lastname,string phone){ Brevohandler.getcontacts(); HttpRequest req = new HttpRequest(); Http http = new Http(); req.setEndpoint('https://api.brevo.com/v3/contacts'); req.setMethod('POST'); req.setHeader('Content-Type', 'application/json'); req.setHeader('api-key', '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'); Map brevoContact = new Map(); brevoContact.put('email', email); Map brevoAttributes = new Map(); brevoAttributes.put('FIRSTNAME', firstName); brevoAttributes.put('LASTNAME', lastName); brevoAttributes.put('SMS', phone); brevoContact.put('attributes', brevoAttributes); String brevoBody = JSON.serialize(brevoContact); req.setBody(brevoBody); try { HttpResponse res = http.send(req); if (res.getStatusCode() != 201) { System.debug('Failed to create contact in Brevo with status code: ' + res.getStatusCode()); }else{ System.debug('Created Secussfully:'+brevobody); } } catch(Exception e) { System.debug('API call failed with message: ' + e.getMessage()); } } }