簡介
本文說明如何使用安全存取API透過curl來管理目的地清單。
必要條件
需求
思科建議您瞭解以下主題:
採用元件
本文中的資訊係根據以下軟體和硬體版本:
本文中的資訊是根據特定實驗室環境內的裝置所建立。文中使用到的所有裝置皆從已清除(預設)的組態來啟動。如果您的網路運作中,請確保您瞭解任何指令可能造成的影響。
設定
1. 建立您的API金鑰
導航到安全訪問控制台。
- 點選
Admin > Api Keys > Add
建立API金鑰1
建立API金鑰2
- 根據需要增加所需的
API Key Name、Description (Optional)、Expiry Date
建立您的API金鑰3
- 在
Key Scope下,選擇Policies,然後選擇「擴展策略」
- 選擇
Destination Lists,然後 Destinations
- 如果需要,請更改
Scope,否則保留為 Read/Write
- 按一下
CREATE KEY
建立您的API金鑰4
- 複製
API Key和 Key Secret ,然後按一下 ACCEPT AND CLOSE
建立API金鑰5
注意:複製API機密的機會只有一個。Secure Access不會儲存您的API密碼,您無法在最初建立後檢索它。
2. 生成API訪問令牌
要生成API訪問令牌,請發出令牌授權請求:
令牌授權請求
使用您為組織建立的安全訪問API憑據來生成API訪問令牌。
- 在curl範例中,替代您的Secure Access API金鑰與密碼
curl --user key:secret --request POST --url https://api.sse.cisco.com/auth/v2/token -H Content-Type: application/x-www-form-urlencoded -d grant_type=client_credentials
注意:安全訪問OAuth 2.0訪問令牌在一小時(3600秒)後過期。建議您不要刷新訪問令牌,直到該令牌即將過期。
3. 管理目標清單
管理目標清單的方法有多種,包括:
獲取所有目標清單
打開windows命令提示符或Mac terminal運行命令:
curl -L --location-trusted --request GET --url https://api.sse.cisco.com/policies/v2/destinationlists -H "Authorization: Bearer YourAccessToken" -H "Content-Type: application/json"
樣本輸出的程式碼片段:
{"id":23456789,"organizationId":1234567,"access":"none","isGlobal":false,"name":" Test Block list","thirdpartyCategoryId":null,"createdAt":1694070823,"modifiedAt":1702819637,"isMspDefault":false,"markedForDeletion":false,"bundleTypeId":2,"meta": {"destinationCount":2,"domainCount":2,"urlCount":0,"ipv4Count":0,"applicationCount":0}
記下輸出的id欄位下面列出的destinationListId,該欄位進一步用於此目標清單特定的GET、POST或DELETE請求。
取得目的地清單中的所有目的地
- 使用此先前提及步驟獲取
destinationListId,然後獲取所有目標清單
打開windows命令提示符或Mac terminal運行命令:
curl -L --location-trusted --request GET --url https://api.sse.cisco.com/policies/v2/destinationlists/destinationListId/destinations -H "Authorization: Bearer YourAccessToken"
輸出範例:
{"status":{"code":200,"text":"OK"},"meta":{"page":1,"limit":100,"total":3},"data": [ {"id":"415214","destination":"cisco.com","type":"domain","comment":null,"createdAt":"2024-02-20 09:15:46"},{"id":"7237895","destination":"www.cisco.com","type":"domain","comment":null,"createdAt":"2024-02-20 10:19:51"},{"id":"29275814","destination":"10.10.10.10","type":"ipv4","comment":null,"createdAt":"2024-02-20 09:15:46"},{"id":"71918495","destination":"www.subdomain.cisco.com/resoucre","type":"url","comment":null,"createdAt":"2024-02-20 10:29:02"} ]}
建立新的目的地清單
打開windows命令提示符或Mac terminal運行命令:
curl -L --location-trusted --request POST --url https://api.sse.cisco.com/policies/v2/destinationlists -H "Authorization: Bearer YourAccessToken" -H "Content-Type: application/json" -H "Accept: application/json" -d "{\"access\":\"none\",\"isGlobal\":false,\"name\":\"Destination List Name\"}"
輸出範例:
{"id":23456789,"organizationId":1234567,"access":"none","isGlobal":false,"name":"API List 1","thirdpartyCategoryId":null,"createdAt":1708417690,"modifiedAt":1708417690,"isMspDefault":false,"markedForDeletion":false,"bundleTypeId":1,"meta":{"destinationCount":0}}
將目的地新增至目的地清單
- 使用此先前提及步驟獲取
destinationListId,然後獲取所有目標清單
打開windows命令提示符或Mac terminal運行命令:
curl -L --location-trusted --request POST --url https://api.sse.cisco.com/policies/v2/destinationlists/{destinationListId}/destinations -H "Authorization: Bearer YourAccessToken" -H "Content-Type: application/json" -d "[{\"destination":"cisco.com\"},{\"destination\":\"10.10.10.10\"},{\"destination\":\"www.subdomain.cisco.com\/resource\"}]"
輸出範例:
{"status":{"code":200,"text":"OK"},"data":{"id":17804929,"organizationId":1234567,"access":"none","isGlobal":false,"name":"API List 1","thirdpartyCategoryId":null,"createdAt":1708417690,"modifiedAt":1708420546,"isMspDefault":false,"markedForDeletion":false,"bundleTypeId":1,"meta": {"destinationCount":3}}}
刪除目的地清單
- 使用此先前提及步驟獲取
destinationListId,然後獲取所有目標清單
打開windows命令提示符或Mac terminal運行命令:
curl -L --location-trusted --request DELETE --url https://api.sse.cisco.com/policies/v2/destinationlists/destinationListId -H "Authorization: Bearer YourAccessToken"
輸出範例:
{"status":{"code":200,"text":"OK"},"data":[]}
從目的地清單刪除目的地
- 使用此先前提及步驟獲取
destinationListId,然後獲取所有目標清單
- 取得清單
id 中需要使用此先前提及步驟刪除的特定目的地的目的地清單
打開windows命令提示符或Mac terminal運行命令:
curl -L --location-trusted --request DELETE --url https://api.sse.cisco.com/policies/v2/destinationlists/destinationListId/destinations/remove -H "Authorization: Bearer YourAccessToken" -H "Content-Type: application/json" -H "Accept: application/json" -d "[id1,id2]"
輸出範例:
{"status":{"code":200,"text":"OK"},"data":{"id":17804929,"organizationId":1234567,"access":"none","isGlobal":false,"name":"API List 1","thirdpartyCategoryId":null,"createdAt":1708417690,"modifiedAt":1708525645,"isMspDefault":false,"markedForDeletion":false,"bundleTypeId":1,"meta":{"destinationCount":2}}}
疑難排解
安全訪問API終端使用HTTP響應代碼表示API請求成功或失敗。一般而言,2xx範圍內的代碼表示成功,4xx範圍內的代碼表示由所提供資訊導致的錯誤,而5xx範圍內的代碼表示伺服器錯誤。解決問題的方法取決於收到的響應代碼:
REST API -響應代碼1
REST API -響應代碼2此外,在排除API相關錯誤或問題時,以下列出了要注意的速率限制:
相關資訊