Skip to main content
msc23
Explorer
April 23, 2024
Solved

Sandbox API Login: return values?

  • April 23, 2024
  • 2 replies
  • 1712 views

i try to login via a python script, after some struggeling with the certificates i get a return code 200.

but when i try to parse the return value it's not a json object (or structure) it's html.

 

login-request and check response:

 

response = requests.post(loginURL, json=login_data)
print(f"response status code : {response.status_code}")
if response.status_code == 200:
print(response.text)
try:
json_data = response.json()
for key in json_data:
print(key)
except ValueError as e:
print("some ERROR raised:")
print(e)

 

and the print of the response ist html:

<!DOCTYPE html><html lang="en"><head>
<meta charset="utf-8">
<title>FortiSandbox</title>
<base href="/ng/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<style>@charset "UTF-8";body{font-family:Lato,Helvetica,Arial,sans-serif}body{font-weight:var(--nu-theme-dimension-normal-font-weight)}body{background-color:rgb(var(--nu-theme...................

(and much more, but no values, like a sessionid oder similar)

 

 

any hints where i went wrong?

thanks a lot!

 

Best answer by ebilcari

According to FNDN documentation the URL seems correct but the password parameter should be changed to passwd

If not joined yet I would strongly suggest you to join the developer network. Two sponsor approvals are needed and your Fortinet local representative can help with that.

2 replies

ebilcari
Staff
Staff
April 23, 2024

What is the API call in this case? Maybe try with an API client like Postman or curl as a start. I don't have experience with python but based on the result it seems like it's parsing the web page source.

Emirjon
msc23
msc23Author
Explorer
April 24, 2024

sorry, maybe it's a misunderstanding. 

i make an request to a URL 

loginURL = "https://fortisand-api.our-donain.com/"

the login-data (from the FortiSandbox-4.4.3-JSON-API Reference):

login_data = {
"method": "exec",
"params": [
{
# "url": "/sys/login/user",
"user": username,
"password": password
}
],
"id": 1,
"ver": "2.3"

and then getting the response:

response = requests.post(loginURL, json=login_data)

but the response contains only html. 

so how can i get the session-id in this case to make further calls to the fortisandbox?

 

is there an error on the URL?

 

any help is appreciated!

thanks in advance!

ebilcari
Staff
ebilcariAnswer
Staff
April 25, 2024

According to FNDN documentation the URL seems correct but the password parameter should be changed to passwd

If not joined yet I would strongly suggest you to join the developer network. Two sponsor approvals are needed and your Fortinet local representative can help with that.

Emirjon