0
votes

I'm getting the following error when using the Google API Explorer to insert into GCP's Datastore.

I've tried using another name and ID, but still the error. How do I rectify this?

Below are the request body and error.

{
    "mode": "Transactional",
    "mutations": [
        {
            "insert": {
                "key": {
                    "path": [
                        {
                            "id": "56294995342131231",
                            "name": "CL-001",
                            "kind": "Log"
                        }
                    ],
                    "partitionId": {
                        "namespaceId": "",
                        "projectId": "triplog-169706"
                    }
                },
                "properties": {
                    "Title": {
                        "stringValue": "Space Needle"
                    },
                    "Longitude": {
                        "doubleValue": 0.00
                    },
                    "Latitude": {
                        "doubleValue": 0.00
                    },
                    "Date": {
                        "timestampValue": "2015-07-03T10:51:50.649Z"
                    },
                    "Rating": {
                        "integerValue": "5"
                    },
                    "Notes": {
                        "stringValue": "Wonderful site to see"
                    }
                }
            }
        }
    ]
}


{
    "error": {
        "code": 400,
        "message": "Invalid value at 'mutations[0].insert.key.path[0]' (oneof), oneof field 'id_type' is already set. Cannot set 'name'",
        "status": "INVALID_ARGUMENT",
        "details": [
            {
                "@type": "type.googleapis.com/google.rpc.BadRequest",
                "fieldViolations": [
                    {
                        "field": "mutations[0].insert.key.path[0]",
                        "description": "Invalid value at 'mutations[0].insert.key.path[0]' (oneof), oneof field 'id_type' is already set. Cannot set 'name'"
                    }
                ]
            }
        ]
    }
}
2
I have amended the following: "path": [ { "id": "1235629499534213120", "name": "id=1235629499534213120", "kind": "Log" } ] and now the error is this: { "error": { "code": 400, "message": "transactional commit requires a transaction", "status": "INVALID_ARGUMENT" } } - LCL

2 Answers

0
votes

Based on the docs, it looks like you should only be setting either a "name" or "id" in the Path Element, not both.

https://cloud.google.com/datastore/docs/reference/rest/v1/Key#PathElement

0
votes

I've finally got it. To get the "transaction", just run the beginTransaction API.

POST https://datastore.googleapis.com/v1/projects/{projectId}:beginTransaction

This will response with an identifier, which is a long string. Use that as the value of the "transaction".