skip to Main Content

I am trying to use Postman to make a POST request to the Magento API and I am getting back an error message that says:

{“message”:”Unable to save product”}.

Here is the code I am running through Postman.

{
"product":{"sku": "123456","name": "New Shoe","attribute_set_id": 11,"price": "status": "visibility": "type_id": ""created_at": "2016-12-04 15:03:"updated_at": "2016-12-04 15:03:"}

I am running it through a POST request under the /V1/products/ directory. I am able to Get information from the API with the access key I am using so I do not believe that it is an Authorization issue.

I have tried doing the same request changing some of the information using PUT and I am getting the same result. Any suggestions or thoughts would be greatly appreciated!

2

Answers


  1. catalogProductRepositoryV1

    POST /V1/products
    

    Create product

    Body > Data

    {
      "product": {
        "id": 0,
        "sku": "string",
        "name": "string",
        "attributeSetId": 0,
        "price": 0,
        "status": 0,
        "visibility": 0,
        "typeId": "string",
        "createdAt": "string",
        "updatedAt": "string",
        "weight": 0,
        "extensionAttributes": {
          "downloadableProductLinks": [
            {
              "id": 0,
              "title": "string",
              "sortOrder": 0,
              "isShareable": 0,
              "price": 0,
              "numberOfDownloads": 0,
              "linkType": "string",
              "linkFile": "string",
              "linkFileContent": {
                "fileData": "string",
                "name": "string",
                "extensionAttributes": {}
              },
              "linkUrl": "string",
              "sampleType": "string",
              "sampleFile": "string",
              "sampleFileContent": {
                "fileData": "string",
                "name": "string",
                "extensionAttributes": {}
              },
              "sampleUrl": "string",
              "extensionAttributes": {}
            }
          ],
          "downloadableProductSamples": [
            {
              "id": 0,
              "title": "string",
              "sortOrder": 0,
              "sampleType": "string",
              "sampleFile": "string",
              "sampleFileContent": {
                "fileData": "string",
                "name": "string",
                "extensionAttributes": {}
              },
              "sampleUrl": "string",
              "extensionAttributes": {}
            }
          ],
          "stockItem": {
            "itemId": 0,
            "productId": 0,
            "stockId": 0,
            "qty": 0,
            "isInStock": true,
            "isQtyDecimal": true,
            "showDefaultNotificationMessage": true,
            "useConfigMinQty": true,
            "minQty": 0,
            "useConfigMinSaleQty": 0,
            "minSaleQty": 0,
            "useConfigMaxSaleQty": true,
            "maxSaleQty": 0,
            "useConfigBackorders": true,
            "backorders": 0,
            "useConfigNotifyStockQty": true,
            "notifyStockQty": 0,
            "useConfigQtyIncrements": true,
            "qtyIncrements": 0,
            "useConfigEnableQtyInc": true,
            "enableQtyIncrements": true,
            "useConfigManageStock": true,
            "manageStock": true,
            "lowStockDate": "string",
            "isDecimalDivided": true,
            "stockStatusChangedAuto": 0,
            "extensionAttributes": {}
          },
          "giftcardAmounts": [
            {
              "websiteId": 0,
              "value": 0,
              "websiteValue": 0,
              "extensionAttributes": {}
            }
          ],
          "configurableProductOptions": [
            {
              "id": 0,
              "attributeId": "string",
              "label": "string",
              "position": 0,
              "isUseDefault": true,
              "values": [
                {
                  "valueIndex": 0,
                  "extensionAttributes": {}
                }
              ],
              "extensionAttributes": {},
              "productId": 0
            }
          ],
          "configurableProductLinks": [
            0
          ],
          "bundleProductOptions": [
            {
              "optionId": 0,
              "title": "string",
              "required": true,
              "type": "string",
              "position": 0,
              "sku": "string",
              "productLinks": [
                {
                  "id": "string",
                  "sku": "string",
                  "optionId": 0,
                  "qty": 0,
                  "position": 0,
                  "isDefault": true,
                  "price": 0,
                  "priceType": 0,
                  "canChangeQuantity": 0,
                  "extensionAttributes": {}
                }
              ],
              "extensionAttributes": {}
            }
          ]
        },
        "productLinks": [
          {
            "sku": "string",
            "linkType": "string",
            "linkedProductSku": "string",
            "linkedProductType": "string",
            "position": 0,
            "extensionAttributes": {
              "qty": 0
            }
          }
        ],
        "options": [
          {
            "productSku": "string",
            "optionId": 0,
            "title": "string",
            "type": "string",
            "sortOrder": 0,
            "isRequire": true,
            "price": 0,
            "priceType": "string",
            "sku": "string",
            "fileExtension": "string",
            "maxCharacters": 0,
            "imageSizeX": 0,
            "imageSizeY": 0,
            "values": [
              {
                "title": "string",
                "sortOrder": 0,
                "price": 0,
                "priceType": "string",
                "sku": "string",
                "optionTypeId": 0
              }
            ],
            "extensionAttributes": {}
          }
        ],
        "mediaGalleryEntries": [
          {
            "id": 0,
            "mediaType": "string",
            "label": "string",
            "position": 0,
            "disabled": true,
            "types": [
              "string"
            ],
            "file": "string",
            "content": {
              "base64EncodedData": "string",
              "type": "string",
              "name": "string"
            },
            "extensionAttributes": {
              "videoContent": {
                "mediaType": "string",
                "videoProvider": "string",
                "videoUrl": "string",
                "videoTitle": "string",
                "videoDescription": "string",
                "videoMetadata": "string"
              }
            }
          }
        ],
        "tierPrices": [
          {
            "customerGroupId": 0,
            "qty": 0,
            "value": 0,
            "extensionAttributes": {}
          }
        ],
        "customAttributes": [
          {
            "attributeCode": "string",
            "value": "string"
          }
        ]
      },
      "saveOptions": true
    }
    
    Login or Signup to reply.
  2. You can open Magento2 source code, try to find this file vendor/magento/module-catalog/Model/ProductRepository.php:732

    Change last catch to this:

    catch (Exception $e) {
                echo $e->getMessage();
                die();
                throw new CouldNotSaveException(__('Unable to save product'), $e);
            }
    

    You will see what your problem is. Example:
    show exception message

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search