Integrations and APIs for Service

Get Involved. Join the Conversation.

Topic

    Leonardo Barbosa
    Create Contact with a SOAP
    Topic posted January 30, 2015 by Leonardo BarbosaBronze Medal: 1,250+ Points 
    1786 Views, 13 Comments
    Title:
    Create Contact with a SOAP
    Content:

    Hello all,

    I did a XML to create Contacts in RN

    This is a example of my XML:

                   <ns2:GenericFields dataType="OBJECT" name="c">
                      <ns2:DataValue>
                         <ns2:ObjectValue xsi:type="ns2:GenericObject">
                            <ns2:ObjectType>
                               <ns2:TypeName>ContactCustomFieldsc</ns2:TypeName>
                            </ns2:ObjectType>
                            <ns2:GenericFields dataType="STRING" name="profissao">
                               <ns2:DataValue>
                                  <ns2:StringValue>PROFISSAO</ns2:StringValue>
                               </ns2:DataValue>
                            </ns2:GenericFields>
                         </ns2:ObjectValue>
                      </ns2:DataValue>
                   </ns2:GenericFields>

    It work 
    Now I need set custom fields with type Char and Datetime. How I can do this?

    Someone can help me?

    Regards

     

    Comment

     

    • Vivek Goel

      HI Leonardo,

      Have u generated this xml manually or there is some automatic tool to create the XML SOAP request. I have done the same thing but by calling SOAP web service in .Net Code.

      Thanks,

      Vivek

    • Leonardo Barbosa

      Hey Vivek,

      Thanks for your time, but I really need do this in XML SOAP request. Exists some tool to create it automatic?

      Best regards

    • Charlie Mopps

      Right, due to the "Polymorphic" wsdl Rightnow uses, you're going to have to use Raw XML in a LOT of cases. See if the XML bellow helps at all. It's an excerpt of how we create incidents with custom fields.



      Keep in mind, this WILL break eventually. Since you're not actually consuming the WSDL properly (You likely can't... Most applications out there can't use Rightnows WSDL.) the XML Will not update when Rightnow changes the API and they like to change it quite frequently. I suggest reading up on "Polymorphic" wsdls, and rightnows documentation on it so you can properly support this when it does break. There are not a lot of people out there that know how this works.



       



      If you want them to create a normal WSDL, vote up my "Idea": https://cloudcustomerconnect.oracle.com/posts/3b4809d2e4



      Code:




                      <ns4:CustomFields xmlns:ns2="urn:generic.ws.rightnow.com/v1_2" xsi:type="ns2:GenericObject">



                          <ns2:ObjectType>



                              <ns2:TypeName>IncidentCustomFields</ns2:TypeName>



                          </ns2:ObjectType>



                          <ns2:GenericFields dataType="OBJECT" name="c">



                              <ns2:DataValue>



                                  <ns2:ObjectValue xsi:type="ns2:GenericObject">



                                      <ns2:ObjectType>



                                          <ns2:TypeName>IncidentCustomFieldsc</ns2:TypeName>



                                      </ns2:ObjectType>



                                      <ns2:GenericFields dataType="STRING" name="Name_Of_Custom_Field">



                                          <ns2:DataValue>



                                              <ns2:StringValue>[some custom data for custom field]</ns2:StringValue>



                                          </ns2:DataValue>



                                      </ns2:GenericFields>



                                      <ns2:GenericFields dataType="STRING" name="Name_Of_Custom_Field2">



                                          <ns2:DataValue>



                                              <ns2:StringValue>[some custom data for Custom_Field2]</ns2:StringValue>



                                          </ns2:DataValue>



                                      </ns2:GenericFields>



                                  </ns2:ObjectValue>



                              </ns2:DataValue>



                          </ns2:GenericFields>



                      </ns4:CustomFields>




       

    • Leonardo Barbosa

      Hello Jerry,

      I really appreciated your anwser, but you have some docs or links about "Polymorphic" wsdl Rightnow?

      Your code is very similar to mine and worked, but if I set field with datetime type or field with a Picklist, SOAP show a error like this:

      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
         <soapenv:Header/>
         <soapenv:Body>
            <soapenv:Fault>
               <faultcode>soapenv:Sender</faultcode>
               <faultstring>Missing NamedIDValue for property sexo
      While processing GenericFields[0]: sexo
      While processing GenericField: c
      While processing GenericFields[0]: c
      While processing Contact->CustomFields(rng_v1_2::GenericObject).</faultstring>
               <detail>
                  <n0:RequestErrorFault xmlns:n0="urn:faults.ws.rightnow.com/v1_2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                     <n0:exceptionCode>INVALID_REQUEST</n0:exceptionCode>
                     <n0:exceptionMessage>Missing NamedIDValue for property sexo
      While processing GenericFields[0]: sexo
      While processing GenericField: c
      While processing GenericFields[0]: c
      While processing Contact->CustomFields(rng_v1_2::GenericObject).</n0:exceptionMessage>
                  </n0:RequestErrorFault>
               </detail>
            </soapenv:Fault>
         </soapenv:Body>
      </soapenv:Envelope>

      This a custom field with a picklist and part of code that I used to create is:

                       <ns2:GenericFields dataType="OBJECT" name="c">
                        <ns2:DataValue>
                           <ns2:ObjectValue xsi:type="ns2:GenericObject">
                              <ns2:ObjectType>
                                 <ns2:TypeName>ContactCustomFieldsc</ns2:TypeName>
                              </ns2:ObjectType>
                              <ns2:GenericFields dataType="STRING" name="sexo">
                                 <ns2:DataValue>
                                    <ns2:StringValue>m</ns2:StringValue>
                                 </ns2:DataValue>
                              </ns2:GenericFields>
                           </ns2:ObjectValue>
                        </ns2:DataValue>
                     </ns2:GenericFields>

      Any idea? It happens datetime custom fields too

      Best Regards

       

    • Vikram Kaledhonkar

      Hello Leonardo,

      What client side language are you using? Java or .Net or something else?

      I suggest you read up the sample code for dealing with custom fields here: http://documentation.custhelp.com/euf/assets/devdocs/november2014/Connect_Web_Services_for_SOAP/Content/How%20Do%20I/Custom%20Fields/Set%20a%20Custom%20Field%20Value.htm

      Its important to know the dataType of the field while working with custom fields. Here is the example on how to set datetime field as well as a pick-list (menu or NamedID) field:

      <ns2:GenericFields name="co_time">
          <ns2:DataValue>
                <ns2:DateTimeValue>2015-01-08T15:53:44.000+00:00</ns2:DateTimeValue> 
            </ns2:DataValue>
       </ns2:GenericFields>
       <ns2:GenericFields name="co_menu">
           <ns2:DataValue>
               <ns2:NamedIDValue>
                    <ns1:Name xmlns:ns1="urn:base.ws.rightnow.com/v1_3">West</ns1:Name> 
               </ns2:NamedIDValue>
            </ns2:DataValue>
       </ns2:GenericFields>

      As you can see, depending on the dataType of the field, you would need to set DataValue of that time. In my example above, I have a pick list called 'co_menu' containing four possible choices (East, West, Sound, North).

      Also, you don't *have to work with raw XML*. Enterprise languages have SOAP toolkits that allow you to generate client side bindings that can do XML serialization for you. We have customers using Java as well as .Net.

      Thanks,

      Vikram

       

    • Charlie Mopps

      Leonardo, I'm glad it helped!

      You can read about the WSDL's polymorphic nature in the Connect webservice documentation:
      http://documentation.custhelp.com/euf/assets/devdocs/november2014/Connect_Web_Services_for_SOAP/Default.htm

      Start with the section: Connect Web services>Operational Behavior>Operational Overview>Polymorphic Behavior
      There's quite a bit to go over there...

      Vikram,

      He's not using a programming language. He's trying to use the WSDL "Natively"? Not sure if that's the correct term. What you're talking about are programming languages that have Objects that automatically generate/translate the XML for you. In C# you call the method Create.Contacts.???? etc... and that dynamically creates the XML for you and sends it. Likewise, when Rightnow makes changes to the API, those methods handle those changes on the fly. Where-as Leonardo’s integration here will break until he can update his XML (hence my warning earlier)

      You're talking about "Enterprise languages" that have Soap toolkits... well, that's true for the 2 you support (C# and Java). But in reality most don't work with Rightnows WSDL at all (trust me, I've tried quite a few) And, really, most integrations don't use any language at all. For example, we use Siebel, another Oracle application. You open Siebel, click a few links to create a new integration, drop in the WSDL URL and your credentials in... then you can literally drag and drop fields from Siebel to your integration partner. Ticket# = Incident.ID, etc...

      With Rightnows Polymorphic WSDL, you CANNOT do this. The only way you can get the integration to work is to modify the transaction manually and change the XML by hand like Leonardo is doing here. You have to tell Siebel that, to create an incident, you send this XML… and you put X field into Y variable in that XML string. It’s quite labor intensive. We’ve hundreds of different software packages here, most of them Oracle and Rightnows WSDL doesn’t work with any of them. In every case we’ve had to rig the XML just like Leonardo. For every other application we use, you simply drop in the WSDL, and drag and drop fields to each other in a gui and away it goes.

      Don’t get me wrong, this polymorphic behavior has lots of benefits. It’s just that none of those benefits are used by any application I’ve ever seen. Rightnows chosen a little used WSDL format that has theoretical advantages that are rarely, if ever, used in the real world. I do hope that in the future RightNow sees the light and issues and industry standard xsd:Choice WSDL. You’d have a lot fewer support questions in this forum I’d bet.

       

      To read more on the topic, go here:

      http://www.ibm.com/developerworks/library/ws-tip-xsdchoice/

       

    • Vikram Kaledhonkar

      Hello Jerry,

      I appreciate your thoughts, but,

      1) "Likewise, when Rightnow makes changes to the API, those methods handle those changes on the fly. Where-as Leonardo’s integration here will break until he can update his XML (hence my warning earlier)" this is not true. Regardless of whether you are creating SOAP request XMLs manually vs using SOAP libraries, we continue provide backwards compatibility as long as your don't specifically switch using new version of the APIs. (and keep in mind that we keep enhancing our WSDL in the same API version).

      2) " But in reality most don't work with Rightnows WSDL at all (trust me, I've tried quite a few)" Can you point me to specific SOAP toolkits or libraries? Please be specific. I would be more than happy to fix any gaps we may have in our WSDL. (hint: Siebel is NOT a SOAP toolkit, they may have a way to import WSDL).

      3) Yes, xsd:choice is one of the possible alternatives to design your XML schema, and we do already use xsd:choice elements in our Typed/Enterprise WSDL for Generic Objects that are used for interacting with custom objects (and also in our partner/generic WSDL). So I am not sure what exactly you mean by provide xsd:choice WSDL. The link you provided from ibm developerworks is 10 years old and industry has changed a lot since then (I am not sure about Siebel). As far as our core operations go, decision was made to use polymorphic approach at the time of designing first version of our APIs (around 2010). That approach has enabled us to continually evolve our WSDL under the same API version without breaking backwards compatibility. If there is a better approach, we will surely consider it as part of future enhancements. If you have more suggestions, feel free to reach out to me at vikram.kaledhonkar@oracle.com.

      4) Its unfortunate that Siebel cannot consume our WSDL directly. I will be reaching out to my colleagues at Oracle to determine what the underlying issue is and will work towards fixing those.

      Thanks,

      Vikram

       

    • Leonardo Barbosa

      Hello guys, what's up?

      I really appreciated your answer, but in my case cannot use Java or other languagues. I think the better way is a WSDL like a Siebel too, but is not possible for now.

      I read too about "polymorphic" but is not so clear to me and I don't really think is the better way. 

      Vikram I tried use your example code but I receive error.

      Maybe I can open a SR to Oracle and wait for feedback. Other ideas?

      Best Regards,

    • Allan Schrum

      The polymorphic WSDL is simply subclassing in regular object model. The base class is called RNObject and all other objects of interest derive from RNObject. In terms of the XML Schema we say that these objects "extend" from RNObject. Thus a Contact object extends from RNObject, just as an Organization object extends from RNObject. Since both Contact and Organization (and Incident and custom objects) all extend from RNObject, if you have a method that takes an array of RNObjects, then that method can take any object that extends from RNObject. This allows us to Create a Contact and an Incident within the same request resulting in only one trip to the server. The other approach typically uses a noun-verb method naming concept (e.g. contact_create, incident_update) resulting in a lot of methods being created.

      All toolkits seem to support XML Schema extensions from base objects, so that is typically not an issue. Even writing raw XML by hand is not hard as long as you are careful, just like with any detail-oriented job. Using xsi:type="" to specify which object you want to use (that extends RNObject) allows you to tell the system what it is you are doing.

      This is a sample XML for manipulating a Contact object's custom fields. It is hand-generated XML from one of our unit tests (we use many tools to support our unit testing including hand generated code since many of our customers do exactly that). We use prefixes for the namespaces that make it easy to track what we are using (messages, objects, based, etc.) which helps us keep things straight as well as makes it easy to read. This particular request is using Batch method call (so that several methods can be invoked) but the same object shape is used if you just wanted to call Create or Update. This example also introduces the concept of ChainSourceID and ChainDestinationID to hold the created ID of the Contact for further operations. We call this chaining. The security header has been removed, but otherwise this is a standard request. Will it work on your site? No, probably not, because we had different custom fields defined on our Contact object. But the ideas are here.


          <soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>
              <soapenv:Header xmlns:rnm='urn:messages.ws.rightnow.com/v1_2'>
                  <rnm:ClientInfoHeader>
                      <rnm:AppID>ContactCustomFieldByName.xml</rnm:AppID>
                  </rnm:ClientInfoHeader>
              </soapenv:Header>
              <soapenv:Body>
                  <rnm:Batch
                              xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
                              xmlns:xs='http://www.w3.org/2001/XMLSchema'
                              xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
                              xmlns:rnm='urn:messages.ws.rightnow.com/v1_2'
                              xmlns:rno='urn:objects.ws.rightnow.com/v1_2'
                              xmlns:rng='urn:generic.ws.rightnow.com/v1_2'
                              xmlns:rnb='urn:base.ws.rightnow.com/v1_2'
                              xmlns:rnok='urn:base.ws.rightnow.com/v1_2'>

      <!-- Create a Contact Set the pet_type CustomField to Name=fish!-->
      <rnm:BatchRequestItem>
          <rnm:CreateMsg>
              <rnm:RNObjects xsi:type='rno:Contact'>
                  <rnb:ID xsi:type='rnb:ChainSourceID' variableName='cID' />
                    <rno:CustomFields>
                      <rng:GenericFields name='c'>
                        <rng:DataValue>
                          <rng:ObjectValue>
                              <rng:GenericFields dataType='NAMED_ID' name='pet_type'>
                                  <DataValue xmlns='urn:generic.ws.rightnow.com/v1_2'>
                                      <NamedIDValue>
                                          <rnb:Name xmlns:rnb='urn:base.ws.rightnow.com/v1_2'>fish</rnb:Name>
                                      </NamedIDValue>
                                  </DataValue>
                              </rng:GenericFields>
                          </rng:ObjectValue>
                        </rng:DataValue>
                      </rng:GenericFields>
                    </rno:CustomFields>
              </rnm:RNObjects>
          </rnm:CreateMsg>
      </rnm:BatchRequestItem>

      <!--Get the created contact, pet_type CustomField should have ID=3 and Name=fish!-->
      <rnm:BatchRequestItem>
          <rnm:GetMsg>
              <rnm:RNObjects xsi:type='rno:Contact'>
                  <rnb:ID xsi:type='rnb:ChainDestinationID' variableName='cID' />
                  <rno:CustomFields />
              </rnm:RNObjects>
              <rnm:ProcessingOptions>
                  <rnm:FetchAllNames>true</rnm:FetchAllNames>
              </rnm:ProcessingOptions>
          </rnm:GetMsg>
      </rnm:BatchRequestItem>

      <!-- Update the Contact Set the pet_type CustomField to Name=dog!-->
      <rnm:BatchRequestItem>
          <rnm:UpdateMsg>
              <rnm:RNObjects xsi:type='rno:Contact'>
                  <rnb:ID xsi:type='rnb:ChainDestinationID' variableName='cID' />
                    <rno:CustomFields>
                      <rng:GenericFields name='c'>
                        <rng:DataValue>
                          <rng:ObjectValue>
                              <rng:GenericFields dataType='NAMED_ID' name='pet_type'>
                                  <DataValue xmlns='urn:generic.ws.rightnow.com/v1_2'>
                                      <NamedIDValue>
                                          <rnb:Name xmlns:rnb='urn:base.ws.rightnow.com/v1_2'>dog</rnb:Name>
                                      </NamedIDValue>
                                  </DataValue>
                              </rng:GenericFields>
                          </rng:ObjectValue>
                        </rng:DataValue>
                      </rng:GenericFields>
                    </rno:CustomFields>

              </rnm:RNObjects>
          </rnm:UpdateMsg>
      </rnm:BatchRequestItem>

      <!--Get the updated contact, pet_type CustomField should have ID=1 and Name=dog!-->
      <rnm:BatchRequestItem>
          <rnm:GetMsg>
              <rnm:RNObjects xsi:type='rno:Contact'>
                  <rnb:ID xsi:type='rnb:ChainDestinationID' variableName='cID' />
                  <rno:CustomFields />
              </rnm:RNObjects>
              <rnm:ProcessingOptions>
                  <rnm:FetchAllNames>true</rnm:FetchAllNames>
              </rnm:ProcessingOptions>
          </rnm:GetMsg>
      </rnm:BatchRequestItem>

      <!-- CLEANUP !-->
      <rnm:BatchRequestItem>
          <rnm:DestroyMsg>
              <rnm:RNObjects xsi:type='rno:Contact'>
                  <rnb:ID xsi:type='rnb:ChainDestinationID' variableName='cID' />
              </rnm:RNObjects>
          </rnm:DestroyMsg>
      </rnm:BatchRequestItem>


                  </rnm:Batch>
              </soapenv:Body>
          </soapenv:Envelope>

       

      Regards,

      -Allan

    • Leonardo Barbosa

      Hi guys,

      I really appriciate your anwser but continue with troubles. Please see my code

                     <ns2:GenericFields dataType="OBJECT" name="c">
                        <ns2:DataValue>
                           <ns2:ObjectValue xsi:type="ns2:GenericObject">
                              <ns2:ObjectType>
                                 <ns2:TypeName>ContactCustomFieldsc</ns2:TypeName>
                              </ns2:ObjectType>
                              <ns2:GenericFields dataType="NAMED_ID" name="sexo">
                                 <ns2:DataValue>
                                    <ns2:NamedIDValue>
                                       <ID xmlns="urn:base.ws.rightnow.com/v1_2" id="1" />
                                    </ns2:NamedIDValue>
                                 </ns2:DataValue>
                              </ns2:GenericFields>
                           </ns2:ObjectValue>
                        </ns2:DataValue>
                     </ns2:GenericFields>

      Where name="sexo" is a Menu Custom Field and id="1"  is a Id of value. But when I test my XML the SOAP return a error. See a return:

      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
         <soapenv:Header/>
         <soapenv:Body>
            <soapenv:Fault>
               <faultcode>soapenv:Sender</faultcode>
               <faultstring>Cannot save/update: Contact(ID=0): 
      Internal Error - Pair Error
        Pair Chain: 
       Description: The menu_items record and filter (((menu_items.cf_id = 34)) does not exist for foreign key in pair contact_create=&amp;gt;custom_field=&amp;gt;cf_item = 1 col_name=c$sexo

      While performing create on Contact</faultstring>
               <detail>
                  <n0:RequestErrorFault xmlns:n0="urn:faults.ws.rightnow.com/v1_2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                     <n0:exceptionCode>UNKNOWN_EXCEPTION</n0:exceptionCode>
                     <n0:exceptionMessage>Cannot save/update: Contact(ID=0): 
      Internal Error - Pair Error
        Pair Chain: 
       Description: The menu_items record and filter (((menu_items.cf_id = 34)) does not exist for foreign key in pair contact_create=&amp;gt;custom_field=&amp;gt;cf_item = 1 col_name=c$sexo

      While performing create on Contact</n0:exceptionMessage>
                  </n0:RequestErrorFault>
               </detail>
            </soapenv:Fault>
         </soapenv:Body>
      </soapenv:Envelope>

      I'm really sorry, but I have a single month with an RN solution and I need your help.

      Best Regards

    • Allan Schrum

      The system is telling you that the custom field menu "sexo" is not part of the Contact object. If you start up the Agent Desktop you can (if you have privilege) edit in the Database section "Custom Fields" and see where the custom field "sexo" is assigned.

      Regards,

      -Allan

    • Leonardo Barbosa

      Hello guys,

      I really appreciated the answers and I wanted share the solution about my case. I used this code bellow:

                     <ns2:GenericFields dataType="OBJECT" name="c">
                        <ns2:DataValue>
                           <ns2:ObjectValue xsi:type="ns2:GenericObject">
                              <ns2:ObjectType>
                                 <ns2:TypeName>ContactCustomFieldsc</ns2:TypeName>
                              </ns2:ObjectType>
                              <ns2:GenericFields dataType="NAMED_ID" name="sexo">
                                 <ns2:DataValue>
                                    <ns2:NamedIDValue>
                                       <ID xmlns="urn:base.ws.rightnow.com/v1_2" id="9" />
                                    </ns2:NamedIDValue>
                                 </ns2:DataValue>
                              </ns2:GenericFields>
                           </ns2:ObjectValue>
                        </ns2:DataValue>
                     </ns2:GenericFields>

      Thanks for all,

       

      Best Regards

    • Charlie Mopps

      Great!

      FYI: Rightnow finally relented and there is a new, REST API coming up in this years releases:

      http://docs.oracle.com/cloud/latest/servicecs_gs/CXSVC/

      I've not tested them myself, and don't know how well they'll work but I'm really excited to test them once we upgrade.

       

      Edit: sorry for replying to this old post. For some reason I got an update on this today. I've no idea why.