3 Implement FTS

Use the following steps to implement FTS Services on your Unix/Linux system:

  1. Log In

  2. Set Environment Variables

  3. Retrieve OAUTH Token

Once you have implemented FTS Services, you can Call FTS Services.

Log In

Log in to your Unix/Linux Server.

Set Environment Variables

  1. Set environment variable for the CLIENT_ID.

    Command:

    export CLIENT_ID="<CLIENT ID from Pre Requisites>"

    Sample:

    export CLIENT_ID="RGBU_MFCS_STG116_APPID"
  2. Set environment variable for CLIENT_SECRET.

    Command:

    export CLIENT_SECRET="<CLIENT SECRET from Pre Requisites>"

    Sample:

    export CLIENT_SECRET="d0503225-cc58-456a-aee9-2c97c2f1bff1"
  3. Set environment variable for OCI_IAM_BASE_URL.

    Command:

    export OCI_IAM_BASE_URL="<OCI IAM URL from Pre Requisites>"

    Sample:

    export OCI_IAM_BASE_URL="https://idcs-ca69887b7ea4451ebdf967e2a383629e.identity.c9dev2.oc9qadev.com:443"
  4. Set environment variable for OCI_IAM_SCOPE.

    Command:

    export OCI_IAM_SCOPE="OCI IAM SCOPE from Pre Requisites"

    Sample:

    export OCI_IAM_SCOPE="rgbu:merch:MFCS-STG116"
  5. Set environment variable for hostname.

    The format that should be used for the hostname is rex.retail.<Region Name>.ocs.oraclecloud.com/<Customer Subnamespace>/RmsPlatformServices/services/private/FTSWrapper, where:

    • <Region Name> will be the region for your data center.

    • <Customer Subnamespace> will be specific to your company’s name and environment (production, stage, and so on).

    Command:

    export FTS_HOST_NAME="https://rex.retail.<Region from Pre Requisites>.ocs.oraclecloud.com/<Customer Subnamespace from Pre Requisites>/RmsPlatformServices/services/private/FTSWrapper 

    Sample:

    export FTS_HOST_NAME="https://rex.retail.us-phoenix-1.ocs.oc-test.com/rgbu-rex-rgbu-stg116-mfcs/RmsPlatformServices/services/private/FTSWrapper"

Retrieve OAUTH Token

