insert method

Future<ProductInput> insert(
  1. ProductInput request,
  2. String parent, {
  3. String? dataSource,
  4. String? $fields,
})

[Uploads a product input to your Merchant Center account](/merchant/api/guides/products/add-manage#add_a_product).

You must have a products [data source](/merchant/api/guides/data-sources/api-sources#create-primary-data-source) to be able to insert a product. The unique identifier of the data source is passed as a query parameter in the request URL. If a product input with the same contentLanguage, offerId, and dataSource already exists, then the product input inserted by this method replaces that entry. After inserting, updating, or deleting a product input, it may take several minutes before the processed product can be retrieved.

request - The metadata request object.

Request parameters:

parent - Required. The account where this product will be inserted. Format: accounts/{account} Value must have pattern ^accounts/\[^/\]+$.

dataSource - Required. The primary or supplemental product data source name. If the product already exists and data source provided is different, then the product will be moved to a new data source. For more information, see [Create a primary data source](/merchant/api/guides/data-sources/api-sources#create-primary-data-source). Only API data sources are supported. Format: accounts/{account}/dataSources/{datasource}. For example, accounts/123456/dataSources/104628.

$fields - Selector specifying which fields to include in a partial response.

Completes with a ProductInput.

Completes with a commons.ApiRequestError if the API endpoint returned an error.

If the used http.Client completes with an error when making a REST call, this method will complete with the same error.

Implementation

async.Future<ProductInput> insert(
  ProductInput request,
  core.String parent, {
  core.String? dataSource,
  core.String? $fields,
}) async {
  final body_ = convert.json.encode(request);
  final queryParams_ = <core.String, core.List<core.String>>{
    if (dataSource != null) 'dataSource': [dataSource],
    if ($fields != null) 'fields': [$fields],
  };

  final url_ =
      'products/v1/' +
      core.Uri.encodeFull('$parent') +
      '/productInputs:insert';

  final response_ = await _requester.request(
    url_,
    'POST',
    body: body_,
    queryParams: queryParams_,
  );
  return ProductInput.fromJson(
    response_ as core.Map<core.String, core.dynamic>,
  );
}