In Strapi i can get a specific product but how do I get ALL products? - api

I set up a product collection type, added three records and in the browser type
localhost:1337/api/products/2 and it correctly displays record 2:
{"data":{"id":2,"attributes":{"title":"Gillette Razor","price":9.99,"description":"/assets/product-images/product-2.png","featured":true,"createdAt":"2022-08-20T12:23:10.685Z","updatedAt":"2022-08-20T12:29:45.062Z","publishedAt":null}},"meta":{}}
(also works for /1 and /3, showing those products).
But, when I try to see ALL products by typing:
localhost:1337/api/products I get:
{"data":[],"meta":{"pagination":{"page":1,"pageSize":25,"pageCount":0,"total":0}}}
I have given "public" access to "find" and "findOne". Server is running. Why is it not producing a list of the three products entered?

The solution was the data has to be "published" (default is "draft") for the /api/products to show all records, even though the /api/products/x had no issue revealing product x details without being published.
After marking the data as published localhost:1337/api/products now gives me ALL of my products:
{"data":[{"id":1,"attributes":{"title":"razor blade","price":1.99,"description":"/assets/product-images/product-1.png","featured":false,"createdAt":"2022-08-20T12:22:12.498Z","updatedAt":"2022-08-20T15:37:08.598Z","publishedAt":"2022-08-20T15:37:08.597Z"}},{"id":2,"attributes":{"title":"Gillette Razor","price":9.99,"description":"/assets/product-images/product-2.png","featured":true,"createdAt":"2022-08-20T12:23:10.685Z","updatedAt":"2022-08-20T15:37:01.649Z","publishedAt":"2022-08-20T15:37:01.648Z"}},{"id":3,"attributes":{"title":"Barber Razor","price":7.99,"description":"/assets/product-images/product-3.png","featured":null,"createdAt":"2022-08-20T12:23:52.749Z","updatedAt":"2022-08-20T15:36:52.579Z","publishedAt":"2022-08-20T15:36:52.577Z"}}],"meta":{"pagination":{"page":1,"pageSize":25,"pageCount":1,"total":3}}}

Related

Struggling to import analyst share price to GoogleSheets

I am trying to create a column that imports the analyst price target from TipRanks website.
I uploaded two images:
Image 1: you can see the cell that I want to import.
Image 2: you can see my function that doesn't work.
What should I change in order to get this live info?
Thanks.
The site you are checking is actually "javascript" generated thus import functions won't properly work on them.
To check, just try to import the whole site data. If it returns a javascript function, then it is javascript generated.
Sample (tipranks.com)
What you can do is actually try to find other sites that provide the same data.
I did find one with the same data you are looking for, 50.38 for csiq. Link is "https://www.marketwatch.com/investing/stock/csiq/analystestimates". And since data is shown as table, it would be easier to import using importhtml.
Cell formula is:
=INDEX(IMPORTHTML("https://www.marketwatch.com/investing/stock/csiq/analystestimates", "table", 5), 2, 2)
Sample output:
The table is the fifth one in the DOM, and INDEX(table, 2, 2) means getting the 2nd row 2nd column of the table.
If the site is no good for you, you can try finding other sites that would suit your needs. And then use either importhtml or importxml depending on the site structure.
When you inspect the network when the website is loading you will see that the prices come when calling the forecast endpoint https://www.tipranks.com/stocks/tsla/forecast. This in turn returns an html response which is probably generated with Javascript on the client because they use React on the frontend, but you can still see the preview in the Network tab of the browser dev tools.
You can then copy the preview in VSCode and prettify it, to try and pin point the span holding the price. Of course it won't be exact science, because the html tags are generated with some media queries, but you will get close enough to some extent.
After you get the xml path but you get an empty error, you can delete some tags until you get some text. Use search in google sheets to search for highest price label, and than continue adding tags until you get the desired value.
Here is what I managed to get:
Lowest price target:
=importxml("https://www.tipranks.com/stocks/snow/forecast", "/html/body/div[1]/div[1]/div[4]/div[1]/div[2]/div[1]/div[4]/div[2]/div[2]/div[4]/div[1]/div[1]/div[5]/span[2]")
Average price target:
=importxml("https://www.tipranks.com/stocks/snow/forecast", "/html/body/div[1]/div[1]/div[4]/div[1]/div[2]/div[1]/div[4]/div[2]/div[2]/div[4]/div[1]/div[1]/div[3]/span[2]")
Highest price target:
=importxml("https://www.tipranks.com/stocks/snow/forecast", "/html/body/div[1]/div[1]/div[4]/div[1]/div[2]/div[1]/div[4]/div[2]/div[2]/div[4]/div[1]/div[1]/div[1]/span[2]")
In time these methods might change depending on their development process, but you could use the above steps to update the script.
P.S. I wasn't satisfied with the marketwatch analyst price targets. I think the wisdom of the crowd is better on tipranks.
Try this one. Works perfectly fine on my personal Stock Portfolio on Google Sheets:
Lowest Price Target:
=importxml(CONCATENATE("https://www.tipranks.com/stocks/", A1,"/forecast"), "//*[#class='colorpurple-dark ml3 mobile_fontSize7 laptop_ml0']")
Average Price Target:
=importxml(CONCATENATE("https://www.tipranks.com/stocks/", A4,"/forecast"), "//*[#class='colorgray-1 ml3 mobile_fontSize7 laptop_ml0']")
Highest Price Target:
=importxml(CONCATENATE("https://www.tipranks.com/stocks/", A4,"/forecast"), "//*[#class='colorpale ml3 mobile_fontSize7 laptop_ml0']")