To invoke Merchandising cloud FTS Services, you need to obtain an access token and use it as a bearer token.

  1. Run the curl command below to retrieve access token:

    Command:

    export OCI_IAM_TOKEN=$(curl -u $CLIENT_ID:$CLIENT_SECRET -H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" --request POST $OCI_IAM_BASE_URL/oauth2/v1/token -d "grant_type=client_credentials&scope=$OCI_IAM_SCOPE" | jq -r '.["access_token"]')
    

    Note:

    A token is generally valid for 1 hour.
  2. Check the OCI_IAM_TOKEN variable.

    Command:

    echo $OCI_IAM_TOKEN
    
    Example of an OAUTH Token

Call FTS Services

Once you have completed configuration, you can call FTS services from your Unix/Linux server.

Register a New Storage Prefix

Object Storage bucket prefixes must be registered to FTS.  Predefined prefixes are already available and it is recommended you use those. Refer to the predefined prefixes in the “File Transfer Services (FTS)” section of the Merchandising Operations Guide Volume 2.

If new prefixes are required, these will need to be registered. Please note this is only required only if you are adding additional new storage prefixes. If you are using existing, predefined prefixes, you do not need to use this service.

To call the Register a New Storage Prefix service, append /register/<new prefix> to the FTS_HOST_NAME.

Command:

curl -X PUT $FTS_HOST_NAME/register/<new prefix> -H "Accept-Language: en-US" -H "Authorization: Bearer $OCI_IAM_TOKEN"

Sample:

$ curl -X PUT $FTS_HOST_NAME/register/test_prefix -H "Accept-Language: en-US" -H "Authorization: Bearer $OCI_IAM_TOKEN"

List Files

To call the FTS list file service, append /listfiles to the FTS_HOST_NAME.

Command:

curl $FTS_HOST_NAME/listfiles  -H "Accept-Language: en-US" -H "Authorization: Bearer $OCI_IAM_TOKEN" 
Sample Response for List Files Command

Uploading Files

Uploading a file using the FTS service is a two-stage process.  Calling the Retrieve PAR for Uploading Files service returns a Pre Authenticated Request (PAR) in the accessUri key of the response.  That PAR is then used to perform the upload of the file to object storage.

  1. To call the Retrieve PAR for Uploading Files, append /upload to the FTS_HOST_NAME. The Retrieve PAR for Uploading Files service expects a JSON Request body with the following structure:

    {
        "listOfFiles": [
           {
              "storagePrefix": "string",
              "fileName": "string"
           }
        ]
    }

    Command:

    export ACCESS_URI=$(curl "$FTS_HOST_NAME/upload" -H "Accept-Language: en-US" -H "Authorization: Bearer $OCI_IAM_TOKEN" -H "Content-Type: application/json" -d '{"listOfFiles": [{"storagePrefix": "<prefix>", "fileName": "<filename>"}]}' | jq -r '.parList[] | .accessUri')

    Sample:

    export ACCESS_URI=$(curl "$FTS_HOST_NAME/upload" -H "Accept-Language: en-US" -H "Authorization: Bearer $OCI_IAM_TOKEN" -H "Content-Type: application/json" -d '{"listOfFiles": [{"storagePrefix": "incoming", "fileName": "RTLOG_1111_01.zip"}]}' | jq -r '.parList[] | .accessUri') 
    Sample Response for Retrieve PAR for Uploading Files Command
  2. Check the value of ACCESS_URI.

    Command:

    echo $ACCESS_URI
    Sample ACCESS_URI Value
  3. Upload the file to Object Storage using the PAR.

    Command:

    curl "$ACCESS_URI" --upload-file "<full path and filename"

    Sample:

    curl "$ACCESS_URI" --upload-file "RTLOG_1111_01.zip"
  4. Verify the upload using the List Files service.

    Command:

    curl $FTS_HOST_NAME/listfiles  -H "Accept-Language: en-US" -H "Authorization: Bearer $OCI_IAM_TOKEN"
    Sample List Files Response After Upload

Downloading Files

Downloading a file through the FTS service is a two-stage process. Calling the Retrieve PAR for Downloading Files service returns a Pre Authenticated Request (PAR) in the accessUri key of the response.  The PAR is then used to perform the download of the file from object storage.

  1. To call the Retrieve PAR for Downloading Files, append /download to FTS_HOST_NAME. The Retrieve PAR for Uploading Files service expects a JSON Request body with the following structure:

    {
        "listOfFiles": [
           {
              "storagePrefix": "string",
              "fileName": "string"
           }
        ]
    }

    Command:

    export ACCESS_URI=$(curl "$FTS_HOST_NAME/download" -H "Accept-Language: en-US" -H "Authorization: Bearer $OCI_IAM_TOKEN" -H "Content-Type: application/json" -d '{"listOfFiles": [{"storagePrefix": "<prefix>", "fileName": "<filename>"}]}' | jq -r '.parList[] | .accessUri')

    Sample:

    export ACCESS_URI=$(curl "$FTS_HOST_NAME/download" -H "Accept-Language: en-US" -H "Authorization: Bearer $OCI_IAM_TOKEN" -H "Content-Type: application/json" -d '{"listOfFiles": [{"storagePrefix": "incoming", "fileName": "RTLOG_1111_01.zip"}]}' | jq -r '.parList[] | .accessUri') 
    Sample Response for Retrieving PAR for Downloading Files
  2. Check the value of ACCESS_URI.

    Command:

    echo $ACCESS_URI
    Sample Value for the ACCESS_URI
  3. Download the file to Object Storage using the PAR.

    Command:

    curl "$ACCESS_URI" -O

    Sample:

    curl "$ACCESS_URI" -O
    Sample Download Response
  4. Verify the download.

    Command:

    ls <filename>

    Sample:

    ls RTLOG_1111_01.zip
    Sample Verification of Downloaded File

Delete Files

To call the Delete Files service:

  1. Append /delete to FTS_HOST_NAME. The Delete Files service expects a JSON Request body with the following structure:

    {
         "listOfFiles": [
             {
                 "storagePrefix": "string",
                 "fileName": "string"
             }
         ]
    }

    Command:

    curl -X DELETE $FTS_HOST_NAME/delete -H "Accept-Language: en-US" -H "Authorization: Bearer $OCI_IAM_TOKEN" -H "Content-Type: application/json" -d '{"listOfFiles": [{"storagePrefix": "<prefix>", "fileName": "<file name>"}]}'

    Sample:

    curl -X DELETE $FTS_HOST_NAME/delete -H "Accept-Language: en-US" -H "Authorization: Bearer $OCI_IAM_TOKEN" -H "Content-Type: application/json" -d '{"listOfFiles": [{"storagePrefix": "incoming", "fileName": "RTLOG_1111_01.zip"}]}'
    Sample Response for Delete Files
  2. Verify the delete using the List Files Services.

    Command:

    curl $FTS_HOST_NAME/listfiles  -H "Accept-Language: en-US" -H "Authorization: Bearer $OCI_IAM_TOKEN"
    List Files Response After Delete