X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Advice with REST API (https://forum.x-cart.com/showthread.php?t=75159)

johngwms 04-01-2017 06:10 AM

Advice with REST API
 
Hi

I am in the process of evaluating the implications of moving from XC 4.7.5 to XC 5.3.

I plan to use the REST API of XC5 for synchronisation of stock information and the export of new Sales Orders. Order processing will be carried out externally with Zoho Inventory (ZI), and the transfer of data to and from Zoho Inventory will be done using Zapier.

I need to know what is possible and if a Custom Module needs to be written.

Products
Many products will need attributes defined in XC5 and I would like to keep the master versions of these in ZI. The documentation for the REST API does not mention attributes. Does this mean that product attribute data cannot be transferred via the REST API?

Sales Orders
When a customer order is placed on XC5, how can the REST API be used to push the order to ZI? Will it be necessary for ZI to poll the REST API to check for a new order instead?

Access to Custom Module
Can the REST API be used to communicate with a Custom Module?

Any help or suggestions will be warmly received.

qualiteam 04-02-2017 11:27 PM

Re: Advice with REST API
 
Quote:

Originally Posted by johngwms
Products
Many products will need attributes defined in XC5 and I would like to keep the master versions of these in ZI. The documentation for the REST API does not mention attributes. Does this mean that product attribute data cannot be transferred via the REST API?


It is possible to retrieve product attributes, but not in a single REST API request.

First, you should get the product information:
https://[YOUR_STIE]/admin.php?target=RESTAPI&_key=[YOUR_KEY]&_path=product/[PRODUCT_ID]

Then you should iterate over product attributes and get information on every product attribute:
https://[YOUR_SITE]/admin.php?target=RESTAPI&_key=[YOUR_KEY]&_path=attribute/[ATTRIBUTE_ID]

Perhaps, you also should run other requests to get information on which attribute options the product has available.

You will end up with a lot requests per product, so it may make sense to customise the REST API module and add a custom API function that will return all the product's attributes in a single request.

Quote:

Originally Posted by johngwms
Sales Orders
When a customer order is placed on XC5, how can the REST API be used to push the order to ZI? Will it be necessary for ZI to poll the REST API to check for a new order instead?


REST API can be used for pull requests only. Yes, you should poll the API to check for new orders.

Quote:

Originally Posted by johngwms
Access to Custom Module
Can the REST API be used to communicate with a Custom Module?


REST API provides an interface to access the database from third-party applications. You can access database records and fields added by a custom module, but you can't communicate with the module's functions directly (all requests translate to methods defined in Model/Repo classes).

Ashish 04-28-2017 11:29 PM

Re: Advice with REST API
 
How can I modify REST API to get configurable product information?
I have created one order which has configurable product.
Now I want to read that product attributes. How can I read?

qualiteam 05-03-2017 04:19 AM

Re: Advice with REST API
 
REST API is an interface to manipulate data in the database through Repository classes.

So, first you should check the source code and understand what Models (subclasses of \XLite\Model\AEntity) you want to retrieve and how they relate to each other.
They you should run a series of API requests to retrieve the necessary models by their identifiers.
The exact list of requests depends on what exact information you require, so I'm not sure if I can guess it and post there.

When sending a search request, you may filter the data with the _cnd parameters. To find what parameters are available for your models look for prepareCnd***() methods defined in the Repository classes (subclasses of \XLite\Model\Repo\ARepo) that handle operations on models which you need.

fonefun 01-01-2019 02:39 AM

Re: Advice with REST API
 
i already use rest api,

but im installing the Announce module now, and that requires a rest api key (read only)


when i go to the settings on rest api, it does not display any keys


i have 2 questions.

1. do i enter a key manually and match that in my announce login for it to work?

2. if i do the above will it break other connections that i use rest api for, like amazon and ebay. as i dont want to overwrite a working key with the one i enter to get announce working


im asking this as i cannot see anywhere on xcart 5 where any current keys are being used, and im not sure if i can simply add another without affecting existing keys

i hope this make sense

i hope this makes sense

qualiteam 01-05-2019 11:39 AM

Re: Advice with REST API
 
Quote:

Originally Posted by fonefun
i already use rest api,

but im installing the Announce module now, and that requires a rest api key (read only)


when i go to the settings on rest api, it does not display any keys


i have 2 questions.

1. do i enter a key manually and match that in my announce login for it to work?

2. if i do the above will it break other connections that i use rest api for, like amazon and ebay. as i dont want to overwrite a working key with the one i enter to get announce working



1. Yes, you specify your API keys manually, it can be anything you want, if otherwise is not stated in Announce's documentation.

2. I don't think eBay or Amazon use REST API to work with your store. Since you don't have any REST API key specified in the module settings, you are free to enter any key you want.


All times are GMT -8. The time now is 11:16 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.