README.md
January 31, 2019 ยท View on GitHub
Functions API
Objective
- This README describes the setup the Functions API
Services used
- IBM Cloud Functions
- Lite API Management, which is part of IBM Cloud Functions
Setup the users functions API on IBM Cloud
The setup is automated in a bash script. You need an IBM Cloud account and an IBM platform key. This in an overview of the steps to follow.
- Get IBM platform key
- Configurations for bash script automation
- Options for the API usage in the functions API
- Enable the bash script for automation
- Execute the bash script and deploy the scores functions api
- Verify the setup on IBM Cloud
- Change the actions to each API call
- Save the needed data for the Game configuration
1. Get IBM platform key
Note: You have most likely completed this step when you set up the Scores API
- Logon to IBM Cloud use the "us-south" Region with the https://api.ng.bluemix.net API endpoint.
ibmcloud login -a https://api.ng.bluemix.net
- Create a IBM platform for your API key and name it (example my-ibmplatform-key) and provide a filename (example my-ibmplatform-key-key_file).
ibmcloud iam api-key-create my-ibmplatform-key -d "This is my API key to access the IBM platform" --file my-ibmplatform-key-key_file
Leave your terminal open.
2. Configurations for bash script automation
-
Open the file [YOUR-ROOT]bluecloudmirror/scores/scores.local.root.env. This file contains environment variables. This is a copy of scores.local.root.env-template. Most of the information will have been entered when setting up the Scores API.
-
Insert the needed values for following entries and do not change the rest.
Login relevant:
- IBMCLOUD_CLI_DEVOPS_PLATFORM_KEY="[YOUR_PLATFORM_KEY]"
- IBMCLOUD_USER_ID="[YOUR_IBMCLOUD_ID]"
Cloud Foundry Apps and services relevant:
- IBMCLOUD_CF_ORGANIZATION_NAME="[YOUR_ORGANIZATION_NAME]
Configuration relevant to Users API
These values can be found in the API Connect Explorer for the users-api in step 5 at the very end of this README
* IBMCLOUD_USERAPI_URL=""
* IBMCLOUD_USERAPI_CLIENT_ID=""
* IBMCLOUD_USERAPI_CLIENT_SECRET=""
Note: The IBMCLOUD_USERAPI_URL must have a trailing "/" (.../users-api/")
Note2: Check that IBMCLOUD_RESOURCE_GROUP="Default" matches the name of your Resource Group on IBM Cloud, Resource Groups seem to be case sensitive!
3. Enable the bash script for automation
Return to your open terminal.
cd [YOUR-ROOT]/bluecloudmirror/users/functions-api
chmod u+x *.sh
4. Execute the bash script and deploy the scores functions api
This bash script will deploy the users functions api. It uses the IBM Cloud Functions based on OpenWhisk and IBM Lite API Management. It creates actions, sequences and an api.
The bash script shows the execution steps. Some steps do take time, be patient.
After the excution you can find a log file in the this folder. The log is called ibmcloud-create-user-api.log. This log contains detailed information about the execution.
./ibmcloud-create-users-api.sh --install
Here is a sample output of the bash scipt.
TBD
5. Verify the setup on IBM Cloud
-
Login to IBM Cloud
-
Open Functions

- Select Actions in the navigation at the left hand side and verify the region "DALLAS" and select the same space which is used for the Cloud Foundry App. Here you can see the installed actions and sequences.

- Press API. Here you can find the list of APIs used in your Cloud Foundry space with Functions. Click on the API link you can see in the list.

- Here you can see a overview

- Choose Definition
Here you can see the uploaded API configuration. In Path you can find the API calls with the releated Actions. At the moment all related actions are sequences.

6. Change the actions to each API call
For the later usage for the API Explorer we need to change the binded actions in the operations for the functions API. The reason is that the uploaded API imformation does contain older auth information from older action instances.
- Change the used sequences for each API call, by using edit operation.

- Now replace each sequence with the concrete action.

- After the change it should look like this and you can explpore the API definition

7. Save the needed data for the Game configuration
Game relevant
- Select Explore in the API navigation tree and point to the postAddscore operation.

- Choose try in API defintion and copy the curl statement

curl --request POST \ --url https://service.us.apiconnect.ibmcloud.com/gws/apigateway/api/32e3eb9b8120/users/adduser \ --header 'accept: application/json' \ --header 'content-type: application/json' \ --data '{"id":4672220810969088}'
- Insert the api call in the Game App configuration file [YOUR-ROOT]/bluecloudmirror/local.env and save the file.
Example API call for addscore: https://service.us.apiconnect.ibmcloud.com/gws/apigateway/api/32e3eb69b8120/users/adduser
- API_USERS=users-url-not-defined (Change this parameter)
Now you can use the Users functions API in your Game App. :-)
Back Users API !