200 OK response - Probably incorrect payload - Empty response

Hi,
I tried sending both the object and the object json the result is always a 200OK response but empty
I also tried using rhino/geometry/volumemassproperties/compute-brep

fetch('http://123.123.123.123/rhino/geometry/volumemassproperties/compute', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'RhinoComputeKey' :'Supersecretsafekey'
    },
    body: geometryJson
})

I also tried sending the geometry itself but the payload is too long to post, still response from the server 200 [OK] but empty
Payload

{"version":10000,"archive3dm":60,"opennurbs":-1912309748,"data":"+n8CANjeBQAAAAAA+/8CABQAAAAAAAAAxdu1YGDm0xG/5AAQgwEi8JhRycz8/wIAmbwFAAAAAAAzAIAAQFtCAQAAAAAAEBcBAAABAAAA+n8CAL4AAAAAAAAA+/8CABQAAAAAAAAA3dTXTkfp0xG/5QAQgwEi8BDyeHD8/wIAhgAAAAAAAAARAgAAAAAAAAACAAAAAgAAAAAAAAAAAAAAAAAAAAAA8D8AAAAAAAAAAAAAAAAAAAAAAAAAAAAA8L8AAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAATgJKi1yB0ACAAAAAAAAAAAAAAAAAAAAAAAAAAE4CSotcgdAAAAAAAAAAAAAShSj+/9/AoAAAAAAAAAAAAEAAAD6fwIAvgAAAAAAAAD7/wIAFAAAAAAAAADd1NdOR+nTEb/lABCDASLwEPJ4cPz/AgCGAAAAAAAAABECAAAAAAAAAAIAAAACAAAAAAAAAAAAAAAAAAAAAADwPwAAAAAAAAAAAAAAAAAAAAAAAAAAAADwvwAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAACoF9qgay3QPwIAAAABOAkqLXIHQAAAAAAAAAAAATgJKi1yB0CoF9qgay3QPwCY7P6L/38CgAAAAAAAAAAAAQAAAPp/AgD+AAAAAAAAAPv/AgAUAAAAAAAAAN3U105H6dMRv+UAEIMBIvAQ8nhw/P8CAMYAAAAAAAAAEQIAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAAAPA/AAAAAAAAAAAAAAAAAAAA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UkQAQAAAA8D/JeAnL4PwAAAAAAAAAAHv3KTIN19T+Show more

Small snippet of code so you can see what is being sent

Summary
function computeVolume(block, file, rhino) {
    console.log("Computing volume for block: " + block.name);

    // Get the object IDs in the block definition
    let objectIds = block.getObjectIds();
    console.log("Object IDs in block: ", objectIds);

    // Initialize the total volume
    let totalVolume = 0;

    // Loop over the object IDs
    for (let i = 0; i < objectIds.length; i++) {
        console.log("Processing object ID: " + objectIds[i]);

        // Get the geometry object from the model
        let object = file.objects().findId(objectIds[i]);
        let geometry = object.geometry();
        console.log("Geometry object: ", geometry);

        // Convert the geometry to JSON
        let geometryJson = JSON.stringify(geometry);

        // Determine the endpoint based on the type of the geometry
        let endpoint;
        if (geometry instanceof rhino.Brep) {
            endpoint = '/rhino/geometry/volumemassproperties/compute-brep';
        } else if (geometry instanceof rhino.Mesh) {
            endpoint = '/rhino/geometry/volumemassproperties/compute-mesh';
        } else {
            console.log("Unsupported geometry type: " + typeof(geometry));
            continue;
        }

        // Send a request to the Rhino Compute server to compute the volume
        fetch('http://123.123.12.123:xx' + endpoint, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'RhinoComputeKey' : 'xxxxxxx'
            },
            body: geometryJson
        }).then(response => response.json()).then(data => {
            // Get the volume from the response
            let volume = data.Volume;
            console.log("Calculated volume: " + volume);

            // Add the volume to the total volume
            totalVolume += volume;
        }).catch(error => {
            console.error("Error occurred while calculating volume: " + error);
        });
    }

    console.log("Total volume for block: " + totalVolume);
    return totalVolume;
}

Logs

2023-06-23 10:04:02.139 +00:00 [INF] Rhino compute started at 6/23/2023 10:04:02 AM
2023-06-23 10:04:02.359 +00:00 [INF] Initiliazing reverse proxy at 6/23/2023 10:04:02 AM
2023-06-23 10:04:02.359 +00:00 [INF] Spawn children at startup is set to False
2023-06-23 10:04:02.422 +00:00 [INF] Application started. Press Ctrl+C to shut down.
2023-06-23 10:04:02.423 +00:00 [INF] Hosting environment: Production
2023-06-23 10:04:02.424 +00:00 [INF] Content root path: C:\inetpub\wwwroot\aspnet_client\system_web\4_0_30319\rhino.compute
2023-06-23 10:04:02.512 +00:00 [INF] HTTP GET / responded 401 in 53.2078 ms
2023-06-23 10:05:02.390 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:06:02.320 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:07:02.322 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:08:02.325 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:09:02.328 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:10:02.323 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:11:02.332 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:12:02.334 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:13:02.336 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:14:02.339 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:15:02.341 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:16:02.343 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:17:02.344 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:18:02.337 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:19:02.348 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:20:02.350 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:21:02.352 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:22:02.353 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:23:02.355 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:24:02.357 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:25:02.358 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:26:02.360 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:27:02.361 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:28:02.361 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:29:02.364 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:30:02.355 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:31:02.370 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:32:02.373 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:33:02.377 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:34:02.379 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:35:02.425 +00:00 [INF] Max concurrent requests = 0
2023-06-23 10:36:02.392 +00:00 [INF] Max concurrent requests = 0

I’m pretty sure the problem is with the payload being passed, maybe It doesn’t work with Json serialized data? I can’t find any resource available maybe I’m blind
Could anyone please clarify what data I should pass in the body of the request precisely? I tried sending the brep json and brep object itself. Same result.
What should the body be and look like?
@AndyPayne ( :blush: ) @fraguada

Resolved.
You have to make an array of the args and then stringify the array
If anyone encouters the same issue since It’s not documented (There are only examples using NPM packages that handle this for you) there you go with a sample :

if (geometry instanceof rhino.Brep) {
            let args = [geometry];

            // Send a request to the Rhino Compute server to compute the volume
            fetch('http://123.123.123.123/rhino/geometry/brep/getvolume-brep', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'RhinoApiToken': '123x123',
                    'User-Agent': `compute.rhino3d.js/0.11.0`
                },
                body: JSON.stringify(args) // Send the argument list in the request body
            }).then(response => response.json()).then(data => {
                // Get the volume from the response
                let volume = data[0].Volume; // Access the volume from the first item in the response array
                console.log("Calculated volume: " + volume);
                totalVolume += volume;
            }).catch(error => {
                console.error("Error occurred while calculating volume: " + error);
            });
        } else {
            console.log("Geometry is not a Brep, skipping volume calculation");
        }
1 Like