SOAP Advanced Search ignoring asset types?


(Talk) #1

I'm running SOAP advanced search through search_service_requests.js, and while the following output it sends looks good, it returns all asset types.

 

Also, the limit is ignored too, with dozens of results being returned.

 

Is there a problem with the following request?

var assets = ['page_standard','calendar_event_single'],
    limit = 10,
    format = '%asset_assetid%',
    root = 12345,
    statuses = [2,4,8,16,32,64,128,256],
    searchParams = '...', // omitted from post as long and irrelevant
soapBody = AdvancedSearch(assets,'','OR',limit,format,root,'OR',statuses,searchParams,'FALSE'),

    soapRequest = constructSOAPRequest(soapBody, soapURL);

    send(wsdl,soapRequest,function(response){
console.log(response);
});

Translates to:

<SOAP-ENV:Body>
    <ns1:AdvancedSearch>
        <AssetTypes>page_standard</AssetTypes>
        <AssetTypes>calendar_event_single</AssetTypes>
        <FieldLogic>OR</FieldLogic>
        <Limit>10</Limit>
        <ResultFormat>%asset_assetid%</ResultFormat>
        <RootIDs>12345</RootIDs>
        <RootLogic>OR</RootLogic>
        <Statuses>2</Statuses>
        <Statuses>4</Statuses>
        <Statuses>8</Statuses>
        <Statuses>16</Statuses>
        <Statuses>32</Statuses>
        <Statuses>64</Statuses>
        <Statuses>128</Statuses>
        <Statuses>256</Statuses>
        <SearchFields>
            <SearchTerm>test</SearchTerm>
            <WordLogic>AND</WordLogic>
            <DataSources>
                <FieldType>Standard</FieldType>
                <StandardOption>
                    <FieldName>name</FieldName>
                </StandardOption>
            </DataSources>
        </SearchFields>
        <ExcludeRootNodes>FALSE</ExcludeRootNodes>
    </ns1:AdvancedSearch>
</SOAP-ENV:Body>

Matrix 4.16.2

Mac OS X 10.9.2

Chrome 35.0.1916.153

 

Thanks for any help :-)


(Edison Wang) #2

Please have a look at the manual page example usage.

http://manuals.matrix.squizsuite.net/web-services/chapters/soap-api-search-service

 

The format of asset types looks wrong.


(Talk) #3

Hi Edison, thanks, yep I've been working off that. Is passing a simple array not sufficient? The API calls:

multiple_elements_to_string(asset_types, "AssetTypes");
function multiple_elements_to_string(array_elements, element_name)
{
    var result_str    = '';
    for (var i = 0; i < array_elements.length; i++) {
        result_str    += '<'+element_name+'>'+array_elements[i]+'</'+element_name+'>';
    }//end for
    
    return result_str;
    
}//end multiple_elements_to_string()

Which sends back:

<AssetTypes>page_standard</AssetTypes>
<AssetTypes>calendar_event_single</AssetTypes>

Thank you


(Bart Banda) #4

Have you tried using calling the soap call without JS? Just via a SOAP dev client or even within the Matrix interface to see if you can get that working first? Also, not sure if adding multiple statuses by multiple tags actually will search all those statuses, i thought you would just put all statuses into the 1 tag, but might be wrong, probably not your issue anyway. 


(Talk) #5

Hey Bart, thanks. I'm not sure about the statuses, the API seems to be expecting an array, as it calls a method to split it, wrapping each value in <statuses>.

 

The same behaviour is applied to the asset_types variable. I'm not confident enough to say with any certainty, but I suspect that this is could be a bug - unless I'm totally wrong and the API is not expecting a simple array.


(Nic Hubbard) #6

Hey Bart, thanks. I'm not sure about the statuses, the API seems to be expecting an array, as it calls a method to split it, wrapping each value in <statuses>.

 

Yes, you are correct, for things like Statuses it is expecting it in the format:

<Statuses>1</Statuses>
<Statuses>2</Statuses>
<Statuses>4</Statuses>
<Statuses>8</Statuses>
<Statuses>16</Statuses>
<Statuses>32</Statuses>
<Statuses>64</Statuses>
<Statuses>128</Statuses>
<Statuses>256</Statuses>

But for Asset Types you would want:

<AssetTypes>
   <AssetType>page</AssetType>
   <Inherit>1</Inherit>
   <AssetType>file</AssetType>
   <Inherit>1</Inherit>
</AssetTypes>

(Talk) #7

...

But for Asset Types you would want:

<AssetTypes>
   <AssetType>page</AssetType>
   <Inherit>1</Inherit>
   <AssetType>file</AssetType>
   <Inherit>1</Inherit>
</AssetTypes>

 

Thanks Nic, my problem is that search_service_requests.js does not seem able to output the correct XML structure based on the array provided, so I must be wrong in feeding it a simple array, unless it's a bug.

    var asset_types_str        = multiple_elements_to_string(asset_types, "AssetTypes");

^ This will only return:

<AssetTypes>page_standard</AssetTypes>
<AssetTypes>calendar_event_single</AssetTypes>

Thanks


(Nic Hubbard) #8

Yeah, the search_service_requests.js hasn't been touched in 4 years, so that is for sure a bug.

 

Why do you have to use it? Can't you just roll your own requests with your own javascript? It would give you more control...


(Talk) #9

Thanks Nic, I can, but It'd be easier to run with the pre-built function libraries by Squiz - and that would be my preference, assuming they'd update the libraries in line with changes from version to version.

 

I wonder if the limit failure is also a bug at the SOAP server level, any theories?


(Nic Hubbard) #10

I wonder if the limit failure is also a bug at the SOAP server level, any theories?

 

I have used the limit option in my app and it seemed to work exactly how it should. I would use a SOAP client to test the function if you are having doubts.