Inhalte aufrufen

Profilbild

WebApi how the update (PATCH) a product/categorie/etc..


  • Bitte melden Sie sich an, um eine Antwort zu verfassen.
10 Antworten zu diesem Thema

#1 TripleNico

TripleNico

    Member

  • Members
  • 11 Beiträge

Geschrieben: 05 September 2019 - 15:41

Dear,
 
I'm really new to SmartStore (Started today) and today i installed SmartStore including the WebApi. With the Web Api i want to sync a other database with SmartStore. This will be done in a Middleware Winform/WPF application. Currently i'm able to GET and POST new stuff but when i want to update (PATCH) then i get an error back:
{
  "odata.error":{
    "code":"Not implemented.","message":{
      "lang":"en-US","value":"This service doesn't support OData requests in the form '~/entityset'."
    }
  }
}

 

This is tested with the example Winform app provided by SmartStore. If i check the OData documentation i'm doing everything OK, so what am i missing here?

 

I'm also wondering if it is possible to set a link to a picture instead of uploading it via de api? (The pictures are already stored on the webserver which runs on SSD so fast read speed) 

 

 

Besides this i was wondering if someone had written a HMAC IAuthenticator extension for the RestSharp DLL? 



#2 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3441 Beiträge

Geschrieben: 05 September 2019 - 15:57

"...so what am i missing here?"
Wrong URL? Example
PATCH http://localhost:1242/odata/v1/Products(1751)
JSON: {"AdminComment":"hello world!"}
 
"I'm also wondering if it is possible to set a link to a picture instead of uploading it via de api?"
No, not yet.

Schöne Grüße aus Düsseldorf,
Marcus Gesing


#3 TripleNico

TripleNico

    Member

  • Members
  • 11 Beiträge

Geschrieben: 05 September 2019 - 16:09

 

"...so what am i missing here?"
Wrong URL? Example
PATCH http://localhost:1242/odata/v1/Products(1751)
JSON: {"AdminComment":"hello world!"}
 

 

Ah, that works! I didn't know you had to add the Id value to the URL. How does this work if you want to update a batch? Is it also possible to set the Id or is this always controlled by SmartStore and should the SKU be used for your own product Id?

 

 

"I'm also wondering if it is possible to set a link to a picture instead of uploading it via de api?"

No, not yet.

 

Ok, so the way to go now is to upload the image using POSTapi/{version}/Uploads/ProductImages ?

 

Is there also any indication on when this static link to file will be available?



#4 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3441 Beiträge

Geschrieben: 06 September 2019 - 11:21

There is no batch update using Web API. If you need this, you should think about an own plugin and write an importer similar to the one of the service project.
 
According to OData specification, the specifier must always be the primary key of the entity. Otherwise you must query using other OData mechanisms like filter.
 
Yes, POST ProductImages is the Web API endpoint for image upload. Setting an image URL is maybe a feature of the Media Manager which we expect for version 4.0.

Schöne Grüße aus Düsseldorf,
Marcus Gesing


#5 TripleNico

TripleNico

    Member

  • Members
  • 11 Beiträge

Geschrieben: 06 September 2019 - 12:08

Thanks for the info, this is very helpfull. Still i got some questions:

 

1. How would one upload PDF, like a datasheet, to a product?

2. How would one set product descriptions in other languages like DE and EN and NL via de API? 



#6 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3441 Beiträge

Geschrieben: 06 September 2019 - 15:13

PDF upload\binding possibility will be available with the mentioned Media Manager. It is recommended to store specification attributes using the entity of the same name so that this data can be searched and filtered.
 
Translations are stored using LocalizedProperty entity. You can see this in action in the backend at the boxes with tabs "Standard", "German", "English" etc. It is also available via the Web API.

Schöne Grüße aus Düsseldorf,
Marcus Gesing


#7 TripleNico

TripleNico

    Member

  • Members
  • 11 Beiträge

Geschrieben: 12 September 2019 - 10:20

Thanks for the info!

 

Since it's all new to me but i'm learning i was wondering what the correct way/order would be to add a new product via the api meaning:

 

- Product default information

- Product Price

- Product EN and NL descriptions

- Product Pictures

- Product PDF

- Product shipping?

 

So only the basic stuff is needed. We have no need for all the other advanced features.



#8 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3441 Beiträge

Geschrieben: 12 September 2019 - 10:36

