Search code examples
mulenetsuitesuitetalk

Linking a Contact to a Customer using the SOAP API


I’m having an issue with linking a customer object to a pre-existing contact when creating a new customer within the SOAP/SuiteTalk API using the Mulesoft middleware.

I’m successfully creating the contact object earlier, and then trying to use that internal ID to link that contact object to the newly created customer object. The relevant part I’m posting within the customer object (just hardcoding the internal ID in order to get it running):

contactRolesList:
    {
        contactRoles: 
            [
                {
                    contact: {
                        "type": "CONTACT",
                        internalId: '74335',
                    },
                    role: {
                        "type": "CONTACT_ROLE",
                        internalId: ‘-10’,
                    }   
                }
            ]
    }

When I attempt to upsert the customer object this way, I don’t get any errors in the integration role execution log, but the contact is never linked. If I try to upsert a second time, I get an error with the format: Unable to find a matching line for sublist contactroles with key: [contact] and value: [74335]. even though a contact object with that internal ID clearly exists.

Am I going about this entirely the wrong way, or am I just narrowly missing the syntax here?

*As a side note, is it possible to set the relationship on a RecordRef using just the external ID? As in, using just the external ID of the contact object in question to reference it and create the link?

Thank you.


Solution

  • The "contactRolesList" field is only for updating contacts already connected to the customer. In order to link a contact with a customer you need to perform an attach operation.

    I'm not experienced with the Mulesoft middleware you mention, but in a soap request it would look like this:

    <attach xmlns="urn:messages_2017_1.platform.webservices.netsuite.com">
     <attachReferece xsi:type="ns1:AttachContactReference"
         xmlns:ns1="urn:core_2017_1.platform.webservices.netsuite.com">
         <ns1:attachTo internalId="176" type="customer" xsi:type="ns1:RecordRef">
             </ns1:attachTo>
          <ns1:contact internalId="1467" xsi:type="ns1:RecordRef"/>
            <ns1:contactRole internalId="-10" xsi:type="ns1:RecordRef">
             </ns1:contactRole>
      </attachReferece>
    </attach>
    

    You can get additional information in your netsuite CRM's help center at: SuiteCloud Platform/ SuiteTalk Web Services /SuiteTalk SOAP Web Services Platform Guide /SOAP Web Services Operations attach - detach