Uploading your API usage to the IBM License Service

After retrieving the number of API calls made, upload the count to the IBM License Service to store and track your API usage.


To upload the number of API calls to the License Service, you can retrieve the details, create the payload, and post the details manually, or you can create a script and run it against the namespace where your API Connect instance is installed.

Retrieving and uploading details manually

  1. Retrieve the upload token from the License Service as follows:

    oc get secret ibm-licensing-upload-token -n ibm-common-services -o=jsonpath="{.data.token-upload}"  |  base64 --decode
  2. Retrieve the metadata annotations from the analytics-storage pod that was previously used to obtain the number of API calls:

    oc describe pod <analytics-storage-pod-name>
  3. Check the contents described in the metadata.annotations section, and create the payload for your data upload by copying and pasting the details into a JSON file as follows:

      "cloudpakId": "<enter-value>",
      "cloudpakName": "<enter-value>",
      "cloudpakMetric": "RESOURCE_VALUE_UNIT",
      "productId": "<enter-value>",
      "productName": "<enter-value>",
      "productMetric": "MONTHLY_API_CALL",
      "productCloudpakRatio": "<enter-value>",
      "metricValue": <enter-your-number-of-api-calls>,
      "aggregationPolicy": "ADD"
  4. Run the following command against the analytics-storage pod and post the payload you created in the previous step to the License Service:

    kubectl exec -it <analytics-storage-pod-name> -- \
    curl -k -X POST -H 'Content-Type: application/json' -i 'https://ibm-licensing-service-instance.ibm-common-services.svc.cluster.local:8080/v2/metric_upload?token=<upload_token>' --data <payload>

Retrieving and uploading details with a script

Alternatively, if you install jq, you can create a script to complete these steps by saving the following to a shell script and running it as follows:

  1. Save the following as a shell script, for example, my-upload-script.sh:

    TOKEN=$(kubectl get secret ibm-licensing-upload-token -n ibm-common-services -o json | jq -r '.data."token-upload" | @base64d')
    POD=$(kubectl get po -n $NAMESPACE -o custom-columns=NAME:.metadata.name | grep -e "storage-master-0" | head -n 1)
    PAYLOAD=$(kubectl get po $POD -n $NAMESPACE -o json | jq --arg CALLS "$CALLS" '.metadata.annotations | { cloudpakId: .cloudpakId, cloudpakName: .cloudpakName, cloudpakMetric: "RESOURCE_VALUE_UNIT", productId: .productID, productName: .productName, productMetric: .productMetric, productCloudpakRatio: .productCloudpakRatio, metricValue: $CALLS|tonumber, aggregationPolicy: "ADD"  }' )
    RESULT=$(kubectl exec -it $POD -n $NAMESPACE -- curl -k -X POST https://ibm-licensing-service-instance.ibm-common-services.svc.cluster.local:8080/v2/metric_upload?token=$TOKEN -H 'Content-Type: application/json' -d "$PAYLOAD")
    echo $RESULT
  2. Run the script together with the namespace where your API Connect instance is installed and the number of API calls made:

    ./my-upload-script.sh <namespace> <your-number-of-api-calls>