Forum
Perch Shop Product Importer API
Hello,
I am trying to test the Product Importer API. I set up a perch installation from scratch, installed Perch Shop and added Shop and Members to my apps.php
.
Just used the sample script:
<?php
include('/perch/runtime.php');
$API = new PerchAPI(1.0, 'my_importer');
$Importer = $API->get('PerchShopProductImporter');
try {
$Importer->add_item([
'sku' => 'TSHIRT01',
'title' => 'My first t-shirt',
'slug' => 'my-first-t-shirt',
'description' => 'This is a really smashing t-shirt.',
'image_assetID' => 630,
'img_desc' => 'An image of the product',
'status' => true,
'brand' => 1,
'category' => 'products/clothes/',
'catalog_only' => false,
'price' => ['gbp' => 10, 'eur'=>12, 'usd'=>13],
'sale_price' => ['gbp' => 8, 'eur'=>10, 'usd'=>11],
'trade_price' => ['gbp' => 7, 'eur'=>9, 'usd'=>10],
'on_sale' => false,
'tax_group' => 1,
'stock_status' => '1',
'stock_level' => '199',
'stock_location' => true,
'max_in_cart' => 10,
'requires_shipping' => true,
'weight' => 100,
'width' => 20,
'height' => 15,
'depth' => 30,
]);
} catch (Exception $e) {
die('Error: '.$e->getMessage());
}
?>
But all I get is a HTTP 500 error and no added product. What am I missing?
What's the error message you're getting?
I am just getting a blank page, can't see the debug
Hello Mike,
At this point you need to check your error logs: https://docs.grabaperch.com/perch/building/troubleshooting/why-am-i-getting-a-blank-page/
I think you also need to complete the Shop configuration before you can import products. From the installation guide:
https://docs.grabaperch.com/addons/shop/installation/
Hello Hussein,
I did complete the shop installation and can add a product. The problem happens from this line:
When removing everything to this line I get my normal HTML output, but from this line of code I only get a blank screen.
What error(s) do you see in your error logs?
My error logs are empty, is that possible?
It's possible, but not likely. If you can't get PHP to log, consider turning on the display of error messages in your php.ini.
Oh, I did find something, was looking in the wrong place.
Maybe this could be of some help:
Do you get an error for this path? It looks incorrect.
Well, I was using
because with this path I got the HTTP 500 error:
Perch is installed like I always do
If this is a routed Runway master page then you shouldn't need either.
Sorry it is a normal Perch installation. With the document_root line I don't get the error.
Anyone?
Is this not resolved then? You were saying you were no longer getting the error.
Hi Drew,
No I was talking about the runtime include. I get a HTTP 500 error when using
include('/perch/runtime.php');
,and when usinginclude($_SERVER['DOCUMENT_ROOT'].'/perch/runtime.php');
I don't get the HTTP 500 error, but just a blank page. Nothing is happening in the backend. I think I am not able to call the API for some reason. Also tried it on an other install of shop I had on another website, I can't get the products to be added.All code after the
$API = new PerchAPI(1.0, 'my_importer');
doesn't get output.Okay let's start over with my explanation, because It is getting vague at this point.
I have a website using Perch with a working shop installation. When I manually add a product with: - Title: Bike - SKU: BIKE - Slug: bike-bike
the product is being added.
Now I would like to test the Perch Shop product importer API to add this product using the API.
My code:
Now I can only see my top layout being output, nothing else. Also no product is added. So something is wrong with calling the API. What could be the problem?
You can't use content importers with Perch. You need to use Perch Runway for that.
Maybe it would be better to add to the top of the documentation that it is for Runway only (https://docs.grabaperch.com/api/import/shop/products/). I now spent a couple of hours figuring it out, because I thought it was suitable for both.
Thank you anyway for the help.
Mike... on the initial page for
Importing Content
... https://docs.grabaperch.com/api/import/Importing Content
Perch
Runway
provides a number of APIs for importing content directly into the system and into supporting add-ons. This can be useful when migrating content from a different system or reading content from a file.If you have enough products that you need to programatically manage them then you should be using Runway, not Perch.