How to set direct text input within fetch request

Hi,

I’m trying to make a PUT request (using fetch) to the geometry backend API to set the contents of a direct text input within my GH script as JSON data. The request seems to be successful, but the outputs are unchanged which make me think the parameters aren’t sent correctly. I’m probably missing something obvious, but any help would be appreciated. Code snippet below

const computationRequest = async (data) => {
    const computeUrl = await sessionInit;
    fetch(computeUrl, {
        method: "PUT",
        headers: {
            "Content-Type": "application/json"
        },
        data: {
            "max_wait_time": 10000,
            "exports": {
                "id": ""
            },
            parameters:
            {
                "a8999616-f735-42a3-a81d-a520962a3a65": //Have tried setting this as a JSON object and using JSON.stringify
                {
                    "Building Length": 50,
                    "Building Width": 50,
                    "Stories": 6,
                    "FTF": 7,
                    "Finishes": 0.25,
                    "Services": 0.5,
                    "Clear Height": 2.5,
                    "SDL": 2.5,
                    "Imposed": 5,
                    "Grid X": 7.6,
                    "Grid Y": 7.6,
                    "Beam Divisions": 3,
                    "Target Util": 0.8,
                    "Framing": 0,
                    "Slab": 0
                }
            }
        }
    }

Do you want to compute an export or the outputs of a model?
Your request body looks like an export request, but I see two issues:

  • exports.id is not set
  • All parameter values must be stringified (i.e. JSON.stringify in your case)

You might want to consider using our SDK, which will simplify what you want to achieve. The SDK offers a function utils.submitAndWaitForExport which allows you to submit an export request and wait for the result.

An example on how to use submitAndWaitForExport and submitAndWaitForCustomization: ServerlessExample-TwitterBot/modelutil.ts at 7e0cfc003463b62dae6e924ace903df1b1c06630 · shapediver/ServerlessExample-TwitterBot · GitHub

Hi Alexander,

Thank you for the reply. I’m only trying to compute the outputs of the model, which in this case is a single “direct data output” that also happens to be a JSON object. I’ve copied in a link to my shape diver model, the input for my parameter and the output I receive. I’d really rather keep it set up as it for now if possible, so if you can offer any advice on what i’m doing wrong it would be really appreciated.

Model
https://www.shapediver.com/app/m/sd-scheme-designer-master-v0-0-1-3

Input
image

Output (Which is unchanged from calculation from the default input values)

Ok, first step is that you will need to use an output request.
Your request body will look like this:

{
  "your parameter id": "your stringified JSON"
}

A warning: In the longer run you should aim to use the SDK, it will simplify your life.

Hi Alexander,

I believe that’s what im doing already, see image below - let me know if i’ve missed anything. Note how the grid spacing does not update. Worth also noting that if I change the value directly in the shapediver library the computation works just fine.

API request via hoppscotch

Output with Grid X at 7.1m

Output with grid x at 12.0m

Could you provide the precise JSON body you are transmitting please (such that it can be copied and pasted)?

Hi Alexander,

Never got to the bottom of why this wasn’t working, so swapped to the SDK as suggested and everything seems to be working ok.

Thanks for your help!

@Dan_Cole great, many thanks for your feedback!