Re: Simple REST API

Depends on the way your apache conf is setup - with or without mod_rewrite and rewrite rules. Your URL is okay if you have the default apache conf setup.

The OpenVZ template I have is setup to avoid the index.php from showing up in the URL.

27 (edited by andresamayadiaz 07/15/2013 05:33:49 pm)

Re: Simple REST API

Hi Again, i just pushed some new and great changes to the API, this is a brief description of the changes:

- Added .htaccess so you can now use API URL's without index.php, examples: (Thanks to Christian Estrella)
    OLD: GET http://mysystem.com/api/index.php/locations/
    NEW: GET http://mysystem.com/api/locations/

- Added Pagination to GET methods, it used to return all entries, now is per page, under index.php it has define("RESULTS_PER_PAGE", 2); that defines how many entries you will get per page, if you dont establish a page on the request you will get the first page. (Thanks to Christian Estrella)
    OLD Request: GET http://mysystem.com/api/index.php/locations/
    OLD Response: ALL LOCATIONS
   
    NEW Request 1: GET http://mysystem.com/api/index.php/locations/
    NEW Response 1: First Page of Locations
   
    NEW Request 2: GET http://mysystem.com/api/index.php/locations/?page=5
    NEW Response 2: Page 5 of Locations

- Added Sales Transactions Methods for Quotes, Sales Orders, Deliveries, Invoices (GET, PUT, POST)
    NOTE: This changes hasn't been tested deeply, might have some bugs

GitHub Commit ID: https://github.com/andresamayadiaz/FrontAccountingSimpleAPI/commit/b94360564f2bf80fe6d466d85767897351cee3de

Hope everybody likes the changes and if you can help me do some testing i will really appreciate that.

Re: Simple REST API

Congrats Andres - keep up the good work. Just placed a link to this post and relevant commit in the Wiki till I have time to go thru' it.

As you appear to be using the Mac for your work, please remove the Mac specific files like .DS_Store, etc from the repo.

Re: Simple REST API

Hi, thanks.

I just noticed that my .gitignore file is missing i just added it again so those Mac specific files wont go to the repo.

I will be doing some final changes to the API and then start working on the mobile App using it, i'll keep you posted.

... aad

Re: Simple REST API

Hi, sorry about this, but i check the gitignore been missing and noticed that i made a big mistake when doing commit, here is the correct commit on github with IMPORTANT BUG FIXES:

http://github.com/andresamayadiaz/FrontAccountingSimpleAPI/commit/1361feb40343d6fd23d66e4b5383a727ef3eeb08

Sorry about this again. aad

Re: Simple REST API

Fixed commit URL in Wiki:
http://www.frontaccounting.com/fawiki/index.php?n=Devel.SimpleAPIModule

Re: Simple REST API

I'm looking into importing sales data using this API, and I found the following errors in sales.inc:

On lines 220, 323 and 422 the string 'freight_cost' should really be $info['freight_cost']
On lines 241 and 353 the test for ($can_process == false) should be ($can_process['passed'] == false)

But I still don't seem to get any data whatsoever into the sales_add function. It's probably just me, but... Has anyone managed to POST data? In particular multi-dimensional arrays, such as required here. Just what format is the data expected to be in?

Re: Simple REST API

Hi tm. Yes i noticed those bugs but i haven't got time to send it to github.com i probably will at the end of this week and let you know about those fixes.

There is also a bug on can_process:
/*if (!check_num('freight_cost', 0)) {
     return array("passed" => false, "message" => _("The shipping cost entered is expected to be numeric."));
   }*/
This should be commented because check_num verifies POST variable and with the API freight_cost is not a required field.

Let me see if i can send you later a POST example of an invoice.

Re: Simple REST API

This is a JSON representation of the POST, hope this helps

{
  "trans_type": "10",
  "ref": "NoGuia0001",
  "customer_id": "4",
  "branch_id": "15",
  "location": "DEF",
  "deliver_to": "ABC, S.A. DE C.V.",
  "delivery_date": "2013-10-30",
  "delivery_address": "Calle., #2333 int: 0, Algo, C.P. 64420, Monterrey, Nuevo Leon, Estados Unidos Mexicanos",
  "phone": "",
  "cust_ref": "",
  "comments": "",
  "ship_via": "1",
  "payment": "5",
  "sales_type": "1",
  "items": [
    {
      "stock_id": "stock0001",   
      "description": "TRANSPORTE MTY-LAREDO",
      "qty": "1",
      "price": "100",
      "discount": "0"
    }
  ]
}

35 (edited by tm 09/13/2013 09:23:34 am)

Re: Simple REST API

Thank you. I'm looking at the new code now (C Estrella's commit), and it's getting better. Not quite there yet, but... At least I'm getting data into sales_add.

Line 282 is still passing a string to input_num() which can't be right.

And the .htaccess file causes the following entry in the error log
[Fri Sep 13 00:29:15 2013] [alert] [client 192.168.22.50] /var/www/frontaccounting/modules/api/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

Now I'm sure that is a problem with my local configuration, so I've just renamed it for now. I do however get another, more interesting entry:
[Fri Sep 13 00:49:26 2013] [error] [client 192.168.22.50] 0::connect_db.inc:51: mysql_query() expects parameter 2 to be resource, null given

Parameter 2 is $db, a global variable. It is not passed to the function (db_query) which calls mysql_query. It should just be there. How can it not be there? Does it get overwritten by the API code somewhere? Because everything is fine when accessing the system through a web browser.

Edit: No. More likely, it is never set to begin with.

