Skip to content

Shopizer API error: java.lang.NullPointerException: Product must not be null #629

Open
@itonyeig

Description

@itonyeig

I am trying to make a post request with Shopizer's API to create a new porduct.

I can easily create a product through shopizer's admin interface, however, there are certain fields that can only be created through the API.

According to shopizer's swagger docs here you need the following JSON object in your post request to create a product:

{
  "attributes": [
    {
      "attributeDefault": true,
      "attributeDisplayOnly": true,
      "id": 0,
      "option": {
        "code": "string",
        "id": 0,
        "readOnly": true,
        "type": "string"
      },
      "optionValue": {
        "code": "string",
        "defaultValue": true,
        "id": 0,
        "image": "string",
        "name": "string",
        "sortOrder": 0
      },
      "productAttributePrice": 0,
      "productAttributeWeight": 0,
      "productId": 0,
      "sortOrder": 0
    }
  ],
  "available": true,
  "categories": [
    {
      "code": "string",
      "id": 0
    }
  ],
  "creationDate": "string",
  "dateAvailable": "string",
  "descriptions": [
    {
      "description": "string",
      "friendlyUrl": "string",
      "highlights": "string",
      "id": 0,
      "keyWords": "string",
      "language": "string",
      "metaDescription": "string",
      "name": "string",
      "title": "string"
    }
  ],
  "id": 0,
  "images": [
    {
      "bytes": "string",
      "contentType": "string",
      "defaultImage": true,
      "files": [
        null
      ],
      "id": 0,
      "imageType": 0,
      "imageUrl": "string",
      "name": "string",
      "path": "string"
    }
  ],
  "owner": {
    "address": {
      "address": "string",
      "billingAddress": true,
      "bilstateOther": "string",
      "city": "string",
      "company": "string",
      "country": "string",
      "countryCode": "string",
      "firstName": "string",
      "lastName": "string",
      "latitude": "string",
      "longitude": "string",
      "phone": "string",
      "postalCode": "string",
      "stateProvince": "string",
      "zone": "string"
    },
    "emailAddress": "string",
    "firstName": "string",
    "id": 0,
    "lastName": "string"
  },
  "preOrder": true,
  "price": 0,
  "productIsFree": true,
  "productPrices": [
    {
      "code": "string",
      "defaultPrice": true,
      "descriptions": [
        {
          "description": "string",
          "friendlyUrl": "string",
          "highlights": "string",
          "id": 0,
          "keyWords": "string",
          "language": "string",
          "metaDescription": "string",
          "name": "string",
          "priceAppender": "string",
          "title": "string"
        }
      ],
      "discountEndDate": "string",
      "discountStartDate": "string",
      "discounted": true,
      "discountedPrice": 0,
      "id": 0,
      "originalPrice": 0
    }
  ],
  "productShipeable": true,
  "productSpecifications": {
    "dimensionUnitOfMeasure": "cm",
    "height": 0,
    "length": 0,
    "manufacturer": "string",
    "model": "string",
    "weight": 0,
    "weightUnitOfMeasure": "g",
    "width": 0
  },
  "productVirtual": true,
  "quantity": 0,
  "quantityOrderMaximum": 0,
  "quantityOrderMinimum": 0,
  "rating": 0,
  "ratingCount": 0,
  "refSku": "string",
  "relatedProducts": [
    {
      "id": 0,
      "relationShipType": "string"
    }
  ],
  "rentalDuration": 0,
  "rentalPeriod": 0,
  "sku": "string",
  "sortOrder": 0,
  "type": "string",
  "visible": true
}

Here is my object:

{
   "attributes": [
    {
      "attributeDefault": true,
      "attributeDisplayOnly": true,
      "id": 0,
      "option": {
        "code": "colour",
        "id": 50,
        "type": "Radio"
      },
      "optionValue": {
        "code": "Black",
        "defaultValue": true,
        "id": 1,
        "image": "",
        "name": "Black",
        "sortOrder": 0
      },
      "productAttributePrice": 0,
      "productAttributeWeight":null,
      "productId": 10,
      "sortOrder": 0
    }
  ],
  "available": true,
  "categories": [
    {
      "code": "FashionCat",
      "id": 5
    }
  ],
  "creationDate": "2021-08-13",
  "dateAvailable": "2021-08-13",
  "descriptions": [
    {
      "description": "this product is a test",
      "friendlyUrl": "slippers",
      "highlights": "testing",
      "id": 120,
      "keyWords": "slippers",
      "language": "en",
      "metaDescription": "",
      "name": "Slippers",
      "title": ""
    }
  ],
  "id": 111,
  "images": [],
  "owner": {},
  "preOrder": true,
  "price": 1000,
  "productIsFree": false,
  "productPrices": [
    {
      "code": "testcode",
      "defaultPrice": false,
      "descriptions": [
        {
          "description": "test product price",
          "friendlyUrl": "test-product-price",
          "highlights": "none",
          "id": 0,
          "keyWords": "none",
          "language": "en",
          "metaDescription": "none",
          "name": "Test Product Price",
          "priceAppender": "none",
          "title": ""
        }
      ],
      "discountEndDate": "string",
      "discountStartDate": "string",
      "discounted": true,
      "discountedPrice": 0,
      "id": 0,
      "originalPrice": 0
    }
  ],
  
  "productShipeable": false,
  "productSpecifications": {
    "dimensionUnitOfMeasure": "cm",
    "height": 40,
    "length": 10,
    "manufacturer": "Prada",
    "model": "no",
    "weight": 15,
    "weightUnitOfMeasure": "g",
    "width": 11
  },
  "productVirtual": false,
  "quantity": 1000,
  "quantityOrderMaximum": 10,
  "quantityOrderMinimum": 1,
  "rating": 4,
  "ratingCount": 2,
  "refSku": "",
  "rentalDuration": 0,
  "rentalPeriod": 0,
  "sku": "mik123456",
  "sortOrder": 0,
  "type": "GENERAL",
  "visible": true
}

And I get the following response:

{
  "errorCode": null,
  "message": "java.lang.NullPointerException: Product must not be null"
}

I also tried truncating my JSON using only the required fields in shopizer's admin and I came up this this object:

{
    "attributes": [
        {
          "attributeDefault": true,
          "attributeDisplayOnly": true,
          "id": 0,
          "option": {
            "code": "colour",
            "id": 50,
            "type": "Radio"
          },
          "optionValue": {
            "code": "Black",
            "defaultValue": true,
            "id": 1,
            "image": "",
            "name": "Black",
            "sortOrder": 0
          },
          "productAttributePrice": 0,
          "productAttributeWeight":null,
          "productId": 10,
          "sortOrder": 0
        }
      ],
    "categories": [
      {
        "code": "GroceryCat",
        "id": 1
      } 
    ],
    "descriptions": [
      {
        "name": "test product",
        "language": "en"
      }
    ],
    "id": 109,
    "price": 100, 
    "quantity": 20, 
    "quantityOrderMaximum": 5, 
    "quantityOrderMinimum": 1, 
    "sku": "sku123"
  }

However, this was the error I got:

{
  "errorCode": null,
  "message": "com.salesmanager.core.business.exception.ConversionException: com.salesmanager.shop.store.api.exception.ConversionRuntimeException"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions