I am trying to use the REST API to create a unique node. However, I am getting the error about requiring the key 'uri' (see below). Based on the documented examples, this call creates and indexes the newly created node ... so there should not be a 'uri' paramater. My request and response are below. What am I doing wrong?
REQUEST:
http://www.somemachine.com:7474/db/data/index/node/idxHost?unique=get_or_create
{
"key": "name",
"value": "HOST",
"properties": {
"type": "company",
"name": "HOST",
"sequence": 1
}
}
RESPONSE:
state:400, body:
{
"message" : "Missing required key: \"uri\"",
"exception" : "BadInputException",
"fullname" : "org.neo4j.server.rest.repr.BadInputException",
"stacktrace" : [ "org.neo4j.server.rest.repr.formats.JsonFormat.readMap(JsonFormat.java:92)", "org.neo4j.server.rest.web.RestfulGraphDatabase.addToNodeIndex(RestfulGraphDatabase.java:802)", "java.lang.reflect.Method.invoke(Method.java:601)" ],
"cause" : {
"message" : "Missing required key: \"uri\"",
"exception" : "BadInputException",
"stacktrace" : [ "org.neo4j.server.rest.repr.DefaultFormat.validateKeys(DefaultFormat.java:153)", "org.neo4j.server.rest.repr.formats.JsonFormat.readMap(JsonFormat.java:88)", "org.neo4j.server.rest.web.RestfulGraphDatabase.addToNodeIndex(RestfulGraphDatabase.java:802)", "java.lang.reflect.Method.invoke(Method.java:601)" ],
"fullname" : "org.neo4j.server.rest.repr.BadInputException"
}
}
Using curl
c:\apps\curl\curl-7.28.1-win64-nossl>curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"key":"name","value":"HOST","propert
ies":{"type":"company","name":"HOST","sequence":1}}' http://www.somemachine.com:7474/db/data/index/node/idxHost?unique=get_or_create
HTTP/1.1 400 Bad Request
Content-Length: 489
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)
{
"message" : "Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: java.io.Str
ingReader#1e70f68; line: 1, column: 2]",
"exception" : "BadInputException",
"stacktrace" : [ "org.neo4j.server.rest.repr.formats.JsonFormat.readMap(JsonFormat.java:92)", "org.neo4j.server.rest.web.RestfulGraphDatabase.addToNodeIndex(R
estfulGraphDatabase.java:776)", "java.lang.reflect.Method.invoke(Unknown Source)" ]
}
According to the doc, in 1.8 the url ends with '?unique' whereas in 1.9 is '?uniqueness=get_or_create'
I think this may cause your error.
see for 1.8: http://docs.neo4j.org/chunked/stable/rest-api-unique-indexes.html#rest-api-add-a-node-to-an-index-unless-a-node-already-exists-for-the-given-mapping
and 1.9: http://docs.neo4j.org/chunked/milestone/rest-api-unique-indexes.html
Related
I have very basic mapping.json
{
"mappings": [
{
"priority": 1,
"request": {
"method": "GET",
"url": "/your/url?and=query"
},
"response": {
"status": 200,
"statusMessage": "query param test"
}
},
{
"priority": 2,
"request": {
"method": "GET",
"url": "/your"
},
"response": {
"status": 200,
"statusMessage": "no query param"
}
}
]
}
It's the exact same example as given in the documentation.
Result:
admin ~ % curl -i http://localhost:8081/your
HTTP/1.1 200 no query param
Matched-Stub-Id: 6ff84303-8abb-48d0-bd27-679de118afc7
Transfer-Encoding: chunked
Server: Jetty(9.2.z-SNAPSHOT)
admin ~ % curl -i http://localhost:8081/your/url?and=query
zsh: no matches found: http://localhost:8081/your/url?and=query
admin ~ %
Cannot figure out what I am doing wrong here. It's exactly the same example give in the documentation. I tried putting query parameter like this:
"queryParameters" : {
"search_term" : {
"equalTo" : "WireMock"
}
},
This also didn't help.
TIA
Check out the answer and comment from this question, but the tl;dr is that if you want to include query parameters in a CURL request, you have to have the URL in quotes.
That would explain why Postman worked, and the CURL request without query parameters also worked, but the CURL request with query parameters did not.
curl -i 'http://localhost:8081/your/url?and=query' should be enough to solve your problem (might need double quotes instead of single?)
I am trying to schedule a dataflow job with Cloud Scheduler by posting to REST API and authenticate by OAUTH. I have created a template and it works when I manually use Dataflow 'Create job from template'. However, when being used as a HTTP endpoint (https://dataflow.googleapis.com/v1b3/projects/${my.proj}/locations/europe-west1/templates:launch?gcsPath=gs://${my.proj}/templates/${template.name}), it returns the following error:
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"jobName\": Cannot bind query parameter. Field 'jobName' could not be found in request message.\nInvalid JSON payload received. Unknown name \"environment\": Cannot bind query parameter. Field 'environment' could not be found in request message.\nInvalid JSON payload received. Unknown name \"parameters\": Cannot bind query parameter. Field 'parameters' could not be found in request message.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"jobName\": Cannot bind query parameter. Field 'jobName' could not be found in request message."
},
{
"description": "Invalid JSON payload received. Unknown name \"environment\": Cannot bind query parameter. Field 'environment' could not be found in request message."
},
{
"description": "Invalid JSON payload received. Unknown name \"parameters\": Cannot bind query parameter. Field 'parameters' could not be found in request message."
}
]
}
]
}
}
Following is my POST body:
{
"jobName": "test",
"parameters": {
"region": "europe-west1"
},
"environment": {
"tempLocation": "gs://${my.proj}/temp",
"zone": "europe-west1"
}
}
I appreciate any help, thank you in advance!!
I verified that below works:
TEMPLATE_LOCATION="gs://${my.proj}/templates/${template.name}"
API_ROOT_URL="https://dataflow.googleapis.com/"
TEMPLATES_LAUNCH_API="${API_ROOT_URL}/v1b3/projects/${my.proj}/locations/europe-west1/templates:launch"
time curl -X POST -H "Content-Type: application/json" \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"${TEMPLATES_LAUNCH_API}"`
`"?gcsPath=${TEMPLATE_LOCATION}"`
` -d '
{
"jobName": "test",
"parameters": {},
"environment": {
"tempLocation": "gs://${my.proj}/temp",
"workerZone": "europe-west1-d",
}
}'
Note that you don't need to specify region in parameters, and it's workerZone instead of zone.
I am having some trouble posting a transaction on my ReST server. When I try to POST a transaction, I always get a 422 error. If I delete any fields, I will get a 500 error. It seems like whatever transaction id is there is invalid, and I do not know why it is invalid. In my original .cto files, I did not ask for there to be a transactionID field, so I am assuming this is a default field. Here is a screenshot of my POST method:
Here is my input that I put in:
{
"$class": "models.transactionsModel.InvalidateCertificate",
"certificate": "#cert2",
"transactionId": "string",
"timestamp": "2018-06-18T16:57:45.644Z"
}
I made the certificate identifiable by a hash string
Here is the resulting curl, body, and header respectively,
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \
"$class": "models.transactionsModel.InvalidateCertificate", \
"certificate": "#cert2", \
"transactionId": "string", \
"timestamp": "2018-06-18T16:57:45.644Z" \
}' 'http://localhost:3000/api/models.transactionsModel.InvalidateCertificate'
{
"error": {
"statusCode": 422,
"name": "ValidationError",
"message": "The `models_transactionsModel_InvalidateCertificate` instance is not valid. Details: `transactionId` can't be set (value: \"string\").",
"details": {
"context": "models_transactionsModel_InvalidateCertificate",
"codes": {
"transactionId": [
"absence"
]
},
"messages": {
"transactionId": [
"can't be set"
]
}
},
"stack": "ValidationError: The `models_transactionsModel_InvalidateCertificate` instance is not valid. Details: `transactionId` can't be set (value: \"string\").\n at /Users/harshdeshpande/.nvm/versions/node/v8.11.2/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/dao.js:398:12\n at models_transactionsModel_InvalidateCertificate.<anonymous> (/Users/harshdeshpande/.nvm/versions/node/v8.11.2/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/validations.js:578:11)\n at models_transactionsModel_InvalidateCertificate.next (/Users/harshdeshpande/.nvm/versions/node/v8.11.2/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/hooks.js:93:12)\n at models_transactionsModel_InvalidateCertificate.<anonymous> (/Users/harshdeshpande/.nvm/versions/node/v8.11.2/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/validations.js:575:23)\n at models_transactionsModel_InvalidateCertificate.trigger (/Users/harshdeshpande/.nvm/versions/node/v8.11.2/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/hooks.js:83:12)\n at models_transactionsModel_InvalidateCertificate.Validatable.isValid (/Users/harshdeshpande/.nvm/versions/node/v8.11.2/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/validations.js:541:8)\n at /Users/harshdeshpande/.nvm/versions/node/v8.11.2/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/dao.js:394:9\n at doNotify (/Users/harshdeshpande/.nvm/versions/node/v8.11.2/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:155:49)\n at doNotify (/Users/harshdeshpande/.nvm/versions/node/v8.11.2/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:155:49)\n at doNotify (/Users/harshdeshpande/.nvm/versions/node/v8.11.2/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:155:49)\n at doNotify (/Users/harshdeshpande/.nvm/versions/node/v8.11.2/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:155:49)\n at Function.ObserverMixin._notifyBaseObservers (/Users/harshdeshpande/.nvm/versions/node/v8.11.2/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:178:5)\n at Function.ObserverMixin.notifyObserversOf (/Users/harshdeshpande/.nvm/versions/node/v8.11.2/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:153:8)\n at Function.ObserverMixin._notifyBaseObservers (/Users/harshdeshpande/.nvm/versions/node/v8.11.2/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:176:15)\n at Function.ObserverMixin.notifyObserversOf (/Users/harshdeshpande/.nvm/versions/node/v8.11.2/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:153:8)\n at Function.ObserverMixin._notifyBaseObservers (/Users/harshdeshpande/.nvm/versions/node/v8.11.2/lib/node_modules/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:176:15)"
}
}
{
"date": "Mon, 18 Jun 2018 18:23:47 GMT",
"content-encoding": "gzip",
"x-content-type-options": "nosniff",
"x-download-options": "noopen",
"x-frame-options": "DENY",
"content-type": "application/json; charset=utf-8",
"access-control-allow-origin": "http://localhost:3000",
"transfer-encoding": "chunked",
"connection": "keep-alive",
"access-control-allow-credentials": "true",
"vary": "Origin, Accept-Encoding",
"x-xss-protection": "1; mode=block"
}
What is even stranger is that I can submit a valid transaction via the Composer playground. In the composer playground, though, it does not ask for a transactionID or timestamp - it automatically generates while the transaction is being submitted.
See the answer here -> error executing hyperledger fabric code on localhost:3000 (through REST) - transactionId - it is really a Loopback issue.
Post your same transaction as follows (but remove the transactionId and timestamp - these are generated for you and the former represents the transaction Id on the ledger):
{
"$class": "models.transactionsModel.InvalidateCertificate",
"certificate": "#cert2"
}
cheers
I am trying to provide a MOCK service that takes a headerName and value from the query and returns it as a (dynamic) header with the response. I am using the following response definition:
"response" : {
"status" : 200,
"statusMessage": "OK",
"headers" : {
"Content-Type" : "application/json",
"{{request.query.debugHeader}}" : "{{request.query.debugHeaderValue}}"
},
"jsonBody" : {
"headerSent": "{{request.query.debugHeader}} {{request.query.debugHeaderValue}}"
},
"transformers": ["response-template"],
"base64Body" : ""
}
The header value is correctly evaluated and put into the response template, however I can't get the header name to be taken from the request.
When sending a request:
http://localhost:8090/example?debugHeader=name&debugHeaderValue=value
The result headers I get back are:
HTTP/1.1 200 OK
Content-Type: application/json
{{request.query.debugHeader}}: value
However I want {{request.query.debugHeader}} to be replaced with the actual request parameter value ("name" in the example above).
Any ideas?
Thanks in advance
Alex
This is supported in WireMock.Net.
The request which you need to specify looks like this:
{
"Guid": "90356dba-b36c-469a-a17e-669cd84f1f05",
"Priority": 0,
"Request": {
"Path": {
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "/trans",
"IgnoreCase": false
}
]
},
"Methods": [
"get"
]
},
"Response": {
"StatusCode": 200,
"BodyDestination": "SameAsSource",
"Body": "{\"msg\": \"Hello world : {{request.path}}\" }",
"UseTransformer": true,
"Headers": {
"Content-Type": "application/json",
"Transformed-Postman-Token_{{request.path}}": "token is {{request.headers.Postman-Token}}"
}
}
}
This will add the transformed header Transformed-Postman-Token_{{request.path}} in the response.
Presently this type of variability is not part of the out-of-the-box WireMock application and would have to be custom added. In the WireMock documentation the section Extending WireMock and in particular the part on Transforming Responses.
I sent this request to hyperledger's REST API:
$ curl -X POST --header "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "method": "deploy", "params": { "type": 1, "chaincodeID":{ "path":"github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" }, "ctorMsg": { "args":["init", "a", "1000", "b", "2000"] } }, "id": 1 }' localhost:7050/chaincode
and this is the error message I got in return:
{"jsonrpc":"2.0","error":{"code":-32700,"message":"Parse error","data":"Error unmarshalling chaincode request payload: illegal base64 data at input byte 0"},"id":null}
I then added debug log in rest_api.go to check whatever is received by the peer
and got this log:
16:03:46.323 [rest] ProcessChaincode -> DEBU 027 reqBody = { "jsonrpc": "2.0", "method": "deploy", "params": { "type": 1, "chaincodeID":{ "path":"github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" }, "ctorMsg": { "args":["init", "a", "1000", "b", "2000"] } }, "id": 1 }
16:03:46.331 [rest] ProcessChaincode -> ERRO 028 Error unmarshalling chaincode request payload: illegal base64 data at input byte 0
The received message seems to match with the definition of "rpcRequest", "ChaincodeSpec", and "ChaincodeInput", I don't understand why it keeps throwing unmarshalling error to me...