Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
API (xmlrpc) problem
02-26-2013, 11:35 PM
Post: #11
RE: API (xmlrpc) problem
I will try sending this on the off chance Phil doesn't reject it as normal.

Debugging the api is actually very simple when you get the hang of it. When the client app gets a response from the server (your target webERP instance) it receives an array. The first element of the array (for instance $A[0]) will contain a code, zero for success and other numbers for an error. The error numbers are contained in the file api/api_errorcodes.php on the webERP side.

Looking at your debug output you are receiving the following xml:

array (
0 =>
xmlrpcval::__set_state(array(
'me' =>
array (
'int' => 1,
),
'mytype' => 1,
'_php_class' => NULL,
)),
),

Interpreting this you can see that element 0 (zero) has a value of 1 (one). Now looking at api_errorcodes.php we see:

/* Define error codes that are returned by api functions*/
Define('NoAuthorisation', 1);

So error code 1 is for an authorisation failure. The first thing I would look at is if the user/password combination you are sending is a valid one for your webERP instance. I see this in your debug info as part of the function call you are sending:

<param>
<value><string>admin</string></value>
</param>
<param>
<value><string>weberp</string></value>
</param>

Is admin/weberp a valid user/password combination on your webERP?

Thanks
Tim
Quote this message in a reply
02-26-2013, 11:47 PM
Post: #12
RE: API (xmlrpc) problem
(02-26-2013 11:35 PM)weberp-forums Wrote:  Is admin/weberp a valid user/password combination on your webERP?

It is, I have only 2 users and both have weberp set at the password. Thanks for deciphering the error code, though.
Find all posts by this user
Quote this message in a reply
02-26-2013, 11:58 PM
Post: #13
RE: API (xmlrpc) problem
Ok then, next thing to check is that its trying to login to the correct company. In api/api_php.php there is a variable $api_DatabaseName which should contain the database/company name you are trying to log into. Can you check that?

Thanks
Tim
Quote this message in a reply
02-27-2013, 01:10 AM (This post was last modified: 02-27-2013 01:13 AM by SMT Corp.)
Post: #14
RE: API (xmlrpc) problem
^^^ Edit: I had this thread open and I ended up finding this on my own almost by accident and I did not see your reply prior to posting this. You hit the nail right on the head.

Within the API folder, in api_php.php, near the top, the demo database was hardcoded.

Code:
/* Include session.inc, to allow database connection, and access to
   miscfunctions, and datefunctions.*/
    // FOLLOWING ONLY REQUIRED TO SUPPORT PER FUNCTION AUTHENTICATION
    $api_DatabaseName='weberpdemo';
    // END OF OLD STYLE AUTHENTICATION

I changed this to the name of my database, and all is well.

So it looks like the hardcoding is "ONLY REQUIRED TO SUPPORT PER FUNCTION AUTHENTICATION," and I was attempting to use per function authentication. Still, this seems like the kind of thing that should be overwritten to the appropriate database name during installation/configuration, no?
Find all posts by this user
Quote this message in a reply
02-27-2013, 01:15 AM
Post: #15
RE: API (xmlrpc) problem
(02-27-2013 01:10 AM)SMT Corp Wrote:  I think I got it!

Within the API folder, in api_php.php, near the top, the demo database was hardcoded.

Code:
/* Include session.inc, to allow database connection, and access to
   miscfunctions, and datefunctions.*/
    // FOLLOWING ONLY REQUIRED TO SUPPORT PER FUNCTION AUTHENTICATION
    $api_DatabaseName='weberpdemo';
    // END OF OLD STYLE AUTHENTICATION

I changed this to the name of my database, and all is well.

So it looks like the hardcoding is "ONLY REQUIRED TO SUPPORT PER FUNCTION AUTHENTICATION," and I was attempting to use per function authentication. Still, this seems like the kind of thing that should be overwritten to the appropriate database name during installation/configuration, no?

Hi, glad its sorted. The hard coding of the database name is really the only design decision on the api that I regret. It would be better to send the database name with the authentication from the client. Trouble is I am not sure how to correct it now without screwing any external applications that use the api.

Maybe it should read the config.php file and use the default database in there, but what happens if you want to use the api on a different database than the default? I am not sure of the answer, would be interested in any ideas.

Thanks
Tim
Quote this message in a reply
03-14-2013, 06:02 PM
Post: #16
RE: API (xmlrpc) problem
When i'm ruining below code i'm getting this error - Fatal error: Call to a member function kindOf() on a non-object in C:\wamp\www\webERP\xmlrpc\lib\xmlrpc.inc on line 3310



<?php
include '../webERP/xmlrpc/lib/xmlrpc.inc';

//include 'config.inc';

echo '<a href="index.php">Home</a></BR>';

if (isset($_GET['stockid'])) {
$_POST['stockid']=$_GET['stockid'];
$_POST['submit']='set';
}
if (!isset($_POST['submit'])) {
echo '<FORM METHOD="post" action=' . $_SERVER['PHP_SELF'] . '>Enter stock id';
echo '<INPUT type="text" name="stockid"></BR>';
echo 'Enter Location ID <INPUT type="text" name="locationid"></BR><input type="Submit" name="submit" value="Get Balance">';
echo '</FORM>';
} else {


$stockid = new xmlrpcval($_POST['stockid']);
$user = new xmlrpcval('admin');
$password = new xmlrpcval('abc123');

$msg = new xmlrpcmsg("weberp.xmlrpc_GetStockBalance", array($stockid, $user, $password));


$client = new xmlrpc_client('http://localhost/webERP/api/api_xml-rpc.php');
$client->setDebug(2);

$response = $client->send($msg);

$balances = php_xmlrpc_decode($response->value());

echo "<table border=1>";
if (sizeof($balances)<1) {
echo 'oops, an error number '.$balances[0].' has occurred';
}
for ($i=0;$i<sizeOf($balances[1]);$i++) {
echo "<tr><td>".$balances[1][$i]['loccode']."</td><td>".$balances[1][$i]['quantity']."</td></tr>";
}
echo "</table>";
}
?>
Find all posts by this user
Quote this message in a reply
03-28-2013, 11:56 PM (This post was last modified: 04-04-2013 07:33 AM by phil.)
Post: #17
RE: API (xmlrpc) problem
Hi, what information did you get before this error message. With debug level at 2 there was probably a lot of information sent. Can you post it here.

This error means that webERP is returning some information that is not correctly formed xml, probably meaning that it is generating an error message. I take it the userid/password combination you are sending is a genuine webERP login?

Thanks
Tim
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)