Method Community

 

MethodAPIInsert error with input field array

Last post 09-01-2009 11:29 AM by paul. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 08-21-2009 7:55 PM

    • paul
    • Top 500 Contributor
    • Joined on 08-21-2009
    • Posts 11

    MethodAPIInsert error with input field array

    Hello,

    I'm currently working on using the API to create some new customers and I'm getting a strange error message. It reads (PHP syntax):

    [MethodAPIInsertResult] => A blank field name was entered in the arrInsertFieldArray. Please verify there are no empty items in the arrInsertFieldArray.

    In reading the API version 1.1 document it reads that there should be an array named 'arrInsertFieldsArray' for passing in new data. I'm just wondering if the 's' after the word Field is a type-o in the API document or if the error message returned from the is wrong.

    Secondly, I want to make sure I'm reading the API response properly regarding what object type I'm trying to create. I called the API to see read up on the Customer object.

    I.e.

        [MethodAPIFieldListResult] => Success
        [xmlReturned] => <MethodIntegration Table='Customer'>

    And this was the only element that had a required tag set to true.

      <Record>
        <SupportsAdd>true</SupportsAdd>
        <SupportsEdit>true</SupportsEdit>
        <IsRequired>true</IsRequired>
        <FieldName>Name</FieldName>
        <MaxSize>41</MaxSize>
        <DataType>Text</DataType>
      </Record>

    So can I conclude, that I can add a customer via the API supplying as little information as a name?

    Thanks!

     

     

     

  • 08-21-2009 8:39 PM In reply to

    Re: MethodAPIInsert error with input field array

    Paul - the typo appears to be in the response message, rather than the parameter, so the API docs are correct.  It is arrInsertFieldsArray, not arrInsertFieldArray.  I'll forward your findings on - thank you.

    In terms of the Customer, yes, the only required field is Name.  You are absolutely correct.  Seems like you are getting the hang of it pretty quickly.

    You'll find the API is as simple as it seems.  Really, all you are doing is formatting SQL insert, update and query statements using the web service calls.

    Moving this thread to the API forum, since there is a separate forum for API questions.

    HTH

    Paul

     

     

  • 08-24-2009 11:24 AM In reply to

    • paul
    • Top 500 Contributor
    • Joined on 08-21-2009
    • Posts 11

    Re: MethodAPIInsert error with input field array

    Paul,

    Thanks for your quick response. So far, I'm finding the API pretty nice to work with, but I haven't quite gotten my customer insert test to work yet. Here's a block of my code in PHP. Please note that I noticed all of your code samples were in VB and ASP.NET, so once my project is complete, I'd be glad to post my code so other PHP developers can reuse some snippets.

    Does everything look in order?

    <?php

        //@TODO : Add in SSL encryption componenet, currently just communicating over unsecure HTTP

        //use the nusoap library
        require_once('lib/nusoap.php');

        //define the SOAP Client and point to the SOAP Server
        $client = new soapclient('http://www.methodintegration.com/MethodAPI/service.asmx?wsdl',true);  

        $array = array( 'strCompanyAccount' => 'MYCOMPANY',
                          'strLogin' => 'MYNAME',
                          'strPassword'  => 'MYPASSWORD',
                          'strTable' => 'Customer',
                          'arrInsertFieldsArray' => array('Name'),
                          'arrInsertValueArray' => array('Frank The Tank'),
                          'intResponseRecordID'  => $id,                
                       );

        print_r( $client->call('MethodAPIInsert', $array));

        echo 'Response code : '.$id;

        //kill the client
        unset($client);

    /*
        Framework for the call based upon this element from the WSDL
        <s:element minOccurs="0" maxOccurs="1" name="strCompanyAccount" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="strLogin" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="strPassword" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="strTable" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="arrInsertFieldsArray" type="tns:ArrayOfString"/>
        <s:element minOccurs="0" maxOccurs="1" name="arrInsertValueArray" type="tns:ArrayOfString"/>
        <s:element minOccurs="0" maxOccurs="1" name="intResponseRecordID" type="s:string"/>
    */

    ?>

    When I run this test insert, I'm still getting this response:

    Array
    (
        [MethodAPIInsertResult] => A blank field name was entered in the arrInsertFieldArray. Please verify there are no empty items in the arrInsertFieldArray.
        [intResponseRecordID] =>
    )


    Thanks for your time!

     

     

  • 08-24-2009 11:37 AM In reply to

    Re: MethodAPIInsert error with input field array

    Paul - before I get the dev team to look into this, can you just verify one thing for me?

    I've seen this message before, and I think every time I've seen it, the reason was that the last index in the array was not used.

    For example, the array was a 0-based index, and was defined as myarray(10)  when there are 10 values you want to pass, instead of myarray(10-1) to account for the 0 based index.  In other words, if you are passing 10 values, myarray should be myarray(9).

    That's my hunch.  If I'm wrong, let me know and we'll dive deeper.

    And yes, I'm sure the PHP community would LOVE to get a couple samples up here. It would not be the first time someone has asked for it.   :)

    Paul

  • 08-24-2009 12:39 PM In reply to

    • paul
    • Top 500 Contributor
    • Joined on 08-21-2009
    • Posts 11

    Re: MethodAPIInsert error with input field array

    Paul.

    Thanks for the response. I think I see what youre saying, but I dont know if it applies here. PHP arrays natively assign indexing without construction arguments (i.e. default sizing), so when I say

    $fieldArray = array('Name');

    I've just created an arrray with one element indexed at position 0. So

    echo $fieldArray[0];

    would print out 'Name'

    I've  worked with other less dynamic languages where going off the end of an array can be quite problematic, but PHP is pretty flexible with such things.

    Also, in addition I tried using PHPs associative array function with indexing manually forced in just to make sure I wasnt overlooking something.

                          'arrInsertFieldsArray' => array( '0' => 'Name'),
                          'arrInsertValueArray' => array( '0' => 'Frank the Tank'),

    Which is roughly equivalent to :

                          'arrInsertFieldsArray' => array('Name'),
                          'arrInsertValueArray' => array('Frank the Tank'),

    But I was just trying to experiment with your suggestion. But alas, I'm still seeing the same error.


    Thanks for your time,


    Paul

     

     

  • 08-25-2009 8:14 AM In reply to

    Re: MethodAPIInsert error with input field array

     Paul,

    We're still looking into this. We are able to duplicate your issue where the array values are not being passed to the server.

    I'll give you an update by the end of the day on our progress.

    Peter

  • 08-25-2009 12:33 PM In reply to

    • paul
    • Top 500 Contributor
    • Joined on 08-21-2009
    • Posts 11

    Re: MethodAPIInsert error with input field array

    I just looked out at my outbound SOAP envelope and it looks like this

    <SOAP-ENV:Envelope>
    <SOAP-ENV:Body>
    <MethodAPIInsert>
    <strCompanyAccount>MYCOMPANY</strCompanyAccount>
    <strLogin>MYUSERNAME</strLogin>
    <strPassword>MYPASSWORD</strPassword>
    <strTable>Customer</strTable>
    <arrInsertFieldsArray>
    <string/>
    </arrInsertFieldsArray>
    <arrInsertValueArray>
    <string/>
    </arrInsertValueArray>
    <intResponseRecordID/>
    </MethodAPIInsert>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

    So clearly, something is messed up with the input array elements. I'm using PHP's Nusoap library and it might be handling the request data improperly.Could you please provide and example of a property formatted SOAP envelope for creating a Customer ( or any request that uses sub arrrays ).

    Thanks!

  • 08-31-2009 12:40 PM In reply to

    Re: MethodAPIInsert error with input field array

     Paul,

    PHP's Nusoap is a little tricky with array within array.

    Here is the format I was able to pass in the array. Using the 'key' as the datatype allowed the array to be passed in.

     
    //use the nusoap library
    require_once('lib/nusoap.php');
    $ns="urn:servicename";
    $client = new soapclient('http://www.methodintegration.com/MethodAPI/service.asmx?wsdl', true);
     
     
    $array = array( 'strCompanyAccount' => 'AccountName',
     'strLogin' => 'UserName',
     'strPassword'  => Password,
     'strTable' => 'Customer',
     'arrInsertFieldsArray' => array('string' => array('Name')),
     'arrInsertValueArray' => array('string' => array('Frank the Tank')),
     'intResponseRecordID'  => $id         
     );    
    $result =  $client-> call('MethodAPIInsert', $array, array("soapaction"=>"http://tempuri.org/MethodAPIInsert")); 
    echo 'Response code : '.$result[0];

    //kill the client
    unset($client);

  • 09-01-2009 11:29 AM In reply to

    • paul
    • Top 500 Contributor
    • Joined on 08-21-2009
    • Posts 11

    Re: MethodAPIInsert error with input field array

    Peter,

    Looks good! Thanks a ton! i just found out another good practice for using nusoap. I found some documentation that recommmends using the nusoap_client constructor in case the PHP install has both SoapClient and Nusoap installed, that way you know you're getting the right object!

    I.e.    $client = new nusoap_client('https://www.methodintegration.com/MethodAPI/service.asmx?wsdl', true);

    Thanks again!

     

     

Page 1 of 1 (9 items)