CSV Imported categories not listed in PrestaShop Catolog->Categories

I am using PrestaShop Version 1.6.1.4.
I have created a CSV for Categories and uploaded it successfully but the catogories and the sub-categories are not shown in Catolog->Categories. When I configure a Module "Top Horizontal Menu" in that under Available items Categories can be seen and added to UI as well. When I click on the category in UI 404 error pages comes.
Any idea how to fix this?
Thanks in advance.
The below image is from Top Horizontal Menu Module where JEWELLERY is category and the other below them are sub category.
Thw below image shows that the categories CSV is uploaded successfdully
But it is not listed under Catolog->Categories refer the below image for this
First when I added categories from CSV, the categories is not getting displayed in Catalog->Categories but when I add one category manually then it is displayed in Catalog->Categories but cannot add subcategories to it.
I think there should be some issues in Presta Shop.
For example : I manually added "Testing" as one category. It was added as main category by default. Then both "Home" and "Testing" categories can be seen in Catalog ->Categories.
After this I tried to add the subcategories to "Home" categories through CSV, it worked out.
PrestaShop is expecting the category to be listed in Catalog->Categories to add the subcategories to it even if that particular category is in DB.
Now I can add the sub categories to what ever Main Categories needed and also the products are also getting listed under the subcategories through CSV.
But I dont know why it is not getting added to Catalog->Categories initially when I add from CSV.
Now in DB ps_category table the records are as expected as you have listed.
This is the default Prestashop categories (table ps_category). Please check if you have only one row with is_root_category = 1. This must be a category ID 2 (id_category = 2), your site Home category.
And please check if all three categories ID 1, 2, 3 in your table looks the same in columns id_parent, id_shop_default, level_depth, is_root_category.

eBay SDK AddItem new ProductDetails EAN Requirements CANNOT List Or Revise

