Support » Plugin: WooCommerce Multilingual - run WooCommerce with WPML » API: invalid language parameter

  • I have to create translations for existing products, and to save time I decided to use the API. The site default language is Dutch, and I try to make English translations for over 250 products. When I try to send a translation with

    $newData = [
              'description' => $description,
              'short_description' => $shortDescription,
              'translation_of' => $product->id,
              'lang' => 'en',
            ];
            $returnTranslationData = $webshop->createProduct($newData);

    it will return the error

    Error: Invalid language parameter: “en” [422]

    .

    If I change it to ‘lang’ => ‘nl’, it will succeed. (but not linked to any existing product)

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author sergey.r

    (@sergeyr-1)

    Hello,
    is English active language ( We throw this error when translation language not active)?

    Also can you please show what you have inside $webshop->createProduct ?

    Thanks!

    • This reply was modified 6 months, 1 week ago by sergey.r.

    The debug info shows active_languages”:[“en”,”nl”], so they both seem active. We already have several pages with english translations, just not the products yet.

    Relevant code would be

    
    <?php namespace App\Libraries;
    use Automattic\WooCommerce\Client;
    
    /**
     * Class WebshopConnect
     *
     * @package App\Libraries
     */
    class WebshopConnect
    {
        private $woocommerce;
    
        public function __construct(){
          $url = getenv('woocommerce.url');
          $key = getenv('woocommerce.consumer_key');
          $secret = getenv('woocommerce.consumer_secret');
          $this->woocommerce = new Client($url, $key, $secret);
        }
    
        public function createProduct(array $productData){
          return $this->woocommerce->post('products', $productData);
        }
    }

    [edit]
    Apparently one of my colleagues put the English language on hidden (I also didn’t know this was a thing), and this solved it.

    However, I expected it to be a translation for an existing product when I add the translation, but instead it gets added as an new “Dutch” product.

    https://imgur.com/9O2arML
    The top one should be a translation of the bottom one, if I understood the documentation here: https://wpml.org/documentation/related-projects/woocommerce-multilingual/using-wordpress-rest-api-woocommerce-multilingual/

    Plugin Author sergey.r

    (@sergeyr-1)

    You need to put original product id into 'translation_of' ( in you case ‘Hipertherm…’ product id ) and 'lang' to the second language ( in you case ‘en’ )

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘API: invalid language parameter’ is closed to new replies.