Re: REST API

Hello ApMuthu / Cambell

I have found the endpoints and routes from the source code. Thanks

@ApMuthu can you give an example how a direct sales can be posted through the "Insert sales" method?

Regards
Sume MS

Re: REST API

Create a Sales Invoice and use the Slim API to GET that invoice - you will get the json value. Form your new Invoice in json accordingly and use the PUT endpoint to inject your invoice. Putting in such an invoice will not have the Sales Order, Sales Delivery and Customer Payment that would need to have their own PUT requests in place (or does it?).

I'm sure you can now parse the code and determine what you need. The community has put in sufficient effort in double quick time to assist you among others. Hopefully you too will contribute tested code to it once you get familiar.

This is what makes Open Source tick.

Re: REST API

Fantastic ApMuthu, I will follow this and update.
I appreciate that you all have supported me much here, and I will contribute once the testing is done.

Many thanks.
Regards
Sume MS

Re: REST API

@s4m3shms I have started some documentation here but it is a long way from complete.  It is auto generated from comments in the code and I haven't the time to do that all in one go.  But its a start.

In the mean time you can learn how to use the SimpleAPI from the tests that are in the source (but excluded from the package).

https://github.com/cambell-prince/Front … r-cp/tests

As an example, the sales test shows how to list, create, update, and delete a sale.

If anyone wants to see the source annotations for the documentation you can have a look at the feature/docs branch in GitHub.

Cambell https://github.com/cambell-prince

30 (edited by s4m3shms 11/22/2017 07:16:46 am)

Re: REST API

Hello

I am trying to post a category items using this method  http://myurl/modules/api/category/

For example, when I do POST with this
{"category_id":"6","description":"Components6","dflt_tax_type":"1","dflt_units":"each","dflt_mb_flag":"B","dflt_sales_act":"4010","dflt_cogs_act":"5010","dflt_inventory_act":"1510","dflt_adjustment_act":"5040","dflt_assembly_act":"1530","dflt_no_sale":"0"}

The output return a validation error as

{"success":0,"msg":"Description is required"}

But the description is already in the content.

Same for Locations too

http://myurl/modules/api/locations/       and POST content as

{"stock_id":"TEST","loc_code":"DEF","location_name":"Default","delivery_address":"Delivery 1\nDelivery 2\nDelivery 3","phone":"","phone2":"","fax":"","email":"","contact":""}

Message returned is {"success":0,"msg":"Stock Id is required"}

I use this repo : https://github.com/apmuthu/FA24extensions/tree/master/Extensions/api24

Regards

Sume MS

Re: REST API

Hello Cambell

This is extremely useful. I am going through all of them.

Regards
Sume MS





cambell wrote:

@s4m3shms I have started some documentation here but it is a long way from complete.  It is auto-generated from comments in the code and I haven't the time to do that all in one go.  But its a start.

In the mean time you can learn how to use the SimpleAPI from the tests that are in the source (but excluded from the package).

https://github.com/cambell-prince/Front … r-cp/tests

As an example, the sales test shows how to list, create, update, and delete a sale.

If anyone wants to see the source annotations for the documentation you can have a look at the feature/docs branch in GitHub.

Re: REST API

@s4m3shms You'll need to use the content-type: application/x-www-form-urlencoded and ensure that your data is form encoded (not JSON).  This is how the SimpleAPI has always been since its beginning.

The unit tests show how to do this with Guzzle in php.  .NET can also do this easy enough I think.

Cambell https://github.com/cambell-prince

Re: REST API

@s4m3shms I've just got the api working accepting JSON input with a Content-Type: application/json, its only working on my machine right now.  I'll code a unit test and hope to ship a release tomorrow.

Cambell https://github.com/cambell-prince

Re: REST API

A new release of FrontAccountingSimpleAPI is available here:

https://github.com/cambell-prince/FrontAccountingSimpleAPI/releases/tag/v2.4-1.3

This includes support for json sent in requests using Content-Type: application/json with json encoded data in the body.

Cambell https://github.com/cambell-prince

Re: REST API

Hi Cambell

It worked with Content-Type: application/json!

There is a mismatch in the parameters with GET and POST. I had to go through the source to get the correct parameter.
Or can I get the correct parameter type somewhere?

For example when using GET api/category we get:

{"category_id":"1","description":"Components","dflt_tax_type":"1","dflt_units":"each","dflt_mb_flag":"B","dflt_sales_act":"4010","dflt_cogs_act":"5010","dflt_inventory_act":"1510","dflt_adjustment_act":"5040","dflt_wip_act":"1530","dflt_no_sale":"0"}

but I had to POST with this

{"tax_type_id":"1","units":"each","description":"Test9","mb_flag":"B","sales_account":"4010","cogs_account":"5010","inventory_account":"1510","adjustment_account":"5040","wip_account":"1530","dflt_no_sale":"0"}

