WooCommerce Order API always creates empty orders - wordpress

Im playing around with Woo Commerce API (v3.4.4). I can get a product with:
curl -X GET \
'http://localhost/wp-json/wc/v2/products/7?oauth_consumer_key=ck_8cbe42fb09c04954a63994c22145270f27871dec&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1535381325&oauth_nonce=iApWJblA1A5&oauth_version=1.0&oauth_signature=9T1T43FvOpBzVBU+RQS90zMB/XM=' \
-H 'Cache-Control: no-cache' \
-H 'Postman-Token: bdb7f5c9-5719-4bcf-b4fc-38aed3bd5d08'
I get the response:
{
"id": 7,
"name": "Test product",
"slug": "test-product",
"permalink": "http://localhost/product/test-product/",
"date_created": "2018-08-22T15:25:26",
"date_created_gmt": "2018-08-22T15:25:26",
"date_modified": "2018-08-22T15:25:26",
"date_modified_gmt": "2018-08-22T15:25:26",
"type": "simple",
"status": "publish",
"featured": false,
"catalog_visibility": "visible",
"description": "<p>this is a test product</p>\n",
"short_description": "<p>the short desc</p>\n",
"sku": "",
"price": "9",
"regular_price": "10",
"sale_price": "9",
"date_on_sale_from": null,
"date_on_sale_from_gmt": null,
"date_on_sale_to": null,
"date_on_sale_to_gmt": null,
"price_html": "<del><span class=\"woocommerce-Price-amount amount\"><span class=\"woocommerce-Price-currencySymbol\">€</span>10.00</span></del> <ins><span class=\"woocommerce-Price-amount amount\"><span class=\"woocommerce-Price-currencySymbol\">€</span>9.00</span></ins>",
"on_sale": true,
"purchasable": true,
"total_sales": 3,
"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,
"in_stock": true,
"backorders": "no",
"backorders_allowed": false,
"backordered": false,
"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.00",
"rating_count": 0,
"related_ids": [
36,
41
],
"upsell_ids": [],
"cross_sell_ids": [],
"parent_id": 0,
"purchase_note": "",
"categories": [
{
"id": 15,
"name": "Uncategorized",
"slug": "uncategorized"
}
],
"tags": [],
"images": [
{
"id": 8,
"date_created": "2018-08-22T15:24:00",
"date_created_gmt": "2018-08-22T15:24:00",
"date_modified": "2018-08-22T15:24:00",
"date_modified_gmt": "2018-08-22T15:24:00",
"src": "http://localhost/wp-content/uploads/2018/08/sock.jpeg",
"name": "sock",
"alt": "",
"position": 0
}
],
"attributes": [
{
"id": 0,
"name": "size",
"position": 0,
"visible": true,
"variation": false,
"options": [
"small",
"medium",
"large"
]
}
],
"default_attributes": [],
"variations": [],
"grouped_products": [],
"menu_order": 0,
"meta_data": [],
"_links": {
"self": [
{
"href": "http://localhost/wp-json/wc/v2/products/7"
}
],
"collection": [
{
"href": "http://localhost/wp-json/wc/v2/products"
}
]
}
}
This works running the request using CURL on the command line, and running the request in Postman.
But now I try to create an order:
curl -X POST \
'http://localhost/wp-json/wc/v2/orders?oauth_consumer_key=ck_8cbe42fb09c04954a63994c22145270f27871dec&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1535382336&oauth_nonce=P8RWaD9DnZ9&oauth_version=1.0&oauth_signature=GFxtI7+gqbah5fu68gSdqL4V3fs=' \
-H 'Cache-Control: no-cache' \
-H 'Postman-Token: f17bec6a-c76b-4a6c-8797-1df9dac73f36' \
-d '{
"payment_method": "bacs",
"payment_method_title": "Direct Bank Transfer",
"set_paid": true,
"billing": {
"first_name": "John",
"last_name": "Doe",
"address_1": "969 Market",
"address_2": "",
"city": "San Francisco",
"state": "CA",
"postcode": "94103",
"country": "US",
"email": "john.doe#example.com",
"phone": "(555) 555-5555"
},
"shipping": {
"first_name": "John",
"last_name": "Doe",
"address_1": "969 Market",
"address_2": "",
"city": "San Francisco",
"state": "CA",
"postcode": "94103",
"country": "US"
},
"line_items": [
{
"product_id": 7,
"quantity": 1
}
],
"shipping_lines": [
{
"method_id": "flat_rate",
"method_title": "Flat Rate",
"total": 7
}
]
}'
When I run the above request with Postman, it creates an empty order and I get the response:
{
"id": 59,
"parent_id": 0,
"number": "59",
"order_key": "wc_order_5b8413f8ed585",
"created_via": "rest-api",
"version": "3.4.4",
"status": "pending",
"currency": "EUR",
"date_created": "2018-08-27T15:08:40",
"date_created_gmt": "2018-08-27T15:08:40",
"date_modified": "2018-08-27T15:08:41",
"date_modified_gmt": "2018-08-27T15:08:41",
"discount_total": "0.00",
"discount_tax": "0.00",
"shipping_total": "0.00",
"shipping_tax": "0.00",
"cart_tax": "0.00",
"total": "0.00",
"total_tax": "0.00",
"prices_include_tax": false,
"customer_id": 0,
"customer_ip_address": "",
"customer_user_agent": "",
"customer_note": "",
"billing": {
"first_name": "",
"last_name": "",
"company": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"postcode": "",
"country": "",
"email": "",
"phone": ""
},
"shipping": {
"first_name": "",
"last_name": "",
"company": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"postcode": "",
"country": ""
},
"payment_method": "",
"payment_method_title": "",
"transaction_id": "",
"date_paid": null,
"date_paid_gmt": null,
"date_completed": null,
"date_completed_gmt": null,
"cart_hash": "",
"meta_data": [],
"line_items": [],
"tax_lines": [],
"shipping_lines": [],
"fee_lines": [],
"coupon_lines": [],
"refunds": [],
"_links": {
"self": [
{
"href": "http://localhost/wp-json/wc/v2/orders/59"
}
],
"collection": [
{
"href": "http://localhost/wp-json/wc/v2/orders"
}
]
}
}
Bizarrely, when i run the EXACT same request with CURL on the command line, I get the response:
{"code":"woocommerce_rest_authentication_error","message":"Invalid signature - provided signature does not match.","data":{"status":401}}
If I run the request in Postman, but for "product_id" I use "this is a completely fake id" it still creates an empty order and responds with:
{
"id": 60,
"parent_id": 0,
"number": "60",
"order_key": "wc_order_5b84148e002da",
"created_via": "rest-api",
"version": "3.4.4",
"status": "pending",
"currency": "EUR",
"date_created": "2018-08-27T15:11:10",
"date_created_gmt": "2018-08-27T15:11:10",
"date_modified": "2018-08-27T15:11:10",
"date_modified_gmt": "2018-08-27T15:11:10",
"discount_total": "0.00",
"discount_tax": "0.00",
"shipping_total": "0.00",
"shipping_tax": "0.00",
"cart_tax": "0.00",
"total": "0.00",
"total_tax": "0.00",
"prices_include_tax": false,
"customer_id": 0,
"customer_ip_address": "",
"customer_user_agent": "",
"customer_note": "",
"billing": {
"first_name": "",
"last_name": "",
"company": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"postcode": "",
"country": "",
"email": "",
"phone": ""
},
"shipping": {
"first_name": "",
"last_name": "",
"company": "",
"address_1": "",
"address_2": "",
"city": "",
"state": "",
"postcode": "",
"country": ""
},
"payment_method": "",
"payment_method_title": "",
"transaction_id": "",
"date_paid": null,
"date_paid_gmt": null,
"date_completed": null,
"date_completed_gmt": null,
"cart_hash": "",
"meta_data": [],
"line_items": [],
"tax_lines": [],
"shipping_lines": [],
"fee_lines": [],
"coupon_lines": [],
"refunds": [],
"_links": {
"self": [
{
"href": "http://localhost/wp-json/wc/v2/orders/60"
}
],
"collection": [
{
"href": "http://localhost/wp-json/wc/v2/orders"
}
]
}
}
So I have a number of problems:
1/ No matter what product_id I use, the order that's created is always empty
2/ Even if I provide a fake product_id, an order is still created by Woo Commerce. Surely this is incorrect?
3/ Running the create order requests on the command line is giving different responses to Postman

