Google's documentation is like an ocean. It's not easy to find a right one to start. This note contains only basic things that I've already worked with. Try your own hand at Google's APIs will help you understand more.
π Github repo: dinhanhthi/google-api-playground
This note is mainly for Dialogflow APIs. However, I mention also the other services of Google.
- Dialogflow: SDK (other official site) | REST API
- Manage projects: Resource Manager SDK (other official site) | REST API
- Note: From version 2.0.0,resource-managerchange the package to@google-cloud/resource-manager. And from version3.0,0, the "folder" was introduced!
- Active API on some projects: Service Usage SDK | REST API
- Note: APIs can only be activated for Projects, neither folder nor organization!
When you use any NodeJS service, for example,
The 
opts is described here.π Link of all (dialogflow nodejs) samples on github.
The old version uses 
dialogflow and @type/dialogflow. The new version uses only one @google-cloud/dialogflow!On SDK documentation, they don't mention about the location in the 
parent property. For example, they say "parent can be projects/<Project ID or '-'>", but you can add the location information inside it like thatYou have to enable the Dialogflow API in the current project. Other wise, we meet below problem.
You can use Service Usage to enable a service on some project programmatically or go to beflow url to active it visually,
Google has announced that they will be discontinuing the Google Sign-In JavaScript Platform Library for web. You will have to switch to using Google Identity Services (or Sign In With Google or 
gsi). The old service will be completely discontinued on March 31, 2023.What's this 
gapi? You can use it completely inside an HTML file without using any backend.π List of samples (google apis javascript client).
π You have to use REST API in this case.
Tip: If you are using VSCode, you can install the Live Server extension to quickly create a server (port 
5500 by default). Just click the button at the bottom right of the file and a website will appear.π REST API.
π Node.js SDK.
Sometimes, the location infotmation is mentionned in the REST API but not in the SDK. For example, load the list of agents w.r.t. some location
- REST (different with the general case): this link.
- SDK (the same as the general case), in this, we just need to add "location" into the agentproperty, like
- Normally, it's easier if we use Node.js SDK.
- First, you need to create a Service Account, then create a key and download the JSON file. Follow these steps.
- Check an example code.
- Remark: the code above use requestwhich has been already deprecated! You can choose any alternative.
Remark: With keys generated from a service account (stored in JSON), we can only get 1 agent for methods like 
projects.agent.search although it says that we can get a list of agents. In this case, try to get access token via OAuth 2.0. With this, we can access to all projects instead of only 1 (which is used to generate the json file).π List of endpoints (containing location inside).
π LIst of location information you can use with Dialogflow.
You have to use the same endpoint and location information in the API/SDK. If you use them differently, for example,
You will meet an error like below,
In the SDK documention, they don't mention about the location you need to use in the 
agent property. For example, they say "parent can be projects/<Project ID or '-'>", but you can add the location information inside it like thatπ‘They are the same (for endpoints):
π Create here (then you need to choose a project / a folder / an organization)
πΒ Understanding roles.
- If you choose a project, there are some roles cannot be added because they belongs to folders/organization (eg. resourcemanager.projects.list)
- (ref) You have to pay (using Google Workspace or Google Identity) to create an organization or a folder.
If you already have a domain, you can try to create a Google Workspace and use it in 1 month of trial. After that, you can deactivate the Google Workspace account but the things on the Google Cloud Platform are still there and the organization you have created in Google Workspace is still working!
In case you wanna some tasks + don't wanna create a custom role (don't forget to check this list):
π Create a service account. (and also the key for it > then download the JSON file)
- By default, a service account can only access to the current project (even if you choose the roles which created in the organization/folder).
- If you want that service account can perform tasks in the organization/folder, you have to go to IAM & Admin > IAM > choose the organization / folder (yes, IAM is different for different project/organization/folder) > ADD > add the email of the service account to New principals and choose a role for it.
If you use SDK 
listProjectsAsync to list all projects in the organization, you can only list the projects in that organization, not the ones inside a folder even if that folder belongs to the organization.Quota: For each Service Account, the limit of number of projects you can create is 22. You can ask more but the better idea is to create another service account (and don't forget to remove the old one with its credentials).
The old version uses 
dialogflow and @type/dialogflow. The new version uses only one @google-cloud/dialogflow!For example, the returned type for 
getAgent() method can be defined as,π― Aim: Suppose that we want to create a new entities via API (including the system entities).
- List all intents from some agent: just put in the parentsomething likeprojects/<projectId>/agentand then click Execute. Don't forget to choose theintentViewasINTENT_VIEW_FULL(without this one, you cannot see the examples or "trainingPhrases") π Copy and remember the output of typeIntent.
- Create a new entities using this API. Again, put in parentasprojects/<projectId>/agnetand then in the Request body, paste an object which looks like the output in the previous step (remember to remove "name" sections, this section will be created by DF), then Execute.