eBay API: retrieve full item listing by SiteID - ebay-api

Does anyone know how to retrieve a full listing of items by Site (ebay.us, ebay.fr ..) using ebay API?
I am using the Large Merchant Service because I manage thousands of items on each site (about 100k).
https://developer.ebay.com/devzone/large-merchant-services/concepts/lms_apiguide.html
1st solution i have tried (Active Inventory Report) According the doc :
Retrieving an Active Inventory Report
The ActiveInventoryReportRequest allows you to download a description
of all of your active listings by SKU. The SKU details include ItemID,
Price, Quantity, SKU, and SiteID.
I have checked with premium support and there is a mistake, SiteID is never included in response.
2nd solution (GetSellerList)
https://developer.ebay.com/devzone/xml/docs/reference/ebay/GetSellerList.html
According to the docs:
GetSellerList returns a maximum of 5,000 items per call (this is possible if you do not specify a Detail Level, and thus return the
smallest set of data for each item). However, if you specify any
DetailLevel value (and thus increase the fields returned for each
item), you might need to use Pagination values to obtain the complete
result set. If you use a DetailLevel, the response can contain no more
than 200 items per call.
So can not use this one because of limitation to 5000 items and I do not know when items have been added, a few years ago for a bunch of them.
Any ideas?
Regards

You can get lots more than 5,000 results with GetSellerList, but you are right you can only get 200 at a time. The code below is part of a loop iterating through until HasMoreItems is false. The code is written in Perl and uses Net::eBay to connect.
my $result = $eBay->submitRequest( "GetSellerList",
{
UserID => "$ebay_settings{'ebay_account'}",
GranularityLevel => 'Medium',
EndTimeFrom => "$start_time",
EndTimeTo => "$end_time",
Pagination => {
EntriesPerPage => 200,
PageNumber => $page_number
}
}
);
if( ref $result ) {
$result->{HasMoreItems} eq "false" and $done = "Y";
}

Related

Triggering Zapier on new Shopify order containing a specific product

I have a simple Zap that is triggered on a Shopify New Order (with line details) and then creates a new account in a system called Trainerize. Works perfectly, but it is triggered by ANY new Shopify order. I need to trigger the Zap for a specific product in the Shopify order. Is this possible in Zapier, and how would I go about it? It seems you can't talk to Zapier support unless you have a plan, and I don't want a plan if it is not possible!
Yes, it is possible. The exact implementation depends on how you want to identify the specific product. I am listing 2 possible ways
In case, the criteria to identify product is quite simple, you can use Filter by Zap. For example, if you want to identify product by product Id, you can just add a Filter by Zap and add the following conditions.
Line Items Product ID | Text Contains | Your Product ID - 12345
If you have some complex matching condition for your Product, you can also use Code by Zapier to run JavaScript code. To do so, pass the required data as input to code and return output that can be used later to see if the match was found. A simple example that gets LineItems productIds as input.
const TARGET_PRODUCT_ID = 12345;
const productIds = inputData.productIds.split(",");
output = {targetProductFound: false};
productIds.forEach(id => {
// Add more conditions if needed
if(Number(id) === TARGET_PRODUCT_ID){
output.targetProductFound = true;
}
});
return output
Then use Filter to proceed or abort.

How to efficiently retrieve a list of all collections a product belongs to in Shopify?

I want to create a CSV export of product data from a Shopify store. For each product I'm exporting data like the product name, price, image URL etc... In this export I also want to list, for each product, all the collections the product belongs to, preferably in the hierarchal order the collections appear in the site's navigation menu (e.g Men > Shirts > Red Shirts).
If my understanding of the API is correct, for each product I need to make a separate call to the Collect API to get a list of collections it belongs to then another call to the Collections API to get the handle of each collection. This sounds like a lot of API calls for each product.
Is there a more efficient way to do this?
Is there any way to figure out the aforementioned hierarchy of collections?
Unfortunately, as you pointed out, I don't think there is an efficient way of doing this because of the way that the Shopify API is structured. It does not permit collections to be queried from products, rather only products queried from collections. That is, one can't see what collections a product belongs to, but can see what products belong to a collection.
The ShopifyAPI::Collect or ShopifyAPI::Collection REST resource does not return Product variant information, which is needed to get the price information as per the requirements. Furthermore, ShopifyAPI::Collect is limited to custom collections only, and would not work for products in ShopifyAPI::SmartCollection's. For this reason I suggest using GraphQL instead of REST to get the information needed.
query ($collectionCursor: String, $productCursor: String){
collections(first: 1, after: $collectionCursor) {
edges {
cursor
node {
id
handle
products(first: 8, after: $productCursor){
edges{
cursor
node{
id
title
variants(first: 100){
edges{
node{
price
}
}
}
}
}
}
}
}
}
}
{
"collectionCursor": null,
"productCursor": null
}
The $productCursor variable can be used to iterate over all of the products in a collection and the $collectionCursor to iterate over all collections. Note that only the first 100 variants need to be queried since Shopify has a hard limit on 100 variants per product.
The same query can be used to iterate over ShopifyAPI::SmartCollection's.
Alternatively the same query using the REST API would look something like this in Ruby.
collections = ShopifyAPI::Collection.all # paginate
collection.each do |collection|
collection.products.each do |product|
product.title
# note the extra call the Product API to get varint info
ShopifyAPI::Product.find(product.id).variants.each do |varaint|
variant.price
end
end
end
I don't see any way to address the inefficiencies with the REST query, but you might be able to improve on the GraphQL queries by using Shopify's GraphQL Bulk Operations.

