Skip to content
This repository has been archived by the owner on Oct 21, 2021. It is now read-only.

how to upload data to IBMFoodTrust

Josh Horton edited this page Dec 16, 2019 · 5 revisions

How to upload data

This document describes how to upload data to the IBM Food Trust network. Data is encoded in an XML message, and uploaded to IBM Food Trust by an authenticated and registered user. If the POST upload operation is successful, a new asset is created on the network.

IBM Food Trust users will execute one of two methods to upload data:

  1. Upload data manually, using the Swagger API (human users)
  2. Upload data automatically, using a defined workflow (system users and applications).

In either case, the user (human, system or application) uploading the data must be authenticated (and registered with IBM Food Trust), as shown in the following IBM Food Trust flow diagram (Figure 1). The user includes their IBM Food Trust token with each submitted XML message:

Figure 1. IBM Food Trust Flow - uploading data

IBM Food Trust Flow

Prerequisites

To upload data (XML messages) to IBM Food Trust, the user (human, system or application) must have a valid IBMid. Each IBMid must also be registered with IBM Food Trust, by the Organization Administrator:

  1. Register human users: Register the user's IBMid (email address) with IBM Food Trust, at Manage Users Dashboard.

  2. Register system users and applications: Obtain a ServiceId for each system user, as described in the Prerequisite section in How To Get an Authentication Token for System Users.

Manual Submission

Use the following steps to manually (using the Swagger API) upload data to IBM Food Trust. An authenticated and registered user ID (human users only) is required. Each successfully submitted XML message creates an asset on the network:

  1. Sign in to IBM with your IBMid.
  2. Connect to the Swagger IBM Food Trust API.
  3. Expand the Assets POST /fs/connector/v1/assets API.
  4. From your local system, copy the XML message file contents (e.g. EPCIS event, Purchase Order, Receive Advice or Despatch Advice); then paste the contents into the Create Asset API Parameters asset field.
  5. At the bottom of the API, upload the XML message (data) by clicking the Try it out! button.
  6. If successful, a 201 response message is displayed. If an error occurs, a 40x response message is displayed, with an explanation. If necessary, correct the error and retry the Create asset API.

Automated Submission

Only authenticated system users or applications (ServiceId) can automatically upload data to IBM Food Trust. Before defining an automated workflow to upload data, ensure that the ServiceId has a valid token and is registered with IBM Food Trust. If necessary, follow the process to obtain a valid token (example POST request using CURL to send EPCIS_Observation.xml).

Complete the following process to configure a system user or application (authenticated ServiceId) to automatically upload data to IBM Food Trust:

  1. Retrieve a token for the ServiceId from IBM Food Trust Authentication.
  2. Start a POST request to: https://food.ibm.com/ift/api/connector/fs/connector/v1/assets
  3. Paste the token in the Authorization Header, as follows: Bearer <token>.
  4. Submit the XML message to IBM Food Trust.
  5. Receive a new Asset ID from IBM Food Trust, which indicates a successful POST and upload of data.

Curl

The following command line example POST request uses the cURL command to send the XML message file EPCIS_Observation.xml to the IBM Food Trust service (URL). The user's Bearer (onboarding) token is specified:

$ curl -X POST --header 'Content-Type: application/xml' --header 'Accept: application/json' --header 'Authorization: Bearer <ONBOARDING_TOKEN>' -d @EPCIS_Observation.xml 'https://food.ibm.com/ift/api/connector/fs/connector/v1/assets'

A successful POST returns the following message containing a list of the asset ids created:

[
  {"ids":
      ["urn:ibm:provenance:asset:event:observation:9dd5cfaf-802b-4c70-8ae3-0770232f61a1:default:default:e2952199846fee144b34f06ea5485d2afbb04edc7297c03bf19c03ab8b3060e6"]
  }
]

If necessary, review the CURL error responses and solutions.

Bash

A sample Bash script is available to configure an automated data submission workflow for system users and applications. The code snippet is shown below; the ServiceId authentication token, and the XML File to upload must be specified:

$ POST_IFT.sh -t <token> -f <File>

IBM Food Trust will return a new Asset ID for the uploaded data, or an error message.

Clone this wiki locally