ISDP-如何调用API?:操作步骤
操作步骤
- 请求token
以ISDP+查询问题单API接口调用作为示例,获取token口令地址如下:
beta环境地址:
https://isdpcloud-beta.sd.huawei.com/oauth2/oauth/rest_token
生产环境地址:
https://isdpcloud.huawei.com/oauth2/oauth/rest_token
请求类型: post
以下以测试beta环境地址为例Java调用示例:
请求参数:
body : {
"client_id":"isdp-saas-openapi",
"client_secret":"isdp-saas-openapi",
"grant_type":"password",
"username": "********************",
"password":""********************"
};
注:clien_id、client_secret、grant_type为固定参数, "username"和"password"在ISDP+对应租户后台管理创建,详见1.2节OpenAPI订阅说明。
响应参数:
{
"access_token": "1367******************f7bd3ce",
"token_type": "bearer",
"refresh_token": "579b******************9d5396b25f",
"expires_in": 1799,
"scope": "all",
"plat_user": {
"userId": XXXX,
"userNo": "sdcpOj******************BpwNMdYcz",
"userName": "XXXX beta",
"userType": "API",
"email": null,
"phone": null,
"tenantId": 1451,
"status": "0",
"deleteFlag": 0,
"integrationAccount": null,
"pwdUpdateDate": "2020-12-27T16:00:00.000+00:00",
"password": null,
"salt": null,
"machineCode": null,
"fingerMark": 0,
"faceRecog": 0,
"facesetToken": null,
"currentLoginType": "password",
"openId": null
}
}
图1 请求token
图2 请求token示例
- 从响应参数里面获取token口令
获取token口令,token = token_type + " "+ access_token,中间为英文输入法下的一个空格。
图3 获取token口令
以上图示例token口令为:bearer 1367d******************27-c80c5f7bd3ce,beaer后加一个英文输入法下的空格
- 传token调用接口
测试坏境:
https://isdpcloud-beta.sd.huawei.com/openapi/v1/openTask/createTask
生产环境:
https://isdpcloud.huawei.com/openapi/v1/openTask/createTask
请求类型: post
Authorization为:bearer 1367******************f7bd3ce
图4 传token调用接口
Body参数:
图5 Body参数
Python调用示例:
mport json
import urllib3
import requests
BETA_TOKEN_URL = "https://isdpcloud-beta.sd.huawei.com/oauth2/oauth/rest_token"
PRO_TOKEN_URL = "https://isdpcloud.huawei.com/oauth2/oauth/rest_token"
def get_token(beta_or_pro):
url = BETA_TOKEN_URL if beta_or_pro == 'beta' else PRO_TOKEN_URL
headers = {
"Content-Type": "application/json",
}
data_json = {
"client_id": "isdp-saas-openapi",
"client_secret": "isdp-saas-openapi",
"grant_type": "password",
"username": "sdcpO******************wNMdYcz",
"password": "iEVJNc******************QluW8R"
}
data_str = json.dumps(data_json)
urllib3.disable_warnings() # 忽略SSL告警
resp = requests.request("POST", url, data=data_str, headers=headers, verify=False)
# print("get_token.result = ", resp.text)
if resp.status_code == 200:
json_result = json.loads(resp.text)
if "access_token" in json_result:
result = json_result['token_type'] + " " + json_result['access_token']
return result
else:
return ""
else:
return ""
def call_api(token, url, data_json):
headers = {
"Content-Type": "application/json",
"Authorization": token,
}
data_str = json.dumps(data_json)
urllib3.disable_warnings() # 忽略SSL告警
resp = requests.request("POST", url, data=data_str, headers=headers, verify=False)
print(resp.status_code, resp.text)
if __name__ == '__main__':
token_str = get_token('beta')
print("token =", token_str)
api = "https://isdpcloud-beta.sd.huawei.com/openapi/v1/openTask/createTask"
data = {
"taskQueries": [{
"customerTaskId": 1234567899,
}]
}
call_api(token_str, api, data)
- 调用GaussDB(DWS) API接口_数据仓库服务调用API_如何调用API_在DWS中调用API
- 调用API_API调用流程_API网关APIG-华为云
- 开放API_API开放流程_调用API-华为云
- 手写识别api_识别图片文字api_文字识别api_调用_ocr
- 华为云CodeArts API_如何在CodeArts API中发布API
- 域名转出-域名如何转出-域名转出流程-域名转出操作步骤
- 华为云CodeArts API_如何在CodeArts API中设置API的设计规范?
- 调用函数_函数调用方式_函数工作流 FunctionGraph-华为云
- 华为云CodeArts API_如何在CodeArts API中设置请求参数?
- 华为云CodeArts API_如何利用CodeArts API设计一个接口?