Skip to content

Commit 6801a1a

Browse files
author
Hugo Castilho
committed
Example script adding hosts to an existing target
1 parent f1c74f5 commit 6801a1a

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python
2+
"""
3+
Add hosts to an existing target
4+
5+
This action may only be performed by users with the required permissions,
6+
target API keys will no be able to create targets.
7+
8+
"""
9+
import requests
10+
from urllib.parse import urljoin
11+
12+
token = input("API Token: ")
13+
target_id = input("Target ID: ")
14+
15+
headers = {
16+
'Authorization': "JWT {}".format(token),
17+
'Content-Type': "application/json",
18+
}
19+
api_base_url = "https://api.stg.probely.com"
20+
endpoint = urljoin(api_base_url, "targets/{target_id}/assets/")
21+
22+
response = requests.post(
23+
endpoint.format(target_id=target_id),
24+
headers=headers,
25+
json={'host': 'example.com'})
26+
27+
print(response.request.headers)
28+
29+
if response.status_code == 200:
30+
print('\nSUCCESS')
31+
32+
else:
33+
print('\n[%s]\n%s' %(response.status_code, response.text))

0 commit comments

Comments
 (0)