• Resolved deisouss

    (@deisouss)


    Updating dimensions via API is giving the following error:

    {
       "code": "rest_invalid_param",
       "message": "Invalid parameter(s): dimensions",
       "data": {
          "status": 400,
          "params": {
             "dimensions": "dimensions is not of type object."
          },
          "details": {
             "dimensions": {
                "code": "rest_invalid_type",
                "message": "dimensions is not of type object.",
                "data": {
                   "param": "dimensions"
                }
             }
          }
       }
    }

    I have tried PUT and POST to /wp-json/wc/v3/products/{id} with the following string:

    {"dimensions":{"length":"7.00","width":"7.00","height":"6.00"}}

    I can’t seem to find any help on that error, if I try to update other fields that are not nested, it updates correctly.

    In the help file it says that “dimensions” it’s an “object”, it points out to this section:

    https://woocommerce.github.io/woocommerce-rest-api-docs/?shell#product-dimensions-properties

    • This topic was modified 1 year, 5 months ago by deisouss.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @deisouss

    From the details you’ve shared, it looks like you’re encountering an error while trying to update product dimensions via API. The error message indicates that the system is not recognizing “dimensions” as an object, which is necessary for the update process.

    The string you’re using for the update seems to be correct. However, the error might be due to the way the API is interpreting the data. Please ensure that the Content-Type in your request header is set to “application/json”. This informs the API that the data being sent is in JSON format.

    If you’re still encountering the error after this, please provide additional details about your API request so we can further assist you. This includes the method you’re using to send the request (like cURL or Postman), the complete request including headers, and the full response you’re getting.

    Let us know how that goes. Looking forward to helping you.

    Thread Starter deisouss

    (@deisouss)

    Thank you for the reply. We use Zoho, they have a pre-defined connection to Woo REST API, it seems the problem it’s coming from their side as I tried it in cURL and Postman and the JSON string is correct and it works, so it has to do something with the way they are passing the nested elements as Content-Type in header is set to “application/json”.

    Have you had any other users that use Zoho reported this problem?

    Or any other pointers that I can submit to Zoho so they can research it?

    Single items in the JSON string work, such as {“weight”:”5″} only when there are nested elements gives that error

    • This reply was modified 1 year, 4 months ago by deisouss.
    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hello @deisouss,

    Thank you for getting back to us with more information. It’s good to hear that the JSON string works correctly with cURL and Postman, as this confirms that the issue likely lies on Zoho’s side.

    While we haven’t received similar reports from other users using Zoho, the problem could be related to how Zoho handles nested JSON objects. It’s possible that Zoho’s API isn’t correctly parsing the nested “dimensions” object in your JSON string.

    A possible solution could be to check if Zoho has any specific requirements or formats for handling nested JSON objects. If there are, you may need to adjust your JSON string to match their requirements.

    Otherwise, I’d recommend reaching out to Zoho’s support team with the details of the issue. You can provide them with the error message you’re receiving and the JSON string you’re using. They should be able to help you debug the issue from their end.

    I hope this helps, and please let us know if there’s anything else we can assist you with.

    Thread Starter deisouss

    (@deisouss)

    I was able to resolve it with Zoho. For whoever needs the answer, the pre-defined connection in Zoho to WooCommerce works as long as there are no nested components in the JSON string.

    In order to properly pass nested elements you have to add the “content-type” and convert the map string using toString()

    Here is the sample code to update a product’s weight, dimensions and meta data:

    //Get the fields that you want from Zoho
    custom_field_hash = item.get("custom_field_hash");
    update_dimensions = Map();
    dimensions = Map();
    update_dimensions.put("weight",custom_field_hash.get("cf_weight"));
    dimensions.put("length",custom_field_hash.get("cf_shippinglength"));
    dimensions.put("width",custom_field_hash.get("cf_shippingwidth"));
    dimensions.put("height",custom_field_hash.get("cf_shippingheight"));
    update_dimensions.put("dimensions",dimensions);
    meta_data = list();
    meta_data_map = Map();
    meta_data_map.put("key","cf_shipsindividually");
    meta_data_map.put("value",custom_field_hash.get("cf_shipsindividually"));
    meta_data.add(meta_data_map);
    update_dimensions.put("meta_data",meta_data);
    //Display the JSON string to be passed
    info update_dimensions;
    domain = "https://yourdomain.com";
    //Define the Content type (pre-defined connection does not have it)
    headerMap=Map();
    headerMap.put("Content-Type","application/json");
    //Create a pre-defined connection first, ours is named "woocommerce"
    woo_orders = invokeurl
    [
    	url :domain + "/wp-json/wc/v3/products/" + item.get("sku")
    	type :PUT
    	parameters:update_dimensions.toString()
    	headers:headerMap
    	connection:"woocommerce"
    ];
    info woo_orders;
    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @deisouss

    I’m glad you were able to find a solution to your inquiry here and thanks for sharing it with the community too! ??

    Should you have further inquiries, kindly create a new topic here.

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Updating Dimensions via API gives error “dimensions is not of type object.”’ is closed to new replies.