1. ensure that all delivery times are created.
2. create product including price and delivery time id.
3. create LocalizedProperty for translated field values like product name and product description. You need Product.Id of the created product for it.
4. use ProductImages endpoint to upload product images.
 
By the way, why don't you do a CSV import?

Schöne Grüße aus Düsseldorf,
Marcus Gesing


#9 TripleNico

TripleNico

    Member

  • Members
  • 11 Beiträge

Geschrieben: 13 September 2019 - 10:31

Ah good to know that that is the right order to create a product. And deleting a product is in reverse order? 
 
I noticed then when setting product.Id in the JSON and then Posting a new product the Id isn't taken but instead SmartStore creates it own id, is this correct?

For Example: 

Content-Length: 282
Expect: 100-continue
Connection: Keep-Alive
 
{
  "ProductTypeId": 5,
  "Name": "Cool Product",
  "ShortDescription": "This is a short dessdfdsfdsf",
  "FullDescription": "<p>Long text here</p>",
  "Sku": "1456",
  "Price": "34.95",
  "OldPrice": "44.95",
  "SpecialPrice": "20.56",
  "Published": true,
  "Id": 100
}
Response: 
200 OK
{
  "odata.metadata": "http://shop.domain.nl/odata/v1/$metadata#Products/@Element",  
  "ProductTypeId": 5,
  "ParentGroupedProductId": 0,
  "VisibleIndividually": false,
  "Name": "Cool Product",
  "ShortDescription": "This is a short dessdfdsfdsf",
  "FullDescription": "<p>Long text here</p>",
  "AdminComment": null,
  "ProductTemplateId": 0,
  "ShowOnHomePage": false,
  "HomePageDisplayOrder": 0,
  "MetaKeywords": null,
  "MetaDescription": null,
  "MetaTitle": null,
  "AllowCustomerReviews": false,
  "ApprovedRatingSum": 0,
  "NotApprovedRatingSum": 0,
  "ApprovedTotalReviews": 0,
  "NotApprovedTotalReviews": 0,
  "SubjectToAcl": false,
  "LimitedToStores": false,
  "Sku": "1456",
  "ManufacturerPartNumber": null,
  "Gtin": null,
  "IsGiftCard": false,
  "GiftCardTypeId": 0,
  "RequireOtherProducts": false,
  "RequiredProductIds": null,
  "AutomaticallyAddRequiredProducts": false,
  "IsDownload": false,
  "UnlimitedDownloads": false,
  "MaxNumberOfDownloads": 0,
  "DownloadExpirationDays": null,
  "DownloadActivationTypeId": 0,
  "HasSampleDownload": false,
  "SampleDownloadId": null,
  "HasUserAgreement": false,
  "UserAgreementText": null,
  "IsRecurring": false,
  "RecurringCycleLength": 0,
  "RecurringCyclePeriodId": 0,
  "RecurringTotalCycles": 0,
  "IsShipEnabled": false,
  "IsFreeShipping": false,
  "AdditionalShippingCharge": "0",
  "IsTaxExempt": false,
  "IsEsd": false,
  "TaxCategoryId": 0,
  "ManageInventoryMethodId": 0,
  "StockQuantity": 0,
  "DisplayStockAvailability": false,
  "DisplayStockQuantity": false,
  "MinStockQuantity": 0,
  "LowStockActivityId": 0,
  "NotifyAdminForQuantityBelow": 0,
  "BackorderModeId": 0,
  "AllowBackInStockSubscriptions": false,
  "OrderMinimumQuantity": 0,
  "OrderMaximumQuantity": 0,
  "QuantityStep": 0,
  "QuantiyControlType": "Spinner",
  "HideQuantityControl": false,
  "AllowedQuantities": null,
  "DisableBuyButton": false,
  "DisableWishlistButton": false,
  "AvailableForPreOrder": false,
  "CallForPrice": false,
  "Price": "34.95",
  "OldPrice": "44.95",
  "ProductCost": "0",
  "SpecialPrice": "20.56",
  "SpecialPriceStartDateTimeUtc": null,
  "SpecialPriceEndDateTimeUtc": null,
  "CustomerEntersPrice": false,
  "MinimumCustomerEnteredPrice": "0",
  "MaximumCustomerEnteredPrice": "0",
  "HasTierPrices": false,
  "LowestAttributeCombinationPrice": null,
  "HasDiscountsApplied": false,
  "Weight": "0",
  "Length": "0",
  "Width": "0",
  "Height": "0",
  "AvailableStartDateTimeUtc": null,
  "AvailableEndDateTimeUtc": null,
  "DisplayOrder": 0,
  "Published": true,
  "IsSystemProduct": false,
  "SystemName": null,
  "CreatedOnUtc": "2019-09-13T09:20:00.1805115Z",
  "UpdatedOnUtc": "2019-09-13T09:20:00.1805115Z",
  "DeliveryTimeId": null,
  "QuantityUnitId": null,
  "CustomsTariffNumber": null,
  "CountryOfOriginId": null,
  "BasePriceEnabled": false,
  "BasePriceMeasureUnit": null,
  "BasePriceAmount": null,
  "BasePriceBaseAmount": null,
  "BundleTitleText": null,
  "BundlePerItemShipping": false,
  "BundlePerItemPricing": false,
  "BundlePerItemShoppingCart": false,
  "MainPictureId": null,
  "HasPreviewPicture": false,
  "ProductType": "SimpleProduct",
  "BackorderMode": "NoBackorders",
  "DownloadActivationType": "0",
  "GiftCardType": "Virtual",
  "LowStockActivity": "Nothing",
  "ManageInventoryMethod": "DontManageStock",
  "RecurringCyclePeriod": "Days",
  "Id": 17
}

 
 As you can see i post a new product with ID 100 and get a response back saying it is added and has ID 17?
 
 

