For those who are confused like myself , I am consolidating the above steps mentioned by sparsht and fcaelen after working out all the issues that I faced:
1. hit the following URL manually or can make a GET request script :-
https://mycommunityurl.com/auth/oauth2/authorize?client_id=[CLIENT_ID]&response_type=code&redirect_uri=[REDIRECT_URI]
- Encode the [CLIENT_ID] to URL encoded format
- [REDIRECT_URI] is the URL you provide while registering your App under ADMIN>SYSTEM>API Apps .
It will redirect to the the provided [REDIRECT_URI] with code and tenant ID.
For Example -
https://[REDIRECT_URI]?code=[authorization_code]&user-id=[userid]&tenant=[tenant_Id]
Fetch the "authorization code" which is URL Encoded (decode it into string) and pass it as described below in Step 2.
2. Make a POST Curl Request to the given URL. Find the sample code below (for windows cmd users).
curl -X POST ^
https://mycommunityurl.com/api/2.0/auth/accessToken ^
-H "Content-Type: application/json" ^
-H "client-id: [CLIENT_ID]" ^
-d "{ \"client_id\":\"[CLIENT_ID]\", \"client_secret\":\"[CLIENT_SECRET]\", \"grant_type\":\"authorization_code\", \"redirect_uri\":\"[REDIRECT_URI]\", \"code\":\"[Decoded_authorization_code from step 1]\" }"
- [CLIENt_ID] , [CLIENT_SECRET],[REDIRECT_URI] are all that can be obtained while registering your App under ADMIN>SYSTEM>API Apps .
Sample Response Body on success
{
"response": {
"status": "success",
"message": "OK",
"http_code": 200,
"data": {
"access_token": "o5IV0yIiNDj/5lNJ6doJh08LX6SsDwtkDXDVmhGvRtI=",
"expires_in": 86400,
"lithium_user_id": "2d8c95ed-21dc-4ba6-ab9f-d3eff9c928ce",
"refresh_token": "XAAWIWKr38W33SlqYooR9OEJW0um9DoyB/o843rdIxk=",
"token_type": "bearer"
}
}
}
"access_token" will be used to make the calls.
3. Run the LIQL queries via script or curl using the access token from step 2.
Sample Python Code below:
import requests
ACCESS_TOKEN_URL = "https://mycommunityurl.com/api/2.0/search?q=SELECT%20*%20FROM%20users"
x=requests.get(
ACCESS_TOKEN_URL,
headers = {"Content-type" : "application/json", "client-id" : "[CLIENT_ID]","Authorization":"Bearer [Access_TOKEN]"},
)
x.json()
Sample Curl Code (Windows CMD Users) below:
curl --location --request GET "https://mycommunityurl.com/api/2.0/search?q=SELECT%20*%20FROM%20users" ^
-H "content-type: application/json" ^
-H "Authorization: Bearer [Access_Token]" ^
-H "client-id: [CLIENT_ID]"
- Make sure to include the 'Bearer' keyword in the authorization header as shown in the sample code.
Full Kudos and credits to fcaelen and sparsht