Hi Alexander, I’m Balazs’ colleague. I put together the following Python code for trying to figure this out. This is not runnable as-is, but maybe you could spot some misuse of your APIs anyway. Could there potentially be a bug in how you populate the “data”-tag from the /output-endpoint?
# prepare the input to grasshopper model
string_data = json.dumps(shapediver_input, default=datetime_to_string)
# prepare to start a new session
sd_ticket_backend = config.get(...)
sd_base_url = config.get(...)
sd_ticket_url = "/".join([sd_base_url, 'api/v2/ticket', sd_ticket_backend])
resp = requests.post(sd_ticket_url)
print("post to api/v2/ticket=", resp.status_code, "\n")
full_data = resp.json()
session_id = full_data["sessionId"]
params = full_data["parameters"]
for id, param in params.items():
if param["name"] == "InputFromUI":
input_param_id = id # get the ID of the InputFromUI input
print('session id=', session_id)
print("input_param_id=", input_param_id, "\n")
f_size = len(string_data)
print("size=", f_size)
# request upload url for file asset
sd_query_upload_url = "/".join([sd_base_url,'api/v2/session',session_id,'file/upload'])
headers = {'Content-Type': 'application/json'}
payload = json.dumps({input_param_id: {"format": "application/json", "size": f_size}})
upload_url_response = requests.post(sd_query_upload_url, headers=headers, data=payload)
print('post to api/v2/session/:id/file/upload=', upload_url_response.status_code, "\n")
f_upload_url = upload_url_response.json()["asset"]["file"][input_param_id]["href"]
file_id = upload_url_response.json()["asset"]["file"][input_param_id]["id"]
# print('upload url=', f_upload_url)
print('file_id=', file_id, "\n")
# perform upload to assigned URL
upload_response = requests.put(f_upload_url, json=string_data)
print('put to upload file=', upload_response.status_code, "\n")
# get output from model, using uploaded file as input
sd_output_url = "/".join([sd_base_url, 'api/v2/session/{}/output'.format(session_id)])
data = json.dumps({input_param_id: file_id})
headers = {'Content-type': 'application/json'}
print('customization params=', data, "\n")
sd_object = requests.put(sd_output_url, headers=headers, data=data)
print('put to api/v2/session/:id/output=', sd_object.status_code, "\n")
# extract relevant part of response
outputs = sd_object.json()["outputs"]
params = []
for key, param in outputs.items():
if len(param["content"]) > 0:
params.append(param["content"][0])
return params
This produces an output like this:
post to api/v2/ticket= 201
session id= 97a2926f-3a45-48f6-9ab0-850088becb5a
input_param_id= 77e1d03e-3e03-49f6-8d5f-ae5c122326d2
size= 43187
post to api/v2/session/:id/file/upload= 200
file_id= 4b58e006-e68f-49f3-b8e1-80d9f208a830
put to upload file= 200
customization params= {"77e1d03e-3e03-49f6-8d5f-ae5c122326d2": "4b58e006-e68f-49f3-b8e1-80d9f208a830"}
put to api/v2/session/:id/output= 200
As for the actual content returned from this code we would expect this (only pasting a small part of it):
{
"data": [
1.0114815998326414,
1.0114815998326414,
0.8395958377695779,
0.8395958377695779,
0.6869420490842003,
0.6869420490842003,
0.4572,
0.4572,
0.4572,
0.3556000000000001,
0.3556000000000001,
0.3556000000000001
],
"name": "AreaOfMainLegsCircular",
"plugin": "CommPlugin_1",
"id": "16c1e4baa4fe2949a754a5950c066c16"
},
…but we are receiving this:
{
"data": 2,
"format": "data",
"name": "AreaOfMainLegsCircular"
},
Thank you for your help in this!
/Jonas