By the way, why don't you do a CSV import?

 
Well the reason why no CSV import is because the Middleware application would constantly sync our CRM/ERP system with the store. Meaning that after the initial sync with our CRM/ERP system to the webshop it then has to maintain products, categories, users and order information. The webshop has to be seen as a service we provide for our B2B customers and subdealers so they can check pricing and stuff but our CRM/ERP system we use is leading(Because webshop is just 3% of our revenue), so the webshop must slave to it.
 
In the live situation it would be like:

 

Event CRM/ERP system product added/changed/deleted --> Action: Update webshop by adding/updating/deleting product.

Or

Webshop event(by receiving email):User has placed webshop order placed --> Action: Get new order info and create new order in CRM/ERP system which tels a employee to handle this new order.

 
This also applies for customers, these must match the customer profiles in our CRM/ERP system.

 

**** EDIT ****

I now see that the import module is very powerfull and could also be scheduled, i will playarround with this features to see if it wroks for importing products and stuff. What i do mis is the import for brands? And how can you import/add images and PDF to a product? We now copy the image to the ImportProfile root with the filename as: %SKU%_1.jpg for one picture and _2 for the second etc...



#10 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3441 Beiträge

Geschrieben: 13 September 2019 - 13:02

"And deleting a product is in reverse order?"
Yes, except that primary entities like products are not physically deleted but marked as deleted.
 
"...a new product the Id isn't taken but instead SmartStore creates it own id, is this correct?"
Yes, SQL Server is creating it. You cannot change primary keys.
 
"... because the Middleware application would constantly sync our CRM/ERP system with the store"
Although the Web API is a suitable tool for this scenario, I probably wouldn't use it here. If the data exchange occurs very frequently and possibly larger amounts of data are processed, I would prefer a new plugin, which manages the data exchange between shop and CRM/ERP. Such a solution is faster, more flexible, more long-sighted and easier to handle with a view to future upgrades. With a view to Services.Catalog.Importer.ProductImporter, you can use existing import code instead of redeveloping it.

Schöne Grüße aus Düsseldorf,
Marcus Gesing


#11 TripleNico

TripleNico

    Member

  • Members
  • 11 Beiträge

Geschrieben: 26 September 2019 - 13:19

There won't be much traffic, only once a night the databases wil sync. However the user will have a SYNC NOW button to force a sync but this would only be in rare cases. Also their won't be much products <5000. So i think the Import function is the simpelst way to go for now. I'm creating a test app to see what i'm missing and and got some stuff:

  1. How can i add categories to a product?
  2. How can i add PDF to a product?
  3. Is there also a Import Brand profile?

 

Besides this i noticed i would also need the webapi to do a little more custom stuff, no problem but i was wondering if there is a C#/VB.Net code example of how to upload a new image for a product / Brand / Category