Adding a writer to a Catalog product

This example adds an additional writer to a product.

import descarteslabs as dl
import uuid


catalog_client = dl.Catalog()


product_id = str(uuid.uuid4())[:8]

product = catalog_client.add_product(
    product_id=product_id, title="My Product", description="This is my product."
)
print("Product {} added.".format(product["data"]["id"]))

product_attrs = product["data"]["attributes"]

Out:

Product d4ef22d5a6969cb61147ec8ea3e060cdf33e1a49:2a69a1d0 added.

The product that we just created doesn’t have any writers.

print("Product writers: {}".format(product_attrs["writers"]))

Out:

Product writers: []

However, we can add a writer to this product.

changed_product = catalog_client.change_product(
    product_id=product["data"]["id"],
    writers=[
        "email:someuser@gmail.com"
    ],  # Could be the user hash, email, group, or org of another user.
)
changed_product_attrs = changed_product["data"]["attributes"]

Now, 'email:someuser@gmail.com' is a writer for this product. This user can now change the product metadata, add bands, and add imagery to this product.

print("Changed product writers: {}".format(changed_product_attrs["writers"]))

Out:

Changed product writers: [u'email:someuser@gmail.com']

Delete our product; we don’t need it anymore.

catalog_client.remove_product(product_id, add_namespace=True)
print("Product removed.")

Out:

Product removed.

Total running time of the script: ( 0 minutes 3.099 seconds)

Gallery generated by Sphinx-Gallery