PHP SOAP request

Hi everyone,


I was playing with the JS API recently and had problems setting multiple attributes on AssetCreate and this time I have a similar problem with PHP SOAP Request. Again I can easily create a simple asset with the following code remotely using PHP SOAP request but have problems figuring out the right syntax for setting asset attributes (e.g. simple_edit_user). Tried multistructured arrays with no result.

    
    <?php
      ini_set("soap.wsdl_cache_enabled", "0");
    
      $login = Array(
            'login'    => 'username',
            'password' => 'password',
           );
    
    try {
     $client = new SoapClient('http://SYSTEM_ROOT_URL/_web_services/server?WSDL', $login); 
    
     $createInfo = Array (
                    'TypeCode'    => 'folder',
                    'Name'        => 'example folder',
                    'ParentID'    => '235851',
                    'LinkType'    => '1',
                    'IsExclusive' => 'TRUE',
                    'IsDependant' => 'TRUE',
                   );
     $newAsset = $client->CreateAsset($createInfo);
    } catch (SoapFault $e) {
      throw new Exception("SOAP Fault Encountered: ".$e->getMessage());
    }//end
    ?>


Would very much appreciate some help with it. Thanks.

Wojtek.

Squiz MySource v3.28.3 (Matrix) SLA

check out the manual here
http://manuals.matrix.squizsuite.net/web-services/chapters/soap-api-asset-service/



Does this work?


    
    
    
     $createInfo = Array (
                    'TypeCode'    => 'folder',
                    'Name'        => 'example folder',
                    'ParentID'    => '235851',
                    'LinkType'    => '1',
                    'IsExclusive' => 'TRUE',
                    'IsDependant' => 'TRUE',
                    'AttributeInfo' =>  Array(Array('AttributeName'=>'short_name', 'AttributeValue' => 'value'))
                   );
    

Not answering your question directly, but in response to:

[quote]I was playing with the JS API recently and had problems setting multiple attributes on AssetCreate[/quote]



You can use the recent addition of the 'enhanced' JS API to create assets and set attributes (and any other JS API function) all in the one http request now. Here is a quick example, asset #429 is my parent asset:


    
    var api = new Squiz_Matrix_API({
       key: "1234567890"
    });
    
    api.batchRequest({
       functions: {
       "0": {
           "function": "createAsset",
           args: {
               id: 429,
               type_code: "page_standard",
               asset_name: "Test Asset"
           }
       },
       "1": {
           "function": "getAttributes",
           args: {
               id: "%results_0_id%"
           }
       },
       "2": {
           "function": "setMultipleAttributes",
           args: {
               id: "%results_0_id%",
               attr_name: "name\\,short_name",
               attr_val: "Brand new name\\,Brand new short name"
           }
       },
       "3": {
           "function": "getAttributes",
           args: {
               id: "%results_0_id%"
           }
       }
       },
       dataCallback: function(data){
       console.log("Asset created with id: %s", data[0].id);
       console.log("Attributes before change: %o ",data[1]);
       console.log("Attributes after change: %o ",data[3]);
       }
    });

[quote]
check out the manual here

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



Does this work?


    
     $createInfo = Array (
                    'TypeCode'    => 'folder',
                    'Name'        => 'example folder',
                    'ParentID'    => '235851',
                    'LinkType'    => '1',
                    'IsExclusive' => 'TRUE',
                    'IsDependant' => 'TRUE',
                    'AttributeInfo' =>  Array(Array('AttributeName'=>'short_name', 'AttributeValue' => 'value'))
                   );
    

[/quote]



Thanks Edison,

tested it and it works, it needs a newish Squiz version as we needed a patch on our supported system to make it work.



here is how you create a simple_edit_user with PHP SOAP request:


    
    ini_set("soap.wsdl_cache_enabled", "0");
    
        $login = Array(
            'login'    => 'username',
            'password' => 'password',
           );
    
       try {
          $client = new SoapClient('http://SYSTEM_ROOT_URL/_web_services/server?WSDL', $login); 
          
    	$createInfo = Array (
           'TypeCode'    => 'simple_edit_user',
           'Name'        => 'SOAPTEST',
           'ParentID'    => '68',
           'LinkType'    => '1',
           'IsExclusive' => 'TRUE',
           'IsDependant' => 'FALSE',
           'AttributeInfo' => array(
    
               array(
                       'AttributeName' =>  'username',
                       'AttributeValue' => 'test123',
                       ),
               array(
                       'AttributeName' =>  'password',
                       'AttributeValue' => 'test123',
               ),
    
               ),
    
           );
    		  
          $newAsset = $client->CreateAsset($createInfo);
       	  echo("ok");
       } catch (SoapFault $e) {
       	  echo("failed: ".$e->getMessage());
       }


Cheers.
Wojtek.

[quote]
Not answering your question directly, but in response to:







You can use the recent addition of the 'enhanced' JS API to create assets and set attributes (and any other JS API function) all in the one http request now. Here is a quick example, asset #429 is my parent asset:


    
    var api = new Squiz_Matrix_API({
       key: "1234567890"
    });
    
    api.batchRequest({
       functions: {
       "0": {
           "function": "createAsset",
           args: {
               id: 429,
               type_code: "page_standard",
               asset_name: "Test Asset"
           }
       },
       "1": {
           "function": "getAttributes",
           args: {
               id: "%results_0_id%"
           }
       },
       "2": {
           "function": "setMultipleAttributes",
           args: {
               id: "%results_0_id%",
               attr_name: "name\\,short_name",
               attr_val: "Brand new name\\,Brand new short name"
           }
       },
       "3": {
           "function": "getAttributes",
           args: {
               id: "%results_0_id%"
           }
       }
       },
       dataCallback: function(data){
       console.log("Asset created with id: %s", data[0].id);
       console.log("Attributes before change: %o ",data[1]);
       console.log("Attributes after change: %o ",data[3]);
       }
    });

[/quote]



That's cool. Nice way of putting all requests into one readable function. I guess that this will only work on the latest Matrix install though.

Cheers.

Wojtek.

Hi again,


can’t really firure out how to get the ‘create asset’ SOAP Response using PHP. I would need to print the ID of the asset that has been created.

The manual stops at showing the PHP request unfortunately and params for request and response. It’s my first SOAP project so the response logic

is not clear to me. So far got a error message:

     asset ID: failed: Function (“CreateAssetResponse”) is not a valid method for this service 




thanks in advance for any kind of hints of how it’s done in PHP.

Wojtek.

[quote]
Hi again,



can’t really firure out how to get the ‘create asset’ SOAP Response using PHP. I would need to print the ID of the asset that has been created.

The manual stops at showing the PHP request unfortunately and params for request and response. It’s my first SOAP project so the response logic

is not clear to me. So far got a error message:

     asset ID: failed: Function (“CreateAssetResponse”) is not a valid method for this service 




thanks in advance for any kind of hints of how it’s done in PHP.

Wojtek.

[/quote]



You created a Soap Server asset in Matrix and made sure to add the correct functions and activate them?

[quote]
You created a Soap Server asset in Matrix and made sure to add the correct functions and activate them?

[/quote]



… And the wsdl needs to be generated as well. Located on the details screen of the soap server.

Thanks Nic, eventually got that answer from a squiz developer. The response is available in the variable containing the CreateAsset request:


$newAsset = $client->CreateAsset($createInfo);

echo($newAsset);