Inhalte aufrufen

Profilbild

Add a New Product via API

api adding new product

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

#1 Fedor

Fedor

    Newbie

  • Members
  • Punkt
  • 7 Beiträge

Geschrieben: 16 September 2020 - 15:34

Hello,

 

I am trying to add a new product via API.

I suppose, it should be a very straight forward procedure but I cannot find a clear example of it. 

 

Here is the request: 

 

POST http://{store url}/odata/v1/Products

 

JSON:

{

"ProductTypeId": 1,

"Name": "New Product",

"ShortDescription": "This is a short description",

"FullDescription": "<p>Long text here</p>",

"Sku": "1234",

"Price": "14.95",

"OldPrice": "11.95",

"SpecialPrice": "13.56",

"Published": true,

Id": 100

}

 

then I am getting the following response:

 

Response: 400 Bad Request

{
  "odata.error":{
    "code":"","message":{
      "lang":"en-US","value":"Missing client paging. Please specify odata $top query option. Maximum value is 120."
    }
  }
}

 

If I add "$top query option" ... it's treated as a GET request and return the list of existing products. 

 

Please help clarify what am I doing wrong here? 

 

Thank you!

 

 

 

 
 


#2 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3831 Beiträge

Geschrieben: 16 September 2020 - 18:36

I cannot reproduce that. Please specify all product fields when using POST method. You can use a GET request to get a full, JSON formatted list of all product fields by its response.


Marcus Gesing

Smartstore AG


#3 Fedor

Fedor

    Newbie

  • Members
  • Punkt
  • 7 Beiträge

Geschrieben: 16 September 2020 - 20:44

I have requested all product fields from an existing (just created manually) product by using using GET request.

Then specified it when repeated a POST request but the response is the same... perhaps I am not follow a correct sequnce requiered when creating a New Product. 

 

Pease take a look at the screenshoot and JSON file enclosed. 

 

Angehängte Datei  Screenshot_2020-09-16_01.png   515.1K   0 Anzahl Downloads

 

 



#4 Fedor

Fedor

    Newbie

  • Members
  • Punkt
  • 7 Beiträge

Geschrieben: 16 September 2020 - 20:46

JSON body:

 