where dflt_units is replaced with units
dflt_mb_flag is replaced with mb_flag
dflt_sales_act is replaced with sales_account .. and so on

Thanks anyway , keep going..



cambell wrote:

A new release of FrontAccountingSimpleAPI is available here:

https://github.com/cambell-prince/FrontAccountingSimpleAPI/releases/tag/v2.4-1.3

This includes support for json sent in requests using Content-Type: application/json with json encoded data in the body.

Re: REST API

@cambell: In your releases you can exclude the public/.git folder.

Extended the API to cover specific Tax_Type endpoint after synching with @cambell's latest release.
Added json output download example.

Post's attachments

api24.zip 194.7 kb, 7 downloads since 2017-11-24 

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

Re: REST API

@s4m3shms I'm working on refactoring the tests and ensuring consistency in GET, POST and PUT for all endpoints based on your feeback (with tests).

@apmuthu.  Thanks! Fixed in https://github.com/cambell-prince/FrontAccountingSimpleAPI/commit/d3d183aa733d562e2de8536bd8f7ce3a672ae781

Cambell https://github.com/cambell-prince

Re: REST API

Thanks Cambell

Update us on the progress please.

Regards
Sume

Re: REST API

I've released version v2.4-1.4 of the Simple API for Front Accounting.  You can download it here:

https://github.com/cambell-prince/FrontAccountingSimpleAPI/releases/tag/v2.4-1.4

This release ensures consistency in the api parameters between POST (Create) and PUT (Update). Also ensures parameters are named consistently with their use in Front Accounting 2.4.

- Refactor tests to ensure consistency in POST and PUT api.
- Added tests/Crud_Base.php
- Add api_ensureAssociateArray to remove the numeric index elements that come from the Front Accounting functions.
- The category end point now follows the database schema more closely for property names.
- The customers end point now follows the database schema more closely for property names.

Thanks @apmuthu and @s4m3shms for testing and providing feedback.

@s4m3shms Hopefully you will now find the GET, POST and PUT behavior more consistent.

Cambell https://github.com/cambell-prince

Re: REST API

Have synched my repo. Standardised the braces. It continues to work without composer. Latest version attached.

Post's attachments

api24.zip 195.2 kb, 8 downloads since 2017-11-28 

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

Re: REST API

My releases work without composer also.  composer is a developer tool, not an end user tool.

Cambell https://github.com/cambell-prince

Re: REST API

Mine is packaged to work without composer and it's dependencies  by default. The community now has the options of using it
1. with composer (your default) or
2. editing your release to work without it or
3. using mine (default no composer) directly.

Also my version does not need the PHP 5.4+ dependency of the new array declaration []. The FA and API paths are hardcoded in mine though.

Hope these differences will help end users make their choice.

43 (edited by s4m3shms 11/28/2017 10:12:48 am)

Re: REST API

Thanks guys for the excellent works!

I have tested @cambell's version , as you said GET, POST and PUT behaviors are more consistant.

Both @apmuthu and @cambell versions work without any hastle without any dependancy configuration.

I will continue my testing and post the updates.

Regards
Sume MS



cambell wrote:

I've released version v2.4-1.4 of the Simple API for Front Accounting.  You can download it here:

https://github.com/cambell-prince/FrontAccountingSimpleAPI/releases/tag/v2.4-1.4

This release ensures consistency in the api parameters between POST (Create) and PUT (Update). Also ensures parameters are named consistently with their use in Front Accounting 2.4.

- Refactor tests to ensure consistency in POST and PUT api.
- Added tests/Crud_Base.php
- Add api_ensureAssociateArray to remove the numeric index elements that come from the Front Accounting functions.
- The category end point now follows the database schema more closely for property names.
- The customers end point now follows the database schema more closely for property names.

Thanks @apmuthu and @s4m3shms for testing and providing feedback.

@s4m3shms Hopefully you will now find the GET, POST and PUT behavior more consistent.

Re: REST API

@apmuthu I don't understand why an end user would care about composer?  As @s4m3shms notes it works without any dependency configuration required.  The community does not need to edit my releases for the api to work.

As to the new array declaration the only place that appears is in the not yet complete Purchases.php file.  In your code (being a copy of mine) that is not a callable endpoint either.  In my code the file is not included, where as in your code you include it in line 6 of index.php, I would suggest that you simply delete the file if you aren't planning on working on it.  Currently, for the most part its a copy of the Sales api and doesn't work - again not that its callable.  Its an artifact of work in progress.

I have no objection to you forking the code or releasing it, that's what makes open source tick.  You've contributed testing and feedback, for which I'm thankful, and I've fixed bugs.  However, I do want to make sure that statements made as to the benefits of one over the other are accurate.  You claim that mine "requires composer", I cannot see why the end user would need to be concerned with that.   The installation of my release requires downloading the zip or tarball in the releases page and unpacking into the api folder.  From that point it should "just work".  Yours does have the change to Slim which may reduce the logging noise in some versions of php.

