.. include:: /global.inc .. include:: /banner.rst Saving assessments using the CFT ================================ This topic guide explains how to send data to the CFT's creation modules. .. warning:: Users should be warned and advised that this feature is currently in development, and you may notice unusual behavior when using it. Please send anything you notice to tech@coolfarmtool.org and we will investigate it as soon as possible. .. note:: * :ref:`Data schemas` are available for reference * This version of the API has significant changes to these methods; see :doc:`changelog` All URLs start with ``/api/v1/``. .. contents:: Contents :local: Crop assessment --------------- .. note:: When saving a crop product to the database, and you want to use the crop product as a dairy feed item, you will need to create (or use an existing crop product), either in the user interface or using the guide below, ensuring that you send your choice of ``feed_type``. Choices are available on the :ref:`Feed_components item` page .. code-block:: js "crop": { "type": "Potato", "feed_type": null, // Add the name or ID of the feed type here "field_size": { "value": 100, "unit": "ha" }, }, .. _create-crop-assessment-endpoint: .. http:post:: /crop_product/ Create a crop product and save it to the database **Example request** .. sourcecode:: http POST /crop_product/ HTTP/1.1 Host: app.coolfarmtool.org Accept: application/json Content-Type: application/json .. literalinclude:: /../../api/v1/samples/crop_product-calculate-input.json **Example response** .. sourcecode:: http HTTP/1.1 200 OK Content-Type: application/json [ { "status": "success", "crop_product_uri": "https://app.coolfarmtool.org/crop_product/ABC123/", "crop_product_slug": "ABC123" } ] :reqheader X-Api-App-Authorisation: app key; see :doc:`authentication` :reqheader X-Api-Authorisation: api key; see :doc:`authentication` :statuscode 400: missing or incorrect form data .. http:post:: /farms/(str:farm_slug)/crop_products/ Create a crop product for a given farm slug and save it to the database **Example request** .. sourcecode:: http POST /farms/(str:farm_slug)/crop_products/ HTTP/1.1 Host: app.coolfarmtool.org Accept: application/json Content-Type: application/json .. literalinclude:: /../../api/v1/samples/crop_product-calculate-input.json **Example response** .. sourcecode:: http HTTP/1.1 200 OK Content-Type: application/json [ { "status": "success", "crop_product_uri": "https://app.coolfarmtool.org/crop_product/ABC123/", "crop_product_slug": "ABC123" } ] :reqheader X-Api-App-Authorisation: app key; see :doc:`authentication` :reqheader X-Api-Authorisation: api key; see :doc:`authentication` :statuscode 400: missing or incorrect form data Crop type Rice '''''''''''''' .. note:: When creating a rice crop product please note two additional fields: Flooding is a required parameter but optional to provide (if not provided a default value will be used). The time under cultivation may be entered directly in number of days. If it is not provided the IPCC 2019 default number of days based on farm location and region will be applied. Green manure is an optional parameter and may be provided as shown below .. code-block:: js "flooding": { "time_under_cultivation": { "value": 123, "unit": "d" }, "before_cultivation": "Not flooded pre-season (for < 180 days)", "during_cultivation": "Continuously flooded" }, "green_manure": { "amount": { "value": 6.6, "unit": "tonne / ha" } } .. _create-crop-assessment-endpoint: .. http:post:: /crop_product/ Create a rice crop product and save it to the database **Example request** .. sourcecode:: http POST /crop_product/ HTTP/1.1 Host: app.coolfarmtool.org Accept: application/json Content-Type: application/json .. literalinclude:: /../../api/v1/samples/crop_product_rice-calculate-input.json **Example response** .. sourcecode:: http HTTP/1.1 200 OK Content-Type: application/json [ { "status": "success", "crop_product_uri": "https://app.coolfarmtool.org/crop_product/ABC123/", "crop_product_slug": "ABC123" } ] :reqheader X-Api-App-Authorisation: app key; see :doc:`authentication` :reqheader X-Api-Authorisation: api key; see :doc:`authentication` :statuscode 400: missing or incorrect form data Dairy assessment ---------------- .. note:: When saving a dairy product to the database which uses a crop product as a feed item, you will need to create an existing crop product, either in the user interface or the API as specified in the :ref:`Crop assessment` section of this documentation. When sending a request to the /dairy_product/ endpoint, include the crop product as one of the feed components, as demonstrated below. .. code-block:: js { "herd_section": "Dairy calves", "crop_product": { "type": "Soyabean", "slug": null, // Add the slug of your crop product here "product_dry": { "value": 5, "unit": "tonne" }, "feed_type": "Soybean", "emissions_total": { "value": 22469.393582158074, "unit": "kg CO2e" } }, "dry_matter": { "value": 8, "unit": "kg" }, "certified": false } .. http:post:: /dairy_product/ Create a dairy product and save it to the database **Example request** .. sourcecode:: http POST /dairy_product/calculate/ HTTP/1.1 Host: app.coolfarmtool.org Accept: application/json Content-Type: application/json .. literalinclude:: /../../api/v1/samples/dairy_product-calculate-input.json **Example response** .. sourcecode:: http HTTP/1.1 200 OK Content-Type: application/json [ { "status": "success", "dairy_product_uri": "https://app.coolfarmtool.org/dairy_product/ABC123", "dairy_product_slug": "ABC123" } ] :reqheader X-Api-App-Authorisation: app key; see :doc:`authentication` :reqheader X-Api-Authorisation: api key; see :doc:`authentication` :statuscode 400: missing or incorrect form data .. http:post:: /farms/(str:farm_slug)/dairy_products/ Create a dairy product for a given farm slug and save it to the database **Example request** .. sourcecode:: http POST /farms/(str:farm_slug)/dairy_products/ HTTP/1.1 Host: app.coolfarmtool.org Accept: application/json Content-Type: application/json .. literalinclude:: /../../api/v1/samples/dairy_product-calculate-input.json **Example response** .. sourcecode:: http HTTP/1.1 200 OK Content-Type: application/json [ { "status": "success", "dairy_product_uri": "https://app.coolfarmtool.org/dairy_product/ABC123", "dairy_product_slug": "ABC123" } ] :reqheader X-Api-App-Authorisation: app key; see :doc:`authentication` :reqheader X-Api-Authorisation: api key; see :doc:`authentication` :statuscode 400: missing or incorrect form data