I went to the backend of magento I added a reference attribute for product, then I executed the script Programmatically to add product I put:
$_product->setName($product_data->_source->name);
$_product->setTypeId('simple');
$_product->setSku('sku'.$item);
$_product->setreference($product_data->_source->reference);
...
$_product->save();
but an error is displayed as following,
please how to add an attribute and access it with set and thanks in advance