36 (edited by rsearle 06/16/2014 01:05:58 am)

Re: Simple REST API

I'm working through implementing this API as an element of an interface to/from a VirtueMart online shop. I will need to use sales.inc to post invoiced online orders to FA. Since 26 July 2013 sales.inc has included these imports:

18: include_once($path_to_root . "/modules/timbrado/includes/db/comprobantes_db.php.inc");
19: include_once($path_to_root . "/modules/timbrado/includes/db/llavero_db.php.inc");
20: include_once($path_to_root . "/modules/timbrado/includes/generate/AutoFacturaCore.php.inc");
21: include_once($path_to_root . "/modules/timbrado/includes/db/configuraciones_db.php.inc");

What is this timbrado (stamping?) module? I can't find any relevant reference to it anywhere.

Also, the sales_cancel function contains code that depends on AutoFacturaCore.php.inc. This code won't work without the missing includes:

function sales_cancel($branch_id, $uuid)
{
    error_log("\r\n1", 3, "/var/tmp/sasys.log");
    $AutoFactura = new AutoFacturaCore();
    $AutoFactura->userkey = get_cofig("Llave de Usuario", "");
    $AutoFactura->suckey = $branch_id;
    $AutoFactura->url = get_cofig("Servidor", "");
    $datos = array('autofactura_id' => $uuid);
    $response = $AutoFactura->cancelar($datos);
    error_log("\r\n2=>" . json_encode($response), 3, "/var/tmp/sasys.log");

    try {
        if ($response['exito'] == 1) {
            error_log("\r\n3", 3, "/var/tmp/sasys.log");
            set_sql_cancelar_digital($uuid, $response['url']);
            api_success_response(_("The invoice was cancelled."));
            return;
            error_log("\r\n4", 3, "/var/tmp/sasys.log");
        } else {
            error_log("\r\n5", 3, "/var/tmp/sasys.log");
            api_error(500, _('Could not cancel invoice.'));
            return;
        }
    } catch (Exception $e) {
        error_log("\r\n6", 3, "/var/tmp/sasys.log");
        api_error(500, _('Could not cancel invoice. ') . $e->getMessage());
        return;
    }
}

Thanks ...

37 (edited by apmuthu 06/16/2014 02:50:41 am)

Re: Simple REST API

What has the Autofactura (Site - Translation: Self Invoice) project (based on Ruby/Gems) got in common with Front Accounting?

38 (edited by rsearle 06/16/2014 03:18:07 am)

Re: Simple REST API

apmuthu wrote:

What has the Autofactura (Site - Translation: Self Invoice) project (based on Ruby/Gems) got in common with Front Accounting?

If that's what it is, then I'd like to know that too. Why is it imported in the FA Simple REST API sales.inc file (apparently as part of some module entitled timbrado), and why is it used in the sales_cancel function?

But I think "autofactura" translates roughly as "auto-billing", and the mysterious timbrado module may have something to do with a third-party billing system.

Re: Simple REST API

I suspect it's auto(-matic), rather than "self-". While my Spanish is somewhat limited, it seems to be a service for electronic invoices (and/or payment of them) in Mexico. And the ruby code which (I guess) provides an interface to it is written by the same chap who wrote "our" REST API.

He might well have planned to exchange invoice data between Autofactura and FA, using a ruby-based web service. But the API was abandoned (?) before it was finished, so who knows what was actually planned...

Re: Simple REST API

That sounds like it might be true. If so, I guess it tells us what to do with the code.

Does anybody know the current maintenance/support status of the API?

Re: Simple REST API

Some posts in the forum indicate it was used for a desktop version of FA.

Re: Simple REST API

Hi, i am really sorry if i confuse with the Simple REST API for FA and another project on my github repo.

I created a branch of my Simple REST API for a client that wanted to connect FA and other Rails software with AutoFactura, so thats why i created the ruby gem for AutoFactura.

So for the Simple REST API i just changed the branch master with the help of Cambell Prince which send me a pull request that does not have anything additional.

43 (edited by saravanans 05/28/2015 02:42:33 pm)

Re: Simple REST API

I gave the url  http://localhost/frontaccounting/modules/api/category and i follow the steps as you said i got the response code is 200. I inserted the 6 row in stock_category table. But i got the response value is Response does not contain any data. In this url si redirect into login page. Pls anyone help me to clear this problem because i am struggling 1week. The problem in index.php file in api_login();
function calling

44 (edited by andresamayadiaz 02/02/2017 01:53:18 am)

Re: Simple REST API

Hi Again, hope you are all doing well.

It's been a long time since the first release of Simple REST API, and lots of people asked me about a POS integration.

I made some spare time and i am working on a new light weight API and the integration with SynPOS 0.9.3, this is still a work in progress and many data is hardcoded (for example the customer id to sync orders) and lots of bugs still, but i wanted to let you know i am working on this and if there is anyone interested in helping with testing, coding or code review it will be appreciated, just let me know in this post or via email.

... Andres Amaya

Re: Simple REST API

SynPOS hasn't been updated since Nov 2006 at SourceForge and is written in Java.

synpos mirror with some mods is on GitHub and was last updated in Sep 2015.

Which is your repo for the integration?

Initial user / password: 123 / 123
Uses the HSQL DB by default - can configure for MySQL with JDBC.

Post's attachments

SynPOS_LoggedIn.png 21.5 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.

Re: Simple REST API

SynPOS locations

Post's attachments

SynPOS.png 56.6 kb, file has never been downloaded. 

You don't have the permssions to download the attachments of this post.