{
  "AdditionalShippingCharge": "0.0000",
  "AdminComment": null,
  "AllowBackInStockSubscriptions": false,
  "AllowCustomerReviews": true,
  "AllowedQuantities": null,
  "ApprovedRatingSum": 0,
  "ApprovedTotalReviews": 0,
  "AutomaticallyAddRequiredProducts": false,
  "AvailableEndDateTimeUtc": null,
  "AvailableForPreOrder": false,
  "AvailableStartDateTimeUtc": null,
  "BackorderMode": "NoBackorders",
  "BackorderModeId": 0,
  "BasePriceAmount": null,
  "BasePriceBaseAmount": null,
  "BasePriceEnabled": false,
  "BasePriceMeasureUnit": null,
  "BundlePerItemPricing": false,
  "BundlePerItemShipping": false,
  "BundlePerItemShoppingCart": false,
  "BundleTitleText": null,
  "CallForPrice": false,
  "Condition": "New",
  "CountryOfOriginId": null,
  "CreatedOnUtc": "2020-09-16T16:03:16.8",
  "CustomerEntersPrice": false,
  "CustomsTariffNumber": null,
  "DeliveryTimeId": 4,
  "DisableBuyButton": false,
  "DisableWishlistButton": false,
  "DisplayOrder": 0,
  "DisplayStockAvailability": false,
  "DisplayStockQuantity": false,
  "DownloadActivationType": "WhenOrderIsPaid",
  "DownloadActivationTypeId": 1,
  "DownloadExpirationDays": null,
  "FullDescription": null,
  "GiftCardType": "Virtual",
  "GiftCardTypeId": 0,
  "Gtin": null,
  "HasDiscountsApplied": false,
  "HasPreviewPicture": false,
  "HasSampleDownload": false,
  "HasTierPrices": false,
  "HasUserAgreement": false,
  "Height": "0.0000",
  "HideQuantityControl": false,
  "HomePageDisplayOrder": 0,
  "Id": 10,
  "IsDownload": false,
  "IsEsd": false,
  "IsFreeShipping": false,
  "IsGiftCard": false,
  "IsRecurring": false,
  "IsShipEnabled": true,
  "IsSystemProduct": false,
  "IsTaxExempt": false,
  "Length": "0.0000",
  "LimitedToStores": false,
  "LowestAttributeCombinationPrice": null,
  "LowStockActivity": "Nothing",
  "LowStockActivityId": 0,
  "MainPictureId": null,
  "ManageInventoryMethod": "DontManageStock",
  "ManageInventoryMethodId": 0,
  "ManufacturerPartNumber": null,
  "MaximumCustomerEnteredPrice": "1000.0000",
  "MaxNumberOfDownloads": 10,
  "MetaDescription": null,
  "MetaKeywords": null,
  "MetaTitle": null,
  "MinimumCustomerEnteredPrice": "0.0000",
  "MinStockQuantity": 0,
  "Name": "My 3nd Product Added",
  "NotApprovedRatingSum": 0,
  "NotApprovedTotalReviews": 0,
  "NotifyAdminForQuantityBelow": 0,
  "OldPrice": "0.0000",
  "OrderMaximumQuantity": 100,
  "OrderMinimumQuantity": 1,
  "ParentGroupedProductId": 0,
  "Price": "0.0000",
  "ProductCost": "0.0000",
  "ProductTemplateId": 1,
  "ProductType": "SimpleProduct",
  "ProductTypeId": 5,
  "Published": true,
  "QuantityStep": 0,
  "QuantityUnitId": null,
  "QuantiyControlType": "Spinner",
  "RecurringCycleLength": 100,
  "RecurringCyclePeriod": "Days",
  "RecurringCyclePeriodId": 0,
  "RecurringTotalCycles": 10,
  "RequiredProductIds": null,
  "RequireOtherProducts": false,
  "SampleDownloadId": null,
  "ShortDescription": null,
  "ShowOnHomePage": false,
  "Sku": null,
  "SpecialPrice": null,
  "SpecialPriceEndDateTimeUtc": null,
  "SpecialPriceStartDateTimeUtc": null,
  "StockQuantity": 10000,
  "SubjectToAcl": false,
  "SystemName": null,
  "TaxCategoryId": 1,
  "UnlimitedDownloads": true,
  "UpdatedOnUtc": "2020-09-16T16:03:16.8",
  "UserAgreementText": null,
  "Visibility": "Full",
  "Weight": "0.0000",
  "Width": "0.0000"



#5 Fedor

Fedor

    Newbie

  • Members
  • Punkt
  • 7 Beiträge

Geschrieben: 16 September 2020 - 21:45

Please can you provide me with some comments regarding this post as well: 

http://community.sma...ieetc/?p=277998

 

I have been trying to replicate the "Posting a New product" that metioned in conversation but cannot get the same results. 

 

Thank you!  



#6 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3831 Beiträge

Geschrieben: 16 September 2020 - 23:54

Please remove the ID field and try again.


Marcus Gesing

Smartstore AG


#7 Fedor

Fedor

    Newbie

  • Members
  • Punkt
  • 7 Beiträge

Geschrieben: 17 September 2020 - 00:42

Just removed an "ID field"... but it doesn't help. 

 

At the same time, it is important to mention that PATCH request works good, and it does its job updating a "ShortDescription" fileld, for example. Please see the 2nd screenshot. 

 

What should I amend in POST request? 

 

 

POST Request doesn't work  

 

Angehängte Datei  Screenshot_2020-09-17_01.png   523.27K   1 Anzahl Downloads

 

 

PATCH Request works ok! 

 

Angehängte Datei  Screenshot_2020-09-17_02.png   839.24K   0 Anzahl Downloads



#8 Fedor

Fedor

    Newbie

  • Members
  • Punkt
  • 7 Beiträge

Geschrieben: 17 September 2020 - 00:44

A full JSON body is here: 

 

{  "AdditionalShippingCharge": "0.0000",  "AdminComment": null,  "AllowBackInStockSubscriptions": false,  "AllowCustomerReviews": true,  "AllowedQuantities": null,  "ApprovedRatingSum": 0,  "ApprovedTotalReviews": 0,  "AutomaticallyAddRequiredProducts": false,  "AvailableEndDateTimeUtc": null,  "AvailableForPreOrder": false,  "AvailableStartDateTimeUtc": null,  "BackorderMode": "NoBackorders",  "BackorderModeId": 0,  "BasePriceAmount": null,  "BasePriceBaseAmount": null,  "BasePriceEnabled": false,  "BasePriceMeasureUnit": null,  "BundlePerItemPricing": false,  "BundlePerItemShipping": false,  "BundlePerItemShoppingCart": false,  "BundleTitleText": null,  "CallForPrice": false,  "Condition": "New",  "CountryOfOriginId": null,  "CreatedOnUtc": "2020-09-16T16:03:16.8",  "CustomerEntersPrice": false,  "CustomsTariffNumber": null,  "DeliveryTimeId": 4,  "DisableBuyButton": false,  "DisableWishlistButton": false,  "DisplayOrder": 0,  "DisplayStockAvailability": false,  "DisplayStockQuantity": false,  "DownloadActivationType": "WhenOrderIsPaid",  "DownloadActivationTypeId": 1,  "DownloadExpirationDays": null,  "FullDescription": null,  "GiftCardType": "Virtual",  "GiftCardTypeId": 0,  "Gtin": null,  "HasDiscountsApplied": false,  "HasPreviewPicture": false,  "HasSampleDownload": false,  "HasTierPrices": false,  "HasUserAgreement": false,  "Height": "0.0000",  "HideQuantityControl": false,  "HomePageDisplayOrder": 0,  "IsDownload": false,  "IsEsd": false,  "IsFreeShipping": false,  "IsGiftCard": false,  "IsRecurring": false,  "IsShipEnabled": true,  "IsSystemProduct": false,  "IsTaxExempt": false,  "Length": "0.0000",  "LimitedToStores": false,  "LowestAttributeCombinationPrice": null,  "LowStockActivity": "Nothing",  "LowStockActivityId": 0,  "MainPictureId": null,  "ManageInventoryMethod": "DontManageStock",  "ManageInventoryMethodId": 0,  "ManufacturerPartNumber": null,  "MaximumCustomerEnteredPrice": "1000.0000",  "MaxNumberOfDownloads": 10,  "MetaDescription": null,  "MetaKeywords": null,  "MetaTitle": null,  "MinimumCustomerEnteredPrice": "0.0000",  "MinStockQuantity": 0,  "Name": "My 3nd Product Added",  "NotApprovedRatingSum": 0,  "NotApprovedTotalReviews": 0,  "NotifyAdminForQuantityBelow": 0,  "OldPrice": "0.0000",  "OrderMaximumQuantity": 100,  "OrderMinimumQuantity": 1,  "ParentGroupedProductId": 0,  "Price": "0.0000",  "ProductCost": "0.0000",  "ProductTemplateId": 1,  "ProductType": "SimpleProduct",  "ProductTypeId": 5,  "Published": true,  "QuantityStep": 0,  "QuantityUnitId": null,  "QuantiyControlType": "Spinner",  "RecurringCycleLength": 100,  "RecurringCyclePeriod": "Days",  "RecurringCyclePeriodId": 0,  "RecurringTotalCycles": 10,  "RequiredProductIds": null,  "RequireOtherProducts": false,  "SampleDownloadId": null,  "ShortDescription": null,  "ShowOnHomePage": false,  "Sku": null,  "SpecialPrice": null,  "SpecialPriceEndDateTimeUtc": null,  "SpecialPriceStartDateTimeUtc": null,  "StockQuantity": 10000,  "SubjectToAcl": false,  "SystemName": null,  "TaxCategoryId": 1,  "UnlimitedDownloads": true,  "UpdatedOnUtc": "2020-09-16T16:03:16.8",  "UserAgreementText": null,  "Visibility": "Full",  "Weight": "0.0000",  "Width": "0.0000"}



#9 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3831 Beiträge

Geschrieben: 17 September 2020 - 12:17

Strange. Works in a test shop with exactly the same product data. Even at my localhost site under the new OData V4 API it works correctly (with slightly changed JSON formatting). Does the host allow POST to this URL? Sounds like there is a redirecting to the corresponding GET method.

Angehängte Bilder


Marcus Gesing

Smartstore AG


#10 Fedor

Fedor

    Newbie

  • Members
  • Punkt
  • 7 Beiträge

Geschrieben: 18 September 2020 - 09:43

Regarding the host: 

AWS EC2 (Win Server SQL) host works good with POST requests to another API within the same IIS (with different Url but the same security setting of the instance). 

 

1) Where can I check the host settings?   

2) How can I identify that there is a redirection from POST to the corresponding GET method?  As there is no errors or Bad request messages...  

 

Any suggestions which way can I go to fix the problem? 

Thank you! 




Auch markiert mit einem oder mehrerer dieser Schlüsselwörter: api, adding new product