How to use Etsy's updateInventory() call to update Stock/Price for a listing

It is not at all clear to me how to update the price/stock for a listing once it has been created initally using listing->createListing().
To update the stock/price, Etsy's documentation says to call listing->updateInventory(). However, this call requires something called products together with a couple of properties (price_on_property, quantity_on_property and sku_on_property):
listing_id
products*
price_on_property
quantity_on_property
sku_on_property
where:
products is further defined in their documentation as a combination of property_values and offerings which I have no clue about.
listing_id is returned from the call to createListing() initially.
Etsy's footnote about price_on_property, stock_on_property and sku_on_property adds to the confusion:
price_on_property is an array of the property_ids of the properties which price depends on (if any).
quantity_on_property is an array of the property_ids of the properties which quantity depends on (if any).
sku_on_property is an array of the property_ids of the properties
which sku depends on (if any).
The update will fail if the supplied values for product sku and offering quantity and price are incompatible with the supplied values of the "on_property_*" fields.
When supplying a price, supply a float equivalent to amount divided by
divisor as specified in the Money resource.
The products parameter should be a JSON array of products, even if you only send a single product. All field names in the JSON blob should be lowercase.
Taken from https://www.etsy.com/developers/documentation/reference/listinginventory#method_updateinventory
Given that the starting point for adding things for sale on Etsy is just to call createListing() with details of the item that I wish to sell (inc stock quantity and price), I do not understand how to call updateInventory() to update the stock and/or price of this item and so can anybody provide some clarity on this matter please (and yes, I have contacted Etsy developer support, but it might take a while for them to respond).
In python - I assume you have the etsy_api module from github.
Etsy product listings have the following structure:
ListingProduct = {
"price_on_property": [
property_ids
],
"products": [
LIST OF PRODUCT VARIATIONS FOR THIS LIST. IF YOU HAVE NO VARIATIONS
THEN THIS LIST WILL HAVE ONLY 1 PRODUCT.
],
"quantity_on_property": [],
"sku_on_property": []
}
To update prices, you need to send back this ListingProduct model, but with the changes you want. Note
price_on_property is required if you have variations.
sku_on_property is optional if you have different skus for different
variations.
quantity_on_property is optional if you have different quantities on
variations.
The easiest way I have found is to do the following:
Get the listing_id for the product you want to change price on.
Make a call to the inventory URI to get this listing. I'm doing this to avoid having to construct ListingProduct['products']. It has too much going on with it.
listing_id = 'the product's listing_id'
ListingProduct = etsy_api.getInventory(listing_id=listing_id)
ListingProduct['products'] is a list of products for this listing. The size of this list is equal to the number of variations that you have.
Take ListingProduct['products'] and for each variation change the price.
If you take a look at ListingProduct['products'], you will see that the changes that need to be done are,
ListingProducts['products'][0]['offerings'][0]['price'] = NewPrice
If a listing has 2 variations, then change the price on that too
ListingProducts['products'][1]['offerings'][0]['price'] = OtherNewPrice
Once you do this make a call with the data.
data = {
'listing_id': listing_id
'products': json.dumps(ListingProduct['products'])
'price_on_property': 200 #If you have variation
}
etsy_api.updateInventory(**data)
To update the variations for a product in ETSY, you need to use update inventory call from the API (Expecting you are using Etsy module from GitHub).
refer to link https://www.etsy.com/developers/documentation/getting_started/inventory
The data you need to send with this call will include --
array (
products => json_encode($products),
price_on_property =>
quantity_on_property =>
)
price_on_property will include the variation property id provided by etsy
quantity_on_property will be included in case of more than one variation attribute
The products index will include an array of variations with the details --
[0] => (
product_id=> 1234,
property_values" => [
property_id => 500,
property_name => color,
'values => [ green ],
],
offerings" => [
(
price => 200
quantity => 1,
)
)
[1] => and so on...
Property Id will be provided by etsy for variation attributes.

