This application demonstrates how to consume the IM services from the OpenText Cloud Platform using Node.js. This is intended to be a server-side or cli app with the simplest possible set-up to get developers started making API calls to an OCP application using the OAuth client_credentials grant.
JavaScript
dotenv
Reads in environment variables with overrides in .env.
axios
Promise based HTTP client for the browser and node.js.
- Install the latest version of Node JS.
- You must have a trial set up with an organization and tenant. You will also need to create a test app and have the confidential client ID and secret values ready to use for authentication. For background information on this see the documentation.
-
Clone this repository and open it in your IDE. Visual Studio Code can be used for this if you don't have a preferred IDE.
-
Update the
.env
file and replace the values using the config for your OCP app. -
Create a file in the root of the project called
.env.secret
. Copy the following into it and replace the secret value using the config for your OCP app:CLIENT_SECRET=replace-with-clientSecret
This is for local development purposes only. The .env.secret file should never be committed to source control. The client secret should always be handled using a secure secret management procedure.
To run the application using Node.js, open a terminal in your IDE and run the following commands (from the project root).
npm install
npm start
As an example to get you started, the application will fetch a token and print the names of the Content Metadata service traits in your app to the console.
You can then add new samples in the ocp directory to make calls to other API endpoints and test interacting with the APIs using JavaScript. You can replace the existing traits code in callOcp and use the token to make other calls.
Uses the confidential client id and secret with the client_credentials
grant type. See fetchAccessToken for the implementation.
This example calls the Content Metadata Service and uses the following endpoint:
- GET Returns list of all trait definitions