Attributes being truncated when using API
-
Hello,
I’m using the Woocommerce API to list my products.
I’m having an issue with one of my attributes, “Model”.
The value I want to use for my “Model” attribute is “D5600 32GB”.
Every time I list using the API instead of “D5600 32GB” there are two values, one is “D5600” and the other is “32GB”.
How can I stop it from truncating the values of my attributes?
-
Hi there!
Thanks for contacting us. 🙂
I understand you are trying to list the products via WooCommerce Rest API but the attributes are breaking up into two when they have a space.
Could you share details of the request you are making and the JSON response that you get?
Also, could you show us the code you are using to display the products?
I did some tests using the
/wp-json/wc/v3/productsendpoint but I wasn’t able to reproduce this issue. The attributes returned correctly without breaking up.Thank you for getting back to me.
Here is the request I’m making:
curl -X POST https://domain/wp-json/wc/v3/products \ -u ck:cs \ -H "Content-Type: application/json" \ -d '{ "name": "Premium Quality", "type": "simple", "regular_price": "21.99", "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", "categories": [ { "id": 9 }, { "id": 14 } ], "attributes": [ { "name": "Model", "options": "D5600 32GB" } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg" }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg" } ] }'Here is the response I’m getting
{ "id":9393, "name":"Premium Quality", "slug":"premium-quality-4", "permalink":"https:\/\/domain\/product\/premium-quality-4\/", "date_created":"2022-05-25T11:40:28", "date_created_gmt":"2022-05-25T10:40:28", "date_modified":"2022-05-25T11:40:28", "date_modified_gmt":"2022-05-25T10:40:28", "type":"simple", "status":"publish", "featured":false, "catalog_visibility":"visible", "description":"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", "short_description":"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", "sku":"", "price":"21.99", "regular_price":"21.99", "sale_price":"", "date_on_sale_from":null, "date_on_sale_from_gmt":null, "date_on_sale_to":null, "date_on_sale_to_gmt":null, "on_sale":false, "purchasable":true, "total_sales":0, "virtual":false, "downloadable":false, "downloads":[ ], "download_limit":-1, "download_expiry":-1, "external_url":"", "button_text":"", "tax_status":"taxable", "tax_class":"", "manage_stock":false, "stock_quantity":null, "backorders":"no", "backorders_allowed":false, "backordered":false, "low_stock_amount":null, "sold_individually":false, "weight":"", "dimensions":{ "length":"", "width":"", "height":"" }, "shipping_required":true, "shipping_taxable":true, "shipping_class":"", "shipping_class_id":0, "reviews_allowed":true, "average_rating":"0", "rating_count":0, "upsell_ids":[ ], "cross_sell_ids":[ ], "parent_id":0, "purchase_note":"", "categories":[ { "id":15, "name":"Uncategorized", "slug":"uncategorized" } ], "tags":[ ], "images":[ { "id":9391, "date_created":"2022-05-25T12:40:28", "date_created_gmt":"2022-05-25T10:40:28", "date_modified":"2022-05-25T12:40:28", "date_modified_gmt":"2022-05-25T10:40:28", "src":"https:\/\/domain.co.uk\/wp-content\/uploads\/2022\/05\/T_2_front-3.jpg", "name":"T_2_front-3.jpg", "alt":"" }, { "id":9392, "date_created":"2022-05-25T12:40:28", "date_created_gmt":"2022-05-25T10:40:28", "date_modified":"2022-05-25T12:40:28", "date_modified_gmt":"2022-05-25T10:40:28", "src":"https:\/\/domain.co.uk\/wp-content\/uploads\/2022\/05\/T_2_back-3.jpg", "name":"T_2_back-3.jpg", "alt":"" } ], "attributes":[ { "id":0, "name":"Model", "position":0, "visible":false, "variation":false, "options":[ "D5600", "32GB" ] } ], "default_attributes":[ ], "variations":[ ], "grouped_products":[ ], "menu_order":0, "price_html":"<span class=\"woocommerce-Price-amount amount\"><bdi><span class=\"woocommerce-Price-currencySymbol\">£<\/span>21.99<\/bdi><\/span>", "related_ids":[ 6409, 4527, 6264, 9390, 9387 ], "meta_data":[ ], "stock_status":"instock", "has_options":false, "_links":{ "self":[ { "href":"https:\/\/domain.co.uk\/wp-json\/wc\/v3\/products\/9393" } ], "collection":[ { "href":"https:\/\/domain.co.uk\/wp-json\/wc\/v3\/products" } ] } }For now I’m looking at the products from the backend and I can see two options instead of the only one I’m submitting
Thanks again
Hi @arhamm,
Thanks for sharing the request and the JSON response.
I see what you mean with the separate values.

I wasn’t able to reproduce the issue though same as Kaushik mentioned earlier.

Can you try with all plugins disabled (except WooCommerce) and with a default theme like Storefront? Also, make sure you’re sending a
GETHTTP request as per support documentation.https://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-products
Let us know how it goes.
We had the same issue. You have to send the options in an array.
You’re missing the [] – characters which need to embrace your “D5600 32GB”.
I hope this helps!See example down below:
“attributes”: [
{
“name”: “COLORE”,
“position”: 0,
“visible”: false,
“variation”: true,
“options”: [ “Black Blue” ]}
Hi @limabu
You are right, that fixed my issue.
Thanks and thank you @rainfallnixfig @kaushiksomaiya for helping
Regards
Hi @arhamm!
We’re happy to hear that! I’m going to mark this as resolved, but feel free to create a new topic if you need anything else!
All the best!
The topic ‘Attributes being truncated when using API’ is closed to new replies.