10-26-2022 07:59 PM
Hi,
I am looking for an API call that can retrieve the IWO recommender's total actions.
Is there any way to achieve this goal?
BR.
Solved! Go to Solution.
11-01-2022 06:15 AM
Hi LeeLiao,
Using the turbonomic API guide (https://docs.turbonomic.com/pdfdocs/Turbonomic_API_PRINT_8.0.0.pdf) the easiest thing to do is just search for the endpoint in the PDF (eg. /api/v3/markets/Market/actions which starts around page 161). This will show you the acceptable values like actionStateList can be DISABLE/RECOMMEND/PENDING_ACCEPT/ACCEPTED etc..
10-27-2022 06:40 AM - edited 10-27-2022 06:41 AM
If you are able to access & authenticated to the normal Intersight API you would just prepend 'https://intersight.com/wo' to the turbonomic API endpoints. For example:
https://intersight.com/wo/api/v3/markets/Market/actions
While not 100%, most of the turbo api endpoints can be found at:
https://docs.turbonomic.com/pdfdocs/Turbonomic_API_PRINT_8.0.0.pdf
The other way is just to open your browser developer tools and go to the network tab and see what endpoints it is calling as you click through the UI.
I've also have a very basic python example looking for an instance called 'te-useast-aws' and printing the recommended actions:
10-27-2022 08:12 AM
Hi Brian:
thank you for your reply.
I ran the example.py but got the below error.
Traceback (most recent call last):
File "/Users/liaoyi-ming/Desktop/SoftPro/IWOApiExample/example.py", line 21, in <module>
getActions()
File "/Users/liaoyi-ming/Desktop/SoftPro/IWOApiExample/example.py", line 7, in getActions
RESPONSE = requests.request(
File "/opt/homebrew/Caskroom/miniforge/base/envs/tcb/lib/python3.10/site-packages/requests/api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
File "/opt/homebrew/Caskroom/miniforge/base/envs/tcb/lib/python3.10/site-packages/requests/sessions.py", line 573, in request
prep = self.prepare_request(req)
File "/opt/homebrew/Caskroom/miniforge/base/envs/tcb/lib/python3.10/site-packages/requests/sessions.py", line 484, in prepare_request
p.prepare(
File "/opt/homebrew/Caskroom/miniforge/base/envs/tcb/lib/python3.10/site-packages/requests/models.py", line 372, in prepare
self.prepare_auth(auth, url)
File "/opt/homebrew/Caskroom/miniforge/base/envs/tcb/lib/python3.10/site-packages/requests/models.py", line 603, in prepare_auth
r = auth(self)
File "/Users/liaoyi-ming/Desktop/SoftPro/IWOApiExample/intersight_auth.py", line 107, in __call__
auth_header = _get_auth_header(
File "/Users/liaoyi-ming/Desktop/SoftPro/IWOApiExample/intersight_auth.py", line 56, in _get_auth_header
b64_signed_auth_digest = _get_rsasig_b64(secret_key, string_to_sign.encode())
File "/Users/liaoyi-ming/Desktop/SoftPro/IWOApiExample/intersight_auth.py", line 47, in _get_rsasig_b64
return b64encode(key.sign(
TypeError: _EllipticCurvePrivateKey.sign() takes 3 positional arguments but 4 were given
I generate the API key from intersight and modify the example.py as following:
import json
1 import requests
2
3 from intersight_auth import IntersightAuth
4
5 def getActions():
6 RESPONSE = requests.request(
7 method="GET",
8 url="https://intersight.com/wo/api/v3/supplychains?disable_hateoas=true&environment_type=HYBRID& uuids=Market",
9 auth=AUTH
10 )
11
12 record = RESPONSE.json()
13
14 print(record)
15
16 #Configure Intersight API token
17 AUTH = IntersightAuth(
18 secret_key_filename='SecretKey.txt',
19 api_key_id='6333c2557564612d33496a74/6333c2557564612d33496a78/635a99bf7564612d30bc273b'
20 )
21
22 getActions()
Where can fix the error?
10-27-2022 09:24 AM
Hi LeeLiao,
Is the API key you are using for schema version 2 or 3? You'll want to use the version 2 with this example, looks like you might have a v3 elliptic curve key
v2 secret key file starts with: -----BEGIN RSA PRIVATE KEY-----
v3 secret key files starts with : -----BEGIN EC PRIVATE KEY-----
10-27-2022 07:18 PM
Hi Brian:
thank you for your reply.
the query work!! after changing the API version to v2.
but I am facing another issue with the API call.
I use the below API call but got a "bad request" response.
https://intersight.com/wo/api/v3/markets/Market/actions/stats?disable_hateoas=true
{'error': {'status_code': 400, 'status': 'Bad Request'}}
I use the browser's develop mode to get the API URL.
Is there any mistake about this URL?
10-28-2022 05:33 AM
Try starting out one level up at just to confirm you can retrieve any data:
https://intersight.com/wo/api/v3/markets/Market/actions?disable_hateoas=true
The '/actions/stats' in your above link only supports POST which is why it is probably erroring out. For that you would need to do something like the following using the payload information from your browser tools or the turbonomic api docs:
import json
import requests
from intersight_auth import IntersightAuth
def postActions():
payload = '''{
"actionInput":{
"actionStateList":[
"PENDING_ACCEPT"
],
"environmentType":"ONPREM",
"groupBy":[
"actionModes"
]
},
"relatedType":"VirtualMachine",
"scopes":[
"Market"
]
} '''
RESPONSE = requests.request(
method="POST",
url="https://intersight.com/wo/api/v3/markets/Market/actions/stats?disable_hateoas=true",
auth=AUTH,
data=payload
)
record = RESPONSE.json()
print(record)
#Configure Intersight API token
AUTH = IntersightAuth(
secret_key_filename='SecretKey.txt',
api_key_id='xxxx/yyyy/zzzz'
)
postActions()
Which in my instance returns:
[{'date': '2022-10-28T12:28:51Z', 'statistics': [{'name': 'numActions', 'filters': [], 'values': {'max': 151.0, 'min': 151.0, 'avg': 151.0, 'total': 151.0}, 'value': 151.0}, {'name': 'numEntities', 'filters': [], 'values': {'max': 126.0, 'min': 126.0, 'avg': 126.0, 'total': 126.0}, 'value': 126.0}, {'name': 'costPrice', 'filters': [{'type': 'property', 'value': 'savings'}], 'units': '$/h', 'values': {'max': 0.3204228, 'min': 0.3204228, 'avg': 0.3204228, 'total': 0.3204228}, 'value': 0.3204228}]}]
10-31-2022 06:05 PM
Hi Brian:
thank you for your patience and reply.
I can get info. from below URL.
https://intersight.com/wo/api/v3/markets/Market/actions?disable_hateoas=true
Where can I search the parameter of this POST method?
https://intersight.com/wo/api/v3/markets/Market/actions?disable_hateoas=true
11-01-2022 06:15 AM
Hi LeeLiao,
Using the turbonomic API guide (https://docs.turbonomic.com/pdfdocs/Turbonomic_API_PRINT_8.0.0.pdf) the easiest thing to do is just search for the endpoint in the PDF (eg. /api/v3/markets/Market/actions which starts around page 161). This will show you the acceptable values like actionStateList can be DISABLE/RECOMMEND/PENDING_ACCEPT/ACCEPTED etc..
12-26-2022 05:22 PM
Hi Brian:
Recently, I ran the script but got the below errors.
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/local/lib/python3.10/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.10/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python3.10/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/appdynamics/src/example.py", line 32, in <module>
getActions()
File "/opt/appdynamics/src/example.py", line 19, in getActions
record = RESPONSE.json()
File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
What the problem is?
BR
01-04-2023 06:34 AM
It seems like it is not receiving a valid JSON response back, you may need to add additional print statements to troubleshoot what is being returned, in the example above adding print(RESPONSE.text) above the record = RESPONSE.json() would return additional information.
May also be helpful if you could add which API endpoint you are trying to use, whether you are GET/POST/Update/Delete, and the payload if applicable.
Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: