AddTerms web service - anyone got it to work?

May 28, 2012 at 9:24 AM
Edited May 28, 2012 at 9:26 AM

Does anyone have a working example for how to use the AddTerm web service? Loading existing taxanomy terms works fine, but I need to add some terms! Here is the code I am trying:

AddTerm("<newTerms><newTerm label="Under Root" clientId="1" parentTermId="00000000-0000-0000-0000-000000000000"></newTerms>");
function AddTerm(TermsToAdd) {

    $().SPServices({
        operation: "AddTerms",
        sspId: TaxConfiguration.SspId,
        termSetId: TaxConfiguration.TermSetId,
        lcid: 1033,
        newTerms: TermsToAdd,
        completefunc: TermsAddComplete
    });
}

I keep getting errors stating that I don't have the appropriate GUIDs. I have tried many different versions of the newTerms xml syntax all with the exact same error.

May 28, 2012 at 9:47 AM
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body><soap:Fault><faultcode>soap:Client</faultcode>
<faultstring>Server was unable to read request. ---&gt; There is an error in XML document (1, 291). ---&gt; 
Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope>
May 28, 2012 at 9:59 AM
Edited May 28, 2012 at 10:23 AM

I have tried with an existing Guid also! The SOAP request being sent is this (except for some extra linebreaks that I added):

<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body>
<AddTerms xmlns='http://schemas.microsoft.com/sharepoint/taxonomy/soap/' >
<sharedServiceId>c66c56f7-3721-494f-9606-ccdd7e381cd4</sharedServiceId>
<termSetId>44e7c1e7-b44e-4913-9044-e333826ee844</termSetId>
<lcid>1033</lcid>
<newTerms>&lt;newTerms&gt;&lt;newTerm label=&quot;Under Root&quot; clientId=&quot;1&quot; parentTermId=&quot;00000000-0000-0000-0000-000000000000&quot;&gt;&lt;/newTerms&gt;</newTerms>
</AddTerms></soap:Body></soap:Envelope>
It corresponds very well with the syntax declared on MSDN here!
Coordinator
May 28, 2012 at 3:53 PM

Peter:

The problem may be with your encoding, though it's possible that was introduced when you posted here. Have you tried:

AddTerm("<newTerms><newTerm label='Under Root' clientId='1' parentTermId='00000000-0000-0000-0000-000000000000'></newTerms>");
function AddTerm(TermsToAdd) {

    $().SPServices({
        operation: "AddTerms",
        sspId: TaxConfiguration.SspId,
        termSetId: TaxConfiguration.TermSetId,
        lcid: 1033,
        newTerms: TermsToAdd,
        completefunc: TermsAddComplete
    });
}

Also, from the MSDN page:

New Terms must be stored in XML nodes named NewTerm with an attribute label, attribute clientId and attribute parentTermid. You can have as many NewTerm nodes as needed. clientId is an int that the client used to uniquely identify the newTerm. The parentTermId must either be the GUID of another Term, or an empty GUID if the new Term should be at the root of the TermSet.

So you need to either pass in the parent GUID or a blank ('') GUID for this to work.

M.

Coordinator
May 28, 2012 at 3:53 PM

p.s. If you do get this working, please post your example back so that I can add it to the docs to help others!

M.

May 28, 2012 at 6:10 PM
Edited May 28, 2012 at 7:09 PM

Hi Marc,

Thank you for your reply. I tried two more variants and they did give a different response. Instead of the GUID error message above I got much shorter error saying "Bad Request".

This is the code variants I tried:

 AddTerm("<newTerms><newTerm label='Under Root' clientId='1' parentTermId='00000000-0000-0000-0000-000000000000'></newTerms>"); 
 AddTerm("<newTerms><newTerm label='Under Root' clientId='1' parentTermId=''></newTerms>"); 

I will surely post again if I get this to work, but I am running out of hope and things to try here!

May 28, 2012 at 6:54 PM
Edited May 28, 2012 at 7:12 PM

If someone else is wrestling with this:

I now actually got a success-message by removing the enclosing <newTerms> tag. Nothing is actually added to the terms, though!

AddTerm("&lt;newTerm label=&quot;Under Root&quot; clientId=&quot;1&quot; parentTermId=&quot;00000000-0000-0000-0000-000000000000&quot;&gt;&lt;/newTerm&gt;");

May 28, 2012 at 7:42 PM

So, now I am at the same position as David, from this post!