I've asked this question on an eBay forum already, but you have been very helpful, so probably worth posting here too.
Over the past few days I have realised that for many categories in which I sell, EANs are becoming required. I have been trying to update my eBay integration to take this into account, but have run into problems.
The additions to my code provide a workflow, and have problems as follows:
I sell musical instruments and accessories, so let's take a typical example a product "Boss CS-3 Compression Pedal", here's a link to a seller listing it: http://www.ebay.co.uk/itm/231547986565
The EAN is 4957054012854
I want to list this in "Musical Instruments > Guitars & Basses > Accessories > Effects Pedals" Category ID for this is: 41410
So, as I understand it, the first thing I need to know is whether EAN is a requirement for this Category. So, using the eBay .NET SDK I run a post to GetCategoryFeatures requesting the following feature IDs:
BrandMPNIdentifierEnabled,
EANEnabled,
UPCEnabled,
ISBNIdentifierEnabled
The response gives me, amongst other things:
EANEnabled: Required,
ISBNEnabled: Disabled,
UPCEnabled: Disabled,
BrandMPNIdentifierEnabled: False
This indicates to me that the EAN is a required ProductDetails value to include in the AddItem post.
So now I need to know if the EAN for this item exists in the eBay Catalogue, so I do a post to findItemsByProduct in the FindingService. I post to this URL:
http://svcs.ebay.com/services/search/FindingService/v1?SECURITY-APPNAME=[MY-APP-ID]&OPERATION-NAME=findItemsByProduct&GLOBAL-ID=EBAY-GB&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON&REST-PAYLOAD&productId.#type=EAN&productId=4957054012854&paginationInput.entriesPerPage=1
The responses ack field is "Failure", which, from what I have gleaned from various internet posts tells me that the item is not found in the eBay Catalogue. Why? I don't know, as the listing example I give above shows the EAN in the Item Specifics fields... but anyway...
So, armed with this information, I can find only the advice that I should replaced the EAN value with a value returned from a post to GeteBayDetails, the value being found as ProductIdentifierUnavailableText which, in my instance (for eBay UK) reads "Does not apply".
Now, I build my item as usual and add the ProductDetails value as follows (in VB.net):
Dim ProductDetails As New ProductListingDetailsType With {
.EAN = "Does not apply"
}
I also note the requirement for an MPN and add that (it returned an error if not provided)
When I list it, I get a Failure response with the following error:
No product found for ProductListingDetails.<EAN> <Does not apply>.
If I take away the ProductDetails I get:
Required field, EAN, is missing. Please add EAN to the listing and retry, so clearly, I do need to provide this information.
I get exactly the same problem trying to revise a listing.
I have tried adding the EAN in the ItemSpecifics object instead of ProductDetails, but that returns the "EAN Missing" error, and have tried alternating between including one, or the other, or both.
So my questions are:
1: Can someone please explain to me what I am doing wrong and how I go about rectifying it, because at the moment I cannot list, or revise items on eBay at all!
2: Since most of my suppliers provide a UPC, not an EAN, am I to take it literally that the idetifier to be provided MUST be an EAN? Or can I provide the UPC field instead?
Hope this saves someone some time on the addItem and reviseItem call (it took me a while to work out)
I managed to make it work using
<ProductListingDetails>
<EAN>Does not apply</EAN>
</ProductListingDetails>
You can add following into your XML
<VariationProductListingDetails>
<EAN>$EAN</EAN>
</VariationProductListingDetails>

Magento API Rest filters

So I have this piece of code below which will sucessfully pull a product and give the XML data for my magento store...
http://mywebsite.com/api/rest/products?type=rest&filter[1][attribute]=name&filter[1][in]=test%20product%20name
However, it will ONLY pull up the product info if I make the product name perfect. If I try to just put in
http://mywebsite.com/api/rest/products?type=rest&filter[1][attribute]=name&filter[1][in]=test
It will not bring ANY products. It was my understanding that if I used the "[in]" filter that it should bring up all products containing the "test" word but it doesnt...
in - "equals any of" - returns items that are equal to the item(s) with the specified attribute(s)
Try to use 'like' ...
http://mywebsite.com/api/rest/products?type=rest&filter[1][attribute]=name&filter[1][like]=%test%

Magento API creates simple product correct -> but afterwards tells "101 Product not exists"

I try to add some pictures to a simple product, which was created (without error) by the API. The product is shown in frontend its functional with all wanted attributes. But if I check afterwards
$client->call($sessionId, 'product.info', '123456');
I get Soap Error: "101: Product doesn't exists". But its definitivly reachable over back- and frontend. (Cache cleared, Index refreshed)
Same issue, when I try to add media informations. On Confugurable Products the error don't show up and the pictures are added whithout any problems.
Maybe I messed something up with the attributes or the attribut sets... I don't know, where to watch first.
I'm at my php’s end!
Using Magento 1.6.0.0
Thank your for clarify me.
Best regards.
Since the ame API function ("product.info" in this case) receive as a parameter both SKU and ID, there is a problem if your are looking for SKU's which is numeric values.
To avoid this problem, we always adding space to the end of SKU before sending it to the API. For example, if your SKU is "123456" you should send "123456 " to the API.
Have you tried this call with your product id instead of the sku? I had some problems in the past with product calls and the sku.
I've installed 2 magentos and we always use numeric SKUs and I've always had this problem.
I've solved it by modifying the file:
app/code/core/Mage/Catalog/Model/Api/Resource.php
About line 122 that reads:
$product = Mage::helper('catalog/product')->getProduct($productId, $this->_getStoreId($store), $identifierType);
I've changed it to:
$product = Mage::helper('catalog/product')->getProduct($productId, $this->_getStoreId($store), 'sku');
This way the function always expects an SKU.