I keep getting System callout error when updating a contact field for multiple contacts.
System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out
public static List<Id> getId(){
//find a list of contacts with birthdays today
Contact[] c1 = [SELECT Id, email, Birthday__c, Name
FROM Contact
WHERE email <> '' AND
DAY_IN_MONTH(Birthday__C) = :Date.today().day() AND
CALENDAR_MONTH(Birthday__C) = :Date.today().month()];
//add the list of contacts to a list
List<Id> mailToIds = new List<Id>();
for(Contact r : c1) {
//Add contacts that have birthdays to the list
System.debug('recipient' + r.Birthday__c);
mailToIds.add(r.Id); // add to email contact array
}
return mailToIds;
}
public static void updateContact(){
List<Id> idList = new List<Id>();
idList = getId();
GiftLink giftLink = new GiftLink();
Contact queryContact;
for(Id t : idList){
queryContact = [SELECT id, Name, gift_link__c FROM Contact WHERE id = :t];
queryContact.gift_link__c = giftLink.apiCall(queryContact.Name);
update queryContact;
System.debug(queryContact.Name);
}
}