Method Community

 

Create Customer & Opportunity

Last post 08-16-2017 8:42 AM by Method_Peter. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 07-31-2017 9:59 AM

    Create Customer & Opportunity

    Hello,

    I've been trying to create a Customer (Lead) via API call and it works OK.

    Followed the guide from https://gist.github.com/relish27/67432c710f4b4904ca6f and adjusted it to use plain PHP SOAP calls (no external libraries).


    Seems to me that all is working OK, but I cannot create Opportunity. One of the errors is: 'CustomerRef is missing...'.

    I understand that I need to use something from customer table but I'm not sure what. After inspecting the Opportunity table the required fields (have starts on them) are:

    // Name > FullName?

    // OpportunityStage > Prospecting

    // Customer ?

    // CloseDate > Jul-25-2017

    // AssignedTo > ?

    After successful customer creation you get the RecordID for Customer. What exactly am I supposed to send in order to create Opportunity with Customer creation?

    Also in video tutorial it says that Web 2 Lead creates Customer, 2x Activities and 1x Opportunity. Can you explain the process for creating Activities as well.


    I will paste code here for reference, I'm working on Magento platform:

    https://pastebin.com/zSh0F6FU - SOAP Call code

    https://pastebin.com/nuSDkSUG - Creating of data fields/values arrays to be sent via SOAP

  • 08-16-2017 7:57 AM In reply to

    Re: Create Customer & Opportunity

    My appologies for being slow to response.  This is an excellent question.  

    The short answer is FullName - you need to include the FullName of the Customer you want to link to the Opportunity.  In a subsequent post I'm going to attempt to explain how you can figure this out.

    Peter Dyer
    Product Manager - Method
  • 08-16-2017 8:42 AM In reply to

    Re: Create Customer & Opportunity

    Let's walk through the process of figuring out what to submit to the API.  

    Step #1 - Identify want we want to create - in this case Opportunity

    Step #2 - Query the field list for Opportunity

    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
    <soap:Header/>
    <soap:Body>
    <tem:MethodAPIFieldListV2>
    <tem:strCompanyAccount>{{account}}</tem:strCompanyAccount>
    <tem:strLogin>{{login}}</tem:strLogin>
    <tem:strPassword>{{password}}</tem:strPassword>
    <tem:strSessionID></tem:strSessionID>
    <tem:strTable>Opportunity</tem:strTable>
    </tem:MethodAPIFieldListV2>
    </soap:Body>
    </soap:Envelope>

    Step #3 - Search field list response for <IsRequired>true</IsRequired>

    For Opportunity we see: AssignedTo, CloseDate, Customer, Name, OpportunityStage .  Note the list of required fields will change over time and will change based on customization.

    Step #3b - If there are required fields I'm not familiar with I will create a record in the UI and query it to see what values I get back.  I'm familar with all of the required fields for Opportunity so I am going to skip that step.

    Step #4 - Identify which of the required fields are references to other tables, and identify what the reference is

    From the required fields, the following are references to other tables: AsssignedTo, Customer, OpportunityStage.  I know this because each of these fields is <DataType>DropDown</DataType>

    If we look at Customer we see the following:

    <Record>
    <SupportsAdd>true</SupportsAdd>
    <SupportsEdit>true</SupportsEdit>
    <IsRequired>true</IsRequired>
    <FieldName>Customer</FieldName>
    <MaxSize>-1</MaxSize>
    <DataType>DropDown</DataType>
    <DropdownFromTable>Customer</DropdownFromTable>
    <DropdownDisplayField>FullName</DropdownDisplayField>
    </Record>

    The <DropdownDisplayField> tells us the reference we need to include in our Insert call.  In most cases I will query the reference table (in this case Customer) to see examples of the reference field (in this case FullName) so that I understand what to include in my Insert call.

    Let's look at a different example - Contacts.  This is not a required field but is often useful to fill in when creating an Opportunity.  It looks like this:

    <Record>
    <SupportsAdd>true</SupportsAdd>
    <SupportsEdit>true</SupportsEdit>
    <IsRequired>false</IsRequired>
    <FieldName>Contacts</FieldName>
    <MaxSize>-1</MaxSize>
    <DataType>DropDown</DataType>
    <DropdownFromTable>Contacts</DropdownFromTable>
    <DropdownDisplayField>RecordID</DropdownDisplayField>
    </Record>

    Note that it is referenced from the Contacts table and the reference is RecordID.  I can query the Contacts table to get the RecordID for the Contact I want to include in the Opportunity.

    Step #5 - I can now create my request to create the Opportunity.  Here it is:

    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/">
    <soap:Header/>
    <soap:Body>
    <tem:MethodAPIInsertV2>
    <tem:strCompanyAccount>{{account}}</tem:strCompanyAccount>
    <tem:strLogin>{{login}}</tem:strLogin>
    <tem:strPassword>{{password}}</tem:strPassword>
    <tem:strSessionID></tem:strSessionID>
    <tem:strTable>Opportunity</tem:strTable>
    <tem:arrInsertFieldsArray>
    <tem:string>Name</tem:string>
    <tem:string>CloseDate</tem:string>
    <tem:string>Customer</tem:string>
    <tem:string>OpportunityStage</tem:string>
    <tem:string>AssignedTo</tem:string>
    <tem:string>Contacts</tem:string>
    </tem:arrInsertFieldsArray>
    <tem:arrInsertValueArray>
    <tem:string>Another oppty 6</tem:string>
    <tem:string>2017-08-31</tem:string>
    <tem:string>Big Company</tem:string>
    <tem:string>Prospecting</tem:string>
    <tem:string>Peter Dyer</tem:string>
    <tem:string>4</tem:string>
    </tem:arrInsertValueArray>
    </tem:MethodAPIInsertV2>
    </soap:Body>
    </soap:Envelope>

    I get a response that looks like this:

    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
    <MethodAPIInsertV2Response xmlns="http://tempuri.org/">
    <MethodAPIInsertV2Result>&lt;?xml version="1.0" encoding="windows-1252" ?>&lt;MethodAPI response = "Success" RecordID="1" >&lt;/MethodAPI></MethodAPIInsertV2Result>
    </MethodAPIInsertV2Response>
    </soap:Body>
    </soap:Envelope>


    Peter Dyer
    Product Manager - Method
Page 1 of 1 (3 items)