function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ivan WinzerIvan Winzer 

GET/POST method oauth in trigger/class

So i have setup a oAuth connected app in my dev box and trying to follow all the steps, i even am working in POSTMAN and got it to connect using the key and tokens provided by magento but when i try to run it thru the debug in salesforce it says that "the nonce is already being used by the consumer with ID %1","paramerters":[114]

I already have triggers and classes in place for updating and creation of a customer but 1. cant figure out how to get my oauth to work in debug, and 2. where do i add this into my code to make the get / post calls to magneto. Hopefully someone has dont this before and can help me out.

This is the POSTMAN code i got to work how do i get it to work in salesforce:
POST /rest/V1/hall/salesforce/customer/sync HTTP/1.1
Host: hallwinesm2-uat.smarterspecies.com
Content-Type: application/json
Authorization: OAuth oauth_consumer_key="c3hhpk8hwwhj43cq1kmghueuurfyl5wu",oauth_token="i4xg6hropwhb6grq7xex7u0o22v79vst",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1530801906",oauth_nonce="07QbX9VZBuH",oauth_version="1.0",oauth_signature="YVNZ4Sy0nreV0REXdM5gEK6XPlk%3D"
Cache-Control: no-cache
Postman-Token: 9d0ff9ce-c958-4152-beda-da435d19505d

{
    "customer": {
        "firstname": "Maciej", 
        "lastname": "Garycki", 
        "email": "mgarycki+sf5333@gorillagroup.com", 
        "telephone": "6924609876", 
        "contact_sf_id": "1234567890", 
        "sfdc_updated_at": "182736", 
        "rms_account_no": "12345", 
        "customer_group_code": "GENERAL", 
        "revel_id": "", 
        "website_id": "1", 
        "store_id": "1", 
        "uuid": "", 
        "addresses": []
    }
}

And this is my class that i need to get this added into:
 
public with sharing class DuplicateEmailFilter {


    public void createDefaultEmail(List<Contact> contacts){
        /*
        List<Contact> contactsToUpdate = new List<Contact>();
        for(Contact contact : contacts){
            if(contact.email==null){
                contactsToUpdate.add(new Contact(id=contact.id, email='RMS'+contact.Unique_Contact_Number__c+'@hallwines.noemail.com'));
            }
        }
        
        if(contactsToUpdate.size()>0){
            update contactsToUpdate;
        }
        */
    }
    
    public void processContacts(List<Contact> contacts, Map<Id,Contact> oldMap){
        List<Contact> dupes = new List<Contact>();
        Map<String, Contact> unique = new Map<String,Contact>();
        Set<Id> ids = new Set<Id>();
        
        List<Contact> contactsToUpdate = new List<Contact>();
        List<Task> tasksToCreate = new List<Task>();
        
        for(Contact contact : contacts){
            Contact old = oldMap.get(contact.id);
            if(old == null || old.email != contact.email){
                if(contact.email != null){
                    if(unique.containsKey(contact.email)){
                        dupes.add(contact);
                    }
                    else{
                        unique.put(contact.email,contact);
                    }
                    ids.add(contact.id);
                }
            }
        }
        
        Map<String, Contact> contactsByEmail = new Map<String, Contact>();
        
        for(Contact c : [select id,email,FirstName,LastName from Contact where Do_Not_Sync_with_Ecommerce__c = false and email in :unique.keySet() and id not in :ids]){
           contactsByEmail.put(c.Email, c);
        }  
        
        for(String e : unique.keySet()){
            Contact c = unique.get(e);
            Contact existing = contactsByEmail.get(c.email);
            if(existing!=null && existing.id != c.id){
                dupes.add(c);
            }
        }
        
        for(Contact c : dupes){
            Contact existing = contactsByEmail.get(c.email);
            if(existing == null){
               existing = unique.get(c.email);
            }
            if(IntegrationUtils.isIntegrationUser()){
                contactsToUpdate.add(new Contact(Id=c.id,Do_Not_Sync_With_Ecommerce__c = true));
                tasksToCreate.add(createTask(c, existing));
            }
            else{
                c.addError(getDuplicateMessage(existing));
            }
        }
        
        if(contactsToUpdate.size()>0){
            update contactsToUpdate;
        }
        if(tasksToCreate.size() > 0){
            insert tasksToCreate;
        }
    }
    
    private Task createTask(Contact c,Contact old){
        Task t = new Task(WhoId = c.id, Subject = 'Duplicate Contact',Description=getDuplicateMessage(old));
        return t;
    }
    
    public String getDuplicateMessage(Contact old){
        String link = '<a href="/'+ old.id +'">'+ old.FirstName+' '+old.LastName + '</a>';
        String message = 'Duplicate Contact '+link+' already exists with Email Address '+old.email;
        return message;
    }
    
    @IsTest
    public static void testNoEmail(){
        /*
        User u = new User(id = UserInfo.getUserId(), Integration_User__c = false);
        update u;
        
        Contact c = new Contact(LastName = 'Smith');
        insert c;
        c = [select id, Email, Unique_Contact_Number__c from Contact where id =: c.id];
        System.assertEquals('rms'+c.Unique_Contact_Number__c+'@hallwines.noemail.com',c.email);
        
        u.Integration_User__c = true;
        update u;
        
        c = new Contact(LastName = 'Smith');
        insert c;
        c = [select id, Email, Unique_Contact_Number__c from Contact where id =: c.id];
        System.assertEquals('rms'+c.Unique_Contact_Number__c+'@hallwines.noemail.com',c.email);
        */
    }
    
    
    
    @IsTest
    public static void testIntegrationDuplicateEmail(){
        User u = new User(id = UserInfo.getUserId(), Integration_User__c = true);
        update u;
        
        Contact c = new Contact(LastName = 'Smith',email='test@example.com');
        insert c;
        Contact c2 = new Contact(LastName = 'Smith',email='test@example.com');
        insert c2;
               
        
        c2 = [select id, Email, Do_Not_Sync_With_Ecommerce__c,(select id from Tasks) from Contact where id =: c2.id];
        System.assertEquals(true, c2.Do_Not_Sync_With_Ecommerce__c);
        System.assertEquals(1,c2.tasks.size());
    }
       
    
    @IsTest
    public static void testNotIntegrationDuplicateEmail(){
        User u = new User(id = UserInfo.getUserId(), Integration_User__c = false);
        update u;
        
        Contact c = new Contact(LastName = 'Smith',email='test@example.com');
        insert c;
        
        String msg = '';
        
        try{
            Contact c2 = new Contact(LastName = 'Smith',email='test@example.com');
            insert c2;
        }
        catch(Exception ex){
            msg = ex.getMessage();
        }
        System.assert(msg.contains('Duplicate Contact'));
    }
    
}

I really hope someone can help me out im in a time crunch to get this to work.

Ivan