Cambell https://github.com/cambell-prince

Re: REST API

By end user I mean those who install, maintain and use FrontAccounting by themselves with the Slim API, not the FA application operatives using what someone else installs and maintains.

What is wrong with line 6 of index,php? Just a plain include of all php files in the src folder so that any function in any endpoint can use it. I am planning on working on it to make sure that native FA functions are used for the most part. It works for me.

If there is anyone for whom the code does not work, please let me know - I'd like to know why and will do what needs to be done. I am keeping it as backward compatible as is possible so that those on older PHP versions too can still keep their installs whilst leveraging the REST API.

If you put in some test access values in util.php, you can easily browse to say: http://localhost/fa24/modules/api24/category/1

I've been packaging the original submission from Andres Amaya Diaz for FA 2.3 and worked on it while it was being hammered out. You check the wiki history and the original threads too.

Re: REST API

@apmuthu we have the same definition of 'end user'; installers and maintainers of installations of Front Accounting.

For those in the community who want to use my releases I can assure them that they do not need to concern themselves about composer.  They can download a released zip or tar.gz file from:

https://github.com/cambell-prince/FrontAccountingSimpleAPI/releases

Cambell https://github.com/cambell-prince

Re: REST API

Hi, I'm not sure about paths,

I'm getting:-

Use of undefined constant VARLOG_PATH - assumed 'VARLOG_PATH' in file: /home/path/path/path/config.default.php at line 32

Use of undefined constant VARLOG_PATH - assumed 'VARLOG_PATH' in file: /home/path/path/path/config.php at line 32

include_once(./vendor/autoload.php): failed to open stream: No such file or directory in file: /home/path/path/path/modules/api/index.php at line 41

include_once(): Failed opening './vendor/autoload.php' for inclusion (include_path='.:/opt/alt/php56/usr/share/pear:/opt/alt/php56/usr/share/php') in file: /home/path/path/path/modules/api/index.php at line 41

Class 'Slim\Slim' not found in /home/path/path/path/modules/api/index.php on line 54

Is this defined in File: /home/path/path/path/config_api.php

01: <?php
02: 
03: if (file_exists(__DIR__ . '/_frontaccounting')) {
04:     $rootPath = realpath(__DIR__ . '/_frontaccounting');
05: } else {
06:     $rootPath = realpath(__DIR__ . '/../..');
07: }
08: //Tried this results as above
09: // define('API_ROOT', $rootPath . '/modules/api');
10: // define('FA_ROOT', $rootPath);
11: //tried this same results
12: define('API_ROOT', '.');
13: define('FA_ROOT', './../..');
14: 

Or somewhere else?

What should the path be?

The FrontAccounting Wiki(Manual, examples, tips, setup info, links to accounting sites, etc) https://frontaccounting.com/fawiki/

Re: REST API

This constant was introduced in a recent commit.
Take the diff files (since the release) from here.

Good business for FA consultants wink

49 (edited by s4m3shms 02/11/2018 10:32:26 am)

Re: REST API

cambell wrote:

@apmuthu we have the same definition of 'end user'; installers and maintainers of installations of Front Accounting.

For those in the community who want to use my releases I can assure them that they do not need to concern themselves about composer.  They can download a released zip or tar.gz file from:

https://github.com/cambell-prince/FrontAccountingSimpleAPI/releases

Hello Cambell

I was testing the sales APIs from your latest repository, none of the methods worked for me.

For example:

http://url/modules/api/sales/
or
http://url/modules/api/sales/5

returns nothing.

Whilst other api method are working fine.

Is there any updates?

Regards

50 (edited by cambell 02/12/2018 01:09:30 pm)

Re: REST API

s4m3shms wrote:

I was testing the sales APIs from your latest repository, none of the methods worked for me.

For example:

http://url/modules/api/sales/
or
http://url/modules/api/sales/5

returns nothing.

@s4m3shms The endpoint for the sales url needs to have a transaction type on the end, and its not optional.  So:

http://url/modules/api/sales/10

Have a look at the Sales_Test file to see an example of how to use the api using php.

https://github.com/cambell-prince/FrontAccountingSimpleAPI/blob/master-upstream/tests/Sales_Test.php


would give you all the sales invoices for example.  To get a particular invoice it would be:

http://url/modules/api/sales/5/10

assuming there was an invoice number 5.

Have a look at the Sales_Test.php file to see an example of using the api in php

https://github.com/cambell-prince/FrontAccountingSimpleAPI/blob/master-upstream/tests/Sales_Test.php

Cambell https://github.com/cambell-prince