I was missing:
-H 'Content-Type: application/json' \
from the request. I had this entered in Postman, but had not ticked the check box:

Related

How can I get the translated only products with translation from WooCommerce Multilingual & Multicurrency with Rest API?

The problem is that I get this excerpt of a product from Woocommerce:
[
{
"id": 73,
"name": "cBox",
"slug": "cbox",
"sku": "",
"price": "169",
"regular_price": "169",
"sale_price": "",
"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,
"shipping_required": true,
"shipping_taxable": true,
"shipping_class": "",
"shipping_class_id": 0,
"reviews_allowed": true,
"average_rating": "0.00",
"rating_count": 0,
"upsell_ids": [],
"cross_sell_ids": [],
"parent_id": 0,
"purchase_note": "",
"attributes": [],
"default_attributes": [],
"variations": [],
"grouped_products": [],
"menu_order": 0,
"stock_status": "instock",
"has_options": true,
"translations": {
"de": "73",
"en": "76"
},
"lang": "de",
}
]
You can see the translations, at least the ID's of the translated products. My question is how can I get directly via rest-api only the translated products?
Because with the property "lang=en" it does not work in the url
What does your request look like?
It should work with the lang parameter, you can read more here: https://wpml.org/documentation/related-projects/woocommerce-multilingual/using-wordpress-rest-api-woocommerce-multilingual/