Fetch and insert product price on a custom page in BigCommerce

Is it possible to fetch and insert a product price dynamically for a custom page in BigCommerce?
I am creating a custom page detailing specific products in BigCommerce and I would like to be able to fetch the product price for each product from the system instead of manually setting it on the page.
This way if the price is changed for a product the price will of course dynamically change on the custom page.
I know that BigCommerce uses %%GLOBAL_ProductPrice%% to call the price on the product page and in other code throughout the site, but can't figure out how to utilize this on the custom page where I will have multiple products listed.
I really like #tim-diztinct's answer, I would recommend following that if you can.
But otherwise, the alternative/hard way would be to grab the price directly from the live product page using JavaScript.
In BigCommerce, you can quickly get to a product page using one of these two standardized URLs:
1. store_url.com/products.php?product=product name here
2. store_url.com/products.php?productId=productIdHere (my preferred)
So then if you wanted to grab the live price from the product page, you could do an Ajax call to the product page, and parse the content for the price...
/**
* Makes an HTTP GET to an external product page
* and parses that page for the product's current price.
* #param pid <int> - The product ID to search for.
* #return Promise - Resolved with product price, reject on fail.
*/
function getProductPrice(pid) {
// Ensure pid parameter set:
if (typeof pid == 'undefined') {
throw new Error('Missing product ID.');
} else {
// Ensure pid is a non decimal number:
pid = parseInt(pid);
}
// Return promise to contain the results...
return new Promise(function(resolve, reject) {
// Make an Ajax GET request to the product page:
$.get("site_url_here.com/products.php?productId=" +pid, function(res) {
// If request successful:
if (res) {
// The content for the product page is loaded in 'res'.
// The Price should be contained within a meta element within a div containing the class name 'Value'.
// Below, we parse the html response for the meta element containing the price...
resolve($(res).find('.Value > meta'').attr('content'));
// Else request failed:
} else {
reject(false);
}
});
});
}
//** Calling the above function **//
getProductPrice(25).then(function(price) {
// Do something with the price (insert it into your custom page?)
alert('The product price is ' +price);
}).catch(function(e) {
console.log('Error getting product price - ', e);
});
My last piece of advice so you have something to leave with, is that since I imagine you'll have multiple products on your custom page, then you will need to get the prices for each product.
My recommendation is to perhaps include the product ID somewhere related to each product (such as an ID, or a hidden element). Parse all the ID's into an array, so that forEach value you can call the getProductPrice function, and then inject it into the element on your custom page responsible for displaying the price!
Bonus: Save the prices in a cookie that expires every X interval, and read from there for recurring client requests.
/

How to show product quantity in the cart on custom page

I'm using Prestashop 1.5 and created page with list of grouped products. I want to show quantity of each product in the cart. At shopping cart page exist $product.cart_quantity property, but on my page it doesn't. Please, explain me, how to show product quantity in the cart on my page.
Easyest way I can think of is to access the data via cookies since cart data is stored in them.
You can get cookies data like this:
$context = Context::getContext();
echo '<pre>',print_r($context->cookie, true).'</pre>';
Prestashop Context is a registry for PHP variables that were previously accessed as globals. It aims to standardize the way these variables are accessed, and to make the code more robust by getting rid of global vars.
And our echo is just for example to show what info you can get from cookies.
When costumer adds something to the shopping-cart it automatically gives it a cart id (id_cart) and from there it's fairly easy to access to access that value to get all the info.
To get a cart id ( assuming you already got context ) use this
$Cart = $context->cart;
This returns you a ID of a current cart.
Now you want to return the current products in the cart ( with all the information it includes ). For that you have to use the public function located in prestashop_main_folder/classes/cart.php
So to return all the current products just use the following line
$Cart->getProducts($refresh = false, $id_product = false, $id_country = null)
And then it returns you a array with all the variables what you can easily then access.
BR's
You can do the following:
$context=Context::getContext();
$id_cart=$context->cookie->id_cart;
if($id_cart=='') $id_cart=Tools::getValue('id_cart');
$theCart = new Cart($id_cart);
$products = $theCart->getProducts(true);
$nbTotalProducts = 0;
foreach ($products as $product)
{
$nbTotalProducts += (int)$product['cart_quantity'];
}