52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
import requests
|
|
import Apikeys
|
|
import pprint
|
|
|
|
PP = pprint.PrettyPrinter(indent=4)
|
|
APIKEY = Apikeys.SANDBOX
|
|
HEADERS = {"content-type": "application/json", "X-Api-Key": APIKEY}
|
|
BASEURL = "https://api.northpass.com/v2/migration"
|
|
|
|
def create_project():
|
|
"""
|
|
Function to create a project with just a name. While ID is in the example payload, it isn't needed.
|
|
Will generate a project ID for you in the return that you can use to transfer everything.
|
|
Note that it will not give you an error if a project already exists with that name!
|
|
"""
|
|
payload = { "data": {
|
|
"type": "migration_projects",
|
|
"attributes": {
|
|
"name": "My Second Migration Project"
|
|
},
|
|
} }
|
|
create_req = requests.post(f"{BASEURL}/projects", headers=HEADERS, json=payload)
|
|
print(payload)
|
|
print(create_req.status_code)
|
|
print(create_req.text)
|
|
|
|
|
|
def get_all_projects():
|
|
"""
|
|
Returns all projects. Leverage PrettyPrint or uncomment the name to just return names and ids.
|
|
"""
|
|
get_proj = requests.get(f"{BASEURL}/projects", headers=HEADERS)
|
|
print(get_proj.status_code)
|
|
# PP.pprint(get_proj.json())
|
|
|
|
for items in get_proj.json()['data']:
|
|
print(f"{ items['attributes']['name'] } -- { items['id'] }")
|
|
|
|
def get_specific_project():
|
|
"""
|
|
Returns results from a specific project.
|
|
"""
|
|
proj_id = "13aa7aed-3fb5-4488-9185-3befd0c1ae86"
|
|
get_spec_proj = requests.get(f"{BASEURL}/projects/{proj_id}", headers=HEADERS)
|
|
print(get_spec_proj.status_code)
|
|
PP.pprint(get_spec_proj.json())
|
|
|
|
if __name__ == "__main__":
|
|
# create_project()
|
|
# get_all_projects()
|
|
get_specific_project()
|