Label ACF 'repeater' doesn't work anymore since update WordPress and ACF plugin

I have updated my WordPress from 4.6.x to 5.2.1.
I have also updated plugin ACF Pro from 4.x.x to 5.8.1.
Since then, ACF labels of type 'repeater' doesn't work anymore :
they don't appear anymore in admin panel and in front of application.
The other labels work well.
I don't know why. Do you have an idea ?
{
"key": "field_56f04b4f1d998",
"label": "Layouts",
"name": "layouts",
"type": "repeater",
"instructions": "",
"required": 0,
"conditional_logic": [],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"collapsed": "",
"min": "",
"max": "",
"layout": "block",
"button_label": "Add layout",
"sub_fields": [
{
"key": "field_573c2f5d67d89",
"label": "Type",
"name": "type",
"type": "select",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"choices": {
"layout100": "1\/1",
"layout100_full": "1\/1 full",
"layout5050": "1\/2 + 1\/2",
"layout3366": "1\/3 + 2\/3",
"layout6633": "2\/3 + 1\/3"
},
"default_value": [
0
],
"allow_null": 0,
"multiple": 0,
"ui": 0,
"ajax": 0,
"return_format": "value",
"placeholder": ""
},
{
"key": "field_5a266ce145c75",
"label": "Border top ?",
"name": "border_top",
"type": "true_false",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"message": "",
"default_value": 1
}
]
}
Update acf-component-field plugin and add 'field_group_key=component_group_id' in your json.

How to update the clone fields which is inside the repeater field in ACF?

