create deal_contract crm
Thu Mar 13 2025 13:52:31 GMT+0000 (Coordinated Universal Time)
Saved by @TuckSmith541
void Deal_Creation_From_Trader_Portal() { // >>>>>>>>>-------------------- Contact Creation ---------------------- <<<<<<<<< Email = "TestHassnain@gmail.com"; Phone = "03332425224"; Contact_name = "Hassnain Test"; contactfirstName = if(Contact_name.contains(" "),Contact_name.getPrefix(" "),Contact_name); contactlastName = if(Contact_name.contains(" "),Contact_name.getSuffix(" "),""); //check if conatct exists with the above email api_url = "https://www.zohoapis.com/crm/v2/Contacts/search?criteria=(Email:equals:" + Email + ")"; contactResponse = invokeurl [ url :api_url type :GET connection:"zoho_crm" ]; contactId = ""; if(contactResponse.contains("data") && !contactResponse.get("data").isEmpty()) { contactId = contactResponse.get("data").get(0).get("id"); info "Contact already exists with ID: " + contactId; } else { //creating new contact apiDomain = "https://www.zohoapis.com"; version = "v2"; contact_api_url = apiDomain + "/crm/" + version + "/Contacts"; contactPayload = {"data":{{"Email":Email,"First_Name":contactfirstName,"Last_Name":contactlastName,"Phone":Phone}}}; contact_data_json = contactPayload.toString(); contactCreateResponse = invokeurl [ url :contact_api_url type :POST parameters:contact_data_json connection:"zoho_crm" ]; contactId = contactCreateResponse.get("data").get(0).get("details").get("id"); if(contactCreateResponse.contains("data") && !contactCreateResponse.get("data").isEmpty()) { contactId = contactCreateResponse.get("data").get(0).get("details").get("id"); info "New Contact Created with ID: " + contactId; } else { info "Error: Failed to create Contact."; } } // >>>>>>>>>-------------------- Account Creation ---------------------- <<<<<<<<<< // Account Details // Account_name=buyer_name; Account_name = "ERP Test"; //checking if account with same name exists api_url = "https://www.zohoapis.com/crm/v2/Accounts/search?criteria=(Account_Name:equals:" + Account_name + ")"; accountResponse = invokeurl [ url :api_url type :GET connection:"zoho_crm" ]; accountId = ""; if(accountResponse.contains("data") && !accountResponse.get("data").isEmpty()) { accountId = accountResponse.get("data").get(0).get("id"); info "Account already exist with id: " + accountId; } else { // *Create a new Account* newAccount = Map(); newAccount.put("Account_Name",Account_name); accountPayload = Map(); accountList = List(); accountList.add(newAccount); accountPayload.put("data",accountList); account_data_json = accountPayload.toString(); accountCreateResponse = invokeurl [ url :"https://www.zohoapis.com/crm/v2/Accounts" type :POST parameters:account_data_json connection:"zoho_crm" ]; accountId = ""; accountId = accountCreateResponse.get("data").get(0).get("details").get("id"); if(accountCreateResponse.contains("data") && !accountCreateResponse.get("data").isEmpty()) { accountId = accountCreateResponse.get("data").get(0).get("details").get("id"); info "New Account created with id " + accountId; } else { info "Error: Failed to create Account."; return; } } // >>>>>>>>>-------------------- Account Creation ---------------------- <<<<<<<<<< //Deal info // Deal_Name=Title; // Listing_Status = status; //Status // Deal_Owner = seller_name; // Closing_Date = dealCloseDate; // Deal_Description = product_description; // Acquisition_Cost = addOn;// (amount) // Amount = dealTotal; // Payment_Terms = payment_terms; // Trader_Platform_Link = listingLink Deal_Name = "new Hassnain deal"; Status = "newly created"; Closing_Date = "2025-03-08"; Deal_Description = "just creted this new deal"; Amount = "3500"; // Payment_Terms = ; // Trader_Platform_Link = // Deal_Owner = {"name":"Demo User2","id":"4685069000010160001","email":"user2@demo1.rebiz.com"}; //check if Deal exists deal_name = "New Khizar Business Deal"; api_url = "https://www.zohoapis.com/crm/v2/Deals/search?criteria=(Deal_Name:equals:" + Deal_Name + ")"; accountResponse = invokeurl [ url :api_url type :GET connection:"zoho_crm" ]; if(accountResponse.contains("data") && !accountResponse.get("data").isEmpty()) { accountId = accountResponse.get("data").get(0).get("id"); info "Deal already exist with id: " + accountId; } else { //-------------creating-new-Deal------------------- dealDetails = Map(); dealDetails.put("Deal_Name",Deal_Name); dealDetails.put("Closing_Date",Closing_Date); dealDetails.put("Amount",Amount); //dealDetails.put("Owner",Deal_Owner); dealDetails.put("Account_Name",accountId); dealDetails.put("Contact_Name",contactId); dealPayload = Map(); dealList = List(); dealList.add(dealDetails); dealPayload.put("data",dealList); deal_data_json = dealPayload.toString(); dealResponse = invokeurl [ url :"https://www.zohoapis.com/crm/v2/Deals" type :POST parameters:deal_data_json connection:"zoho_crm" ]; dealId = ""; info "Deal Response" + dealResponse; if(dealResponse.contains("data") && !dealResponse.get("data").isEmpty()) { dealId = dealResponse.get("data").get(0).get("details").get("id"); info " New Deal created with id " + dealId; } else { info "Error: Failed to create Deal."; return; } } }
Comments