The error occurs because DML operations were performed before a callout. To fix this, the callout should be made from an asynchronous method such as one annotated with @future(callout=true), which allows DML operations to be committed separately from the callout. nces: Apex Developer Guide - Making Asynchronous Callouts