I have a field group named 'Sales Item' and 'Invoice'. The invoice field group have a 'Items' field which is a repeater field, the 'Items' field contains the 'Sales Item' field group as clone field.
I need to create an Invoice post type programmatically. All the field of the 'Invoice' is created except the 'Items' field. How do I add the data to the 'Items' reaper field which contain the 'Sales Item' clone field?
Sales Item and Invoice field group.
[
{
"key": "group_5c4033565a799",
"title": "Invoice",
"fields": [
{
"key": "field_5c44150d123de",
"label": "Type",
"name": "ims_invoice_type",
"type": "select",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"choices": {
"sales": "Sales",
"purchases": "Purchases"
},
"default_value": [
"purchases"
],
"allow_null": 0,
"multiple": 0,
"ui": 0,
"return_format": "value",
"ajax": 0,
"placeholder": ""
},
{
"key": "field_5c4033c40bce3",
"label": "Invoice Number",
"name": "ims_invoice_invoice_number",
"type": "text",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
},
{
"key": "field_5c4e943170485",
"label": "Customer",
"name": "ims_invoice_customer",
"type": "relationship",
"instructions": "",
"required": 1,
"conditional_logic": [
[
{
"field": "field_5c44150d123de",
"operator": "==",
"value": "sales"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"post_type": [
"ims_customer"
],
"taxonomy": "",
"filters": [
"search",
"post_type",
"taxonomy"
],
"elements": "",
"min": 1,
"max": 1,
"return_format": "object"
},
{
"key": "field_5c4033620bce1",
"label": "Vendor",
"name": "ims_invoice_vendor",
"type": "relationship",
"instructions": "",
"required": 1,
"conditional_logic": [
[
{
"field": "field_5c44150d123de",
"operator": "==",
"value": "purchases"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"post_type": [
"ims_vendor"
],
"taxonomy": "",
"filters": [
"search",
"post_type",
"taxonomy"
],
"elements": "",
"min": 1,
"max": 1,
"return_format": "object"
},
{
"key": "field_5c40339b0bce2",
"label": "Date",
"name": "ims_invoice_date",
"type": "date_picker",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"display_format": "F j, Y",
"return_format": "d\/m\/Y",
"first_day": 0
},
{
"key": "field_5c4034030cff9",
"label": "Items",
"name": "ims_invoice_sales_items",
"type": "repeater",
"instructions": "",
"required": 1,
"conditional_logic": [
[
{
"field": "field_5c44150d123de",
"operator": "==",
"value": "sales"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"collapsed": "",
"min": 0,
"max": 0,
"layout": "table",
"button_label": "Add Product",
"sub_fields": [
{
"key": "field_5c443f4dd87de",
"label": "Item",
"name": "ims_invoice_sales_items",
"type": "clone",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"clone": [
"group_5c443e86ad330"
],
"display": "seamless",
"layout": "block",
"prefix_label": 0,
"prefix_name": 1
}
]
},
{
"key": "field_5c78f715c5efe",
"label": "Items",
"name": "ims_invoice_purchases_items",
"type": "repeater",
"instructions": "",
"required": 1,
"conditional_logic": [
[
{
"field": "field_5c44150d123de",
"operator": "==",
"value": "purchases"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"collapsed": "",
"min": 0,
"max": 0,
"layout": "table",
"button_label": "Add Product",
"sub_fields": [
{
"key": "field_5c78f730c5eff",
"label": "Items",
"name": "ims_invoice_purchases_items",
"type": "clone",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"clone": [
"group_5c78e0e32443c"
],
"display": "seamless",
"layout": "block",
"prefix_label": 0,
"prefix_name": 1
}
]
},
{
"key": "field_5c41b2ff17b09",
"label": "Sub Total",
"name": "ims_invoice_sub_total",
"type": "read_only",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"copy_to_clipboard": 0,
"display_type": "text"
},
{
"key": "field_5c41b31a17b0b",
"label": "Discount",
"name": "ims_invoice_discount",
"type": "number",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "0.0",
"placeholder": "",
"prepend": "",
"append": "",
"min": 0,
"max": "",
"step": ""
},
{
"key": "field_5c41b32617b0c",
"label": "V.A.T",
"name": "ims_invoice_vat",
"type": "number",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "0.0",
"placeholder": "",
"prepend": "",
"append": "",
"min": 0,
"max": "",
"step": ""
},
{
"key": "field_5c41b33317b0d",
"label": "Total",
"name": "ims_invoice_total",
"type": "read_only",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"copy_to_clipboard": 0,
"display_type": "text"
},
{
"key": "field_5c41b33b17b0e",
"label": "Paid",
"name": "ims_invoice_paid",
"type": "number",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "0.0",
"placeholder": "",
"prepend": "",
"append": "",
"min": 0,
"max": "",
"step": ""
},
{
"key": "field_5c41b34517b0f",
"label": "Due",
"name": "ims_invoice_due",
"type": "read_only",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"copy_to_clipboard": 0,
"display_type": "text"
}
],
"location": [
[
{
"param": "post_type",
"operator": "==",
"value": "ims_invoice"
}
]
],
"menu_order": 0,
"position": "normal",
"style": "default",
"label_placement": "left",
"instruction_placement": "label",
"hide_on_screen": "",
"active": 1,
"description": ""
},
{
"key": "group_5c443e86ad330",
"title": "Sales Item",
"fields": [
{
"key": "field_5c443eab22fe1",
"label": "Item",
"name": "sales_item_item",
"type": "post_object",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"post_type": [
"ims_product"
],
"taxonomy": "",
"allow_null": 0,
"multiple": 0,
"return_format": "object",
"ui": 1
},
{
"key": "field_5c779ac395834",
"label": "SKU",
"name": "sales_item_sku",
"type": "read_only",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"copy_to_clipboard": 0,
"display_type": "text"
},
{
"key": "field_5c443eba22fe2",
"label": "Quantity",
"name": "sales_item_quantity",
"type": "number",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": 1,
"placeholder": "",
"prepend": "",
"append": "",
"min": "",
"max": "",
"step": ""
},
{
"key": "field_5c443ec622fe3",
"label": "Unit Price",
"name": "sales_item_unit_price",
"type": "read_only",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"copy_to_clipboard": 0,
"display_type": "text"
},
{
"key": "field_5c443edf22fe4",
"label": "Price",
"name": "sales_item_price",
"type": "read_only",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"copy_to_clipboard": 0,
"display_type": "text"
},
{
"key": "field_5c443efd22fe5",
"label": "Discount",
"name": "sales_item_discount",
"type": "number",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "0.0",
"placeholder": "",
"prepend": "",
"append": "",
"min": "",
"max": "",
"step": ""
},
{
"key": "field_5c443f0a22fe6",
"label": "Amount",
"name": "sales_item_amount",
"type": "read_only",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"copy_to_clipboard": 0,
"display_type": "text"
}
],
"location": [
[
{
"param": "post_type",
"operator": "==",
"value": "post"
}
]
],
"menu_order": 0,
"position": "normal",
"style": "default",
"label_placement": "top",
"instruction_placement": "label",
"hide_on_screen": "",
"active": 0,
"description": ""
}
]
Here is the code, I have written so far.
$invoice_key = 'ims_invoice_sales_items_';
$customer_id = $_POST['customer_id'];
$ims_products = $_POST['ims_product'];
$basket_discount = $_POST['basket_discount'];
$basket_vat = $_POST['basket_vat'];
$paid = $_POST['paid'];
$sub_total = 0.0;
foreach( $ims_products as $ims_product ) {
$id = $ims_product['id'];
$quantity = intval( $ims_product['quantity'] );
$unit_price = floatval( get_field( 'ims_product_mrp', $id ) );
$discount = floatval( $ims_product['discount'] );
$price = $quantity * $unit_price;
$amount = $price - ( $discount * $price ) / 100.0;
$sub_total += $amount;
$items [] = array(
$invoice_key . 'sales_item_item' => $id,
$invoice_key . 'sales_item_sku' => get_field( 'ims_product_sku', $id ),
$invoice_key . 'sales_item_quantity' => $quantity,
$invoice_key . 'sales_item_unit_price' => $unit_price,
$invoice_key . 'sales_item_price' => $price,
$invoice_key . 'sales_item_discount' => $discount,
$invoice_key . 'sales_item_amount' => $amount
);
}
// var_dump( $items );
// Calculate grand total after discount and vat.
$grand_total = $sub_total - ( $basket_discount * $sub_total ) / 100.0;
$grand_total = $grand_total + ( $basket_vat * $grand_total ) / 100.0;
// Calculate due.
$due = $grand_total - $paid;
$meta_inputs = array(
'ims_invoice_type' => 'sales',
'ims_invoice_invoice_number' => uniqid(),
'ims_invoice_customer' => $customer_id,
'ims_invoice_date' => current_time('d/m/Y', false ),
'ims_invoice_sub_total' => $sub_total,
'ims_invoice_discount' => $basket_discount,
'ims_invoice_vat' => $basket_vat,
'ims_invoice_total' => $grand_total,
'ims_invoice_paid' => $paid,
'ims_invoice_due' => $due
);
$invoice_args = array(
'post_type' => 'ims_invoice',
'post_status' => 'publish',
'meta_input' => $meta_inputs
);
// var_dump( $invoice_args );
$post_id = wp_insert_post( $invoice_args, true );
var_dump( "<h1>Post Id = ${post_id}</h1>");
foreach( $items as $item ) {
var_dump( $item );
add_row( 'ims_invoice_sales_items', $item, $post_id );
}
die;
You don't actually need to call add_row and add each repeater entry in sequence. You can push the entire items array in one go. You will need to do following things to make sure that the below conditions are met and the code will work for you.
You have the correct field key for your repeater field (Something to the effect of field_5bfed0e63a470).
The slug of each repeating element in the repeater group is correct(For example repeater group has a field sales item and the slug for it is in the format sales_item_item).
Once You have made sure of that you just need to create an array of the new items set as you have already created with $items variable and call the below code:
$items_inserted = update_field('field_5bfed0e63a470', $items, $post_id);
Things should work fine for you with this. Good Luck!!!

Unable to transcode telegram voice message using IBM Watsown Speech to Text with Node-Red

Trying to transcript audio from Telegram voice message but I got "unable to transcode data stream audio/opus -> audio/x-float-array" error from watson's speech to text node.
I'm using Node-Red on Raspberry to simply transcript audio from Telegram voice message with node-red-contrib-telegrambot and node-red-node-watson.
With text messages, my code works as a charm.
With Voice Messages, I got "unable to transcode data stream audio/opus -> audio/x-float-array" error from watson's speech to text node.
node-red flow images I don't have enough reputation point to post images :(
JSON flow export
[
{
"id": "b4106ec1.63dd58",
"type": "tab",
"label": "Telegram",
"disabled": false,
"info": ""
},
{
"id": "d1198164.e38f68",
"type": "telegram receiver",
"z": "b4106ec1.63dd58",
"name": "FMWatsonBot",
"bot": "5f347711.7876d8",
"saveDataDir": "",
"x": 110,
"y": 100,
"wires": [
[
"f4b4ab25.5dde18",
"f5d126df.5b6928"
],
[]
]
},
{
"id": "c6ec445d.0840d8",
"type": "telegram sender",
"z": "b4106ec1.63dd58",
"name": "Send2Telegram",
"bot": "5f347711.7876d8",
"x": 780,
"y": 80,
"wires": [
[]
]
},
{
"id": "f4b4ab25.5dde18",
"type": "debug",
"z": "b4106ec1.63dd58",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 290,
"y": 60,
"wires": []
},
{
"id": "f5d126df.5b6928",
"type": "function",
"z": "b4106ec1.63dd58",
"name": "Save chat context",
"func": "msg.chatId = msg.payload.chatId;\nmsg.type = msg.payload.type;\nmsg.content = msg.payload.content;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 230,
"y": 160,
"wires": [
[
"c3d1a92d.227568"
]
]
},
{
"id": "276cfad7.cef62e",
"type": "function",
"z": "b4106ec1.63dd58",
"name": "Set Chat Context",
"func": "msg.payload = {\n chatId : msg.chatId,\n topic : msg.type,\n type : \"message\",\n content : msg.payload};\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"x": 730,
"y": 220,
"wires": [
[
"c6ec445d.0840d8"
]
]
},
{
"id": "c3d1a92d.227568",
"type": "switch",
"z": "b4106ec1.63dd58",
"name": "Check msg type",
"property": "type",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "message",
"vt": "str"
},
{
"t": "eq",
"v": "voice",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 3,
"x": 300,
"y": 240,
"wires": [
[
"e8452a44.f967c8"
],
[
"6aea6224.578d8c"
],
[]
]
},
{
"id": "e8452a44.f967c8",
"type": "function",
"z": "b4106ec1.63dd58",
"name": "Echo message",
"func": "msg.payload = {\n chatId : msg.chatId,\n topic : \"Text Echo\",\n type : msg.type,\n content : msg.content};\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 540,
"y": 80,
"wires": [
[
"c6ec445d.0840d8"
]
]
},
{
"id": "6aea6224.578d8c",
"type": "change",
"z": "b4106ec1.63dd58",
"name": "Set voice URL",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.weblink",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 440,
"y": 300,
"wires": [
[
"fc7b1590.557c"
]
]
},
{
"id": "493d1bac.216d3c",
"type": "change",
"z": "b4106ec1.63dd58",
"name": "Set transcription",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "transcription",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 680,
"y": 300,
"wires": [
[
"276cfad7.cef62e"
]
]
},
{
"id": "fc7b1590.557c",
"type": "watson-speech-to-text",
"z": "b4106ec1.63dd58",
"name": "S2T",
"alternatives": 1,
"speakerlabels": false,
"smartformatting": false,
"lang": "en-GB",
"langhidden": "en-GB",
"langcustom": "NoCustomisationSetting",
"langcustomhidden": "",
"custom-weight": "0.5",
"band": "BroadbandModel",
"bandhidden": "BroadbandModel",
"keywords": "",
"keywords-threshold": "0.5",
"word-confidence": false,
"password": "",
"apikey": "#########CHANGED VALUE TO POST###########",
"payload-response": false,
"streaming-mode": false,
"streaming-mute": true,
"auto-connect": false,
"discard-listening": false,
"disable-precheck": false,
"default-endpoint": true,
"service-endpoint": "https://stream.watsonplatform.net/speech-to-text/api",
"x": 530,
"y": 360,
"wires": [
[
"493d1bac.216d3c"
]
]
},
{
"id": "5f347711.7876d8",
"type": "telegram bot",
"z": "",
"botname": "FMWatsonBot",
"usernames": "",
"chatids": "",
"baseapiurl": "",
"updatemode": "polling",
"pollinterval": "300",
"bothost": "",
"localbotport": "8443",
"publicbotport": "8443",
"privatekey": "",
"certificate": "",
"verboselogging": false
}
]
Any hint?
Thanks in advance
Ferruccio
It boils down to how you are fetching the audio from Telegram. Check the answer to this related question - https://developer.ibm.com/answers/questions/424777/help-how-do-i-use-speech-to-text-with-my-telegram/
which shows how to build the url to send through to the Speech to text node.
Update: Flow perfectly works with telegram node v4.4.0, but fails with new version 5.1.5
So, it's not a problem regarding Speech to Text node.

How do I share the contents of a file two-way between host and container?

I am pretty sure it used to work this way, but now I can't make it work anymore... This is the problem:
$ docker run -d -p 80:80 --name frontend -v $(pwd)/nginx.conf:/etc/nginx/nginx.conf -v $(pwd)/htpasswd:/htpasswd nginx
I want to have this nginx.conf file that I want to edit in the host and, then, simply run
$ docker exec -ti frontend nginx -s reload
And have my frontend server reloaded. But I can't see the changes in nginx.conf from inside the container. Why is that?
In case this helps:
[
{
"Id": "39ceafd41f7576638d4b129ea90b0522aa61f25d62e68e361de905638ba74f60",
"Created": "2016-07-07T18:59:35.917569545Z",
"Path": "nginx",
"Args": [
"-g",
"daemon off;"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 17786,
"ExitCode": 0,
"Error": "",
"StartedAt": "2016-07-07T18:59:36.241298894Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:0d409d33b27e47423b049f7f863faa08655a8c901749c2b25b93ca67d01a470d",
"ResolvConfPath": "/var/lib/docker/containers/39ceafd41f7576638d4b129ea90b0522aa61f25d62e68e361de905638ba74f60/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/39ceafd41f7576638d4b129ea90b0522aa61f25d62e68e361de905638ba74f60/hostname",
"HostsPath": "/var/lib/docker/containers/39ceafd41f7576638d4b129ea90b0522aa61f25d62e68e361de905638ba74f60/hosts",
"LogPath": "/var/lib/docker/containers/39ceafd41f7576638d4b129ea90b0522aa61f25d62e68e361de905638ba74f60/39ceafd41f7576638d4b129ea90b0522aa61f25d62e68e361de905638ba74f60-json.log",
"Name": "/frontend",
"RestartCount": 0,
"Driver": "devicemapper",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": [
"/home/jpmelos/nginx.conf:/etc/nginx/nginx.conf",
"/home/jpmelos/htpasswd:/htpasswd"
],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "infra",
"PortBindings": {
"80/tcp": [
{
"HostIp": "",
"HostPort": "80"
}
]
},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"StorageOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": -1,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"BlkioIOps": 0,
"BlkioBps": 0,
"SandboxSize": 0
},
"GraphDriver": {
"Name": "devicemapper",
"Data": {
"DeviceId": "3660",
"DeviceName": "docker-253:0-3147678-71e674d2c1754f73d3fdd933a1971bf8464f6aa6b738dc818a668beb96a4e6ea",
"DeviceSize": "10737418240"
}
},
"Mounts": [
{
"Source": "/home/jpmelos/nginx.conf",
"Destination": "/etc/nginx/nginx.conf",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
},
{
"Source": "/home/jpmelos/htpasswd",
"Destination": "/htpasswd",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
"Config": {
"Hostname": "39ceafd41f75",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"443/tcp": {},
"80/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NGINX_VERSION=1.11.1-1~jessie"
],
"Cmd": [
"nginx",
"-g",
"daemon off;"
],
"Image": "nginx",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "c20b1912f3689cf6b82d19b2ae3173e050b3958e266dd19dd047aeccacabef55",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"443/tcp": null,
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "80"
}
]
},
"SandboxKey": "/var/run/docker/netns/c20b1912f368",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"infra": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "4598916660ed5453a5ec48412452b00ef6dce24f64b5e315b625596a806442c1",
"EndpointID": "9e7d50cdfbdcec31331655b167ec0e6c5ee20b6e3cc7122222706f99418732d2",
"Gateway": "172.18.0.1",
"IPAddress": "172.18.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:12:00:02"
}
}
}
}
]
Interesting bit: the Mounts section says the mountpoints are rprivate. This might be the problem, but I researched and I couldn't find anything about it...
Looks like the answer is that Docker does not allow editing shared files, just files inside shared directories. When I put my configuration files inside a shared directory and included them from nginx.conf, then it all worked.

Resources