0

How can I get the modelId from the getOperation response? When I run getOperation() function using the operationId, the response does not contain the modelId, even though done is true.

I have tried everything from this question: How to programmatically get model id from google-cloud-automl with node.js client library

But the response that is returned to me is different.

My Function:

exports.testOperationStatus = async function(operationId) {
    // Construct request
    const request = {
      name: `projects/${projectId}/locations/${location}/operations/${operationId}`,
    };
  
    const [response] = await client.operationsClient.getOperation(request);
  
    console.log(`Name: ${response.name}`);
    console.log(`Operation details:`);
    console.log(`${JSON.stringify(response, null, 2)}`);
  }

My Response:

    {
  "name": "projects/projectId/locations/us-central1/operations/operationId”,
  "metadata": {
    "type_url": "type.googleapis.com/google.cloud.automl.v1.OperationMetadata",
    "value": {
      "type": "Buffer",
      "data": […]
    }
  },
  "done": true,
  "response": {
    "type_url": "type.googleapis.com/google.cloud.automl.v1.Model",
    "value": {
      "type": "Buffer",
      "data": […]
    }
  },
  "result": "response"
}

    

How do I get my modelId using the operationId?

lisen kaci
  • 151
  • 1
  • 12

1 Answers1

0

I finally figured this one out! It was returning the name with the model-Id in it as a Buffer inside the "value" . In order to extract the model-Id I had to do

const modelId = response.response.value.toString('utf8').replace(/projects\/[a-zA-Z0-9-]*\/locations\/[a-zA-Z0-9-]*\/models\//,''
lisen kaci
  • 151
  • 1
  • 12