GetPublicApiClient

get_public_api_client(app_name_header, on_behalf_of_header, client_type_header, client_id, client_secret)
Expand source code
get_public_api_client(app_name_header, on_behalf_of_header, client_type_header, client_id, client_secret):
"""
Description
-----------
Method 1, To get the client object of QDC Api using client id and client secret.
Args
----
app_name_header: Name of the Client.
on_behalf_of_header: Name of the user who is initiating the request.
client_type_header: Client code type connecting to QDC Api.
client_id: Please request client id by contacting QDC Support.
client_secret: Please request client id by contacting QDC Support.
Returns
-------
object: Authenticated client object.
None: In case of an failure.
Usages
------
# Please request client id/secret through QDC team
# qdc_api is the name of the module
client_id = ""
client_secret = ""
appname = "ai hub"
on_behalf_of = "user_name"
client_type = "Python"
public_api_client = qdc_api.get_public_api_client(appname, on_behalf_of, client_type, client_id, client_secret)
"""
response = requests.post(ACCESS_TOKEN_URL, auth=(client_id, client_secret))
if response.status_code == 200:
token = json.loads(response.text)["access_token"]
print(f"Token acquired: {token}")
else:
print(f"Failed to acquire token: {response.text}")
exit()
# Below headers are mandatory for now, please set X-QCOM-OnBehalfOf and X-QCOM-TracingId accordingly
qdc_headers = {
"X-QCOM-TokenType": "OAuth",
"X-QCOM-ClientId": client_id,
"X-QCOM-AppName": app_name_header,
"X-QCOM-OnBehalfOf": on_behalf_of_header,
"X-QCOM-ClientType": client_type_header,
}
# Create the client using access token
return AuthenticatedClient(base_url=API_BASE_URL, headers=qdc_headers, token=token)

Description

Method 1, To get the client object of QDC Api using client id and client secret.

Arguments

  • app_name_header: Name of the Client.
  • on_behalf_of_header: Name of the user who is initiating the request.
  • client_type_header: Client code type connecting to QDC Api.
  • client_id: Please request client id by contacting QDC Support.
  • client_secret: Please request client id by contacting QDC Support.

Returns

  • object: Authenticated client object.
  • None: In case of an failure.

Usages

  • Please request client id/secret through QDC team
  • qdc_api is the name of the module
client_id = ""
client_secret = ""
appname = "ai hub"
on_behalf_of = "user_name"
client_type = "Python"
public_api_client = qdc_api.get_public_api_client(appname, on_behalf_of, client_type, client_id, client_secret)