I'm using Neo4j 2.0.1 Community. I try to insert a relationship in the graph by sending the query through the REST endpoint.
My relationship query is very simple:
MATCH (t1:Test { name : 'TEST_1' }), (t2:Test { name : 'TEST_2' }) CREATE (t1)-[:REL_TEST]->(t2)
I call it this way in Powershell:
$postParams = "{ `"query`" : `"MATCH (t1:Test { name : {test1} }), (t2:Test { name : {test2} }) CREATE (t1)-[:REL_TEST]->(t2)`",`"params`" : { `"test1`" : `"TEST_1`", `"test2`" : `"TEST_2`" } }"
Invoke-WebRequest -Uri http://localhost:7474/db/data/cypher -Method POST -Body $postParams -Headers #{"Accept"="application/json; charset=UTF-8";"Content-Type"="application/json"}
And I got the following response:
StatusCode : 200
StatusDescription : OK
Content : {
"columns" : [ ],
"data" : [ ]
}
RawContent : HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Length: 40
Content-Type: application/json; charset=UTF-8
Server: Jetty(9.0.z-SNAPSHOT)
{
"columns" : [ ],
"data" : [ ]
}
Forms : {}
Headers : {[Access-Control-Allow-Origin, *], [Content-Length, 40], [Content-Type, application/json; charset=UTF-8], [Server, Jetty(9.0.z-SNAPSHOT)]}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : mshtml.HTMLDocumentClass
RawContentLength : 40
But the relationship is not created. If I then type the same query in the browser UI, it works.
I don't get what I'm an doing wrong, especially since the query works in the browser and the REST calling procedure works for inserting a node for example.
Are you certain that your query is not working. You are not returning any data so it's possible it is being created without your knowing it.
You could try something like this
MATCH (t1:Test{name: {test1}}), (t2:Test{name: {test2}})
CREATE (t1)-[rel:REL_TEST]->(t2)
RETURN rel
If you don't get the rel in your response it means the rel wasn't created probably because at least one of the MATCHes failed. Try returning t1 and t2 as well to see if they are working as expected.
Related
I'm having the following issues:
I need to allow CORS only on a specific domain
I need to make sure that secure cookies are sent along with the cross-origin request.
API Gateway specifies '*' as the Access-Control-Allow-Origin header and I need to only allow "example.com".
I found that I can do this by adding the following in override.ts in the rest API resource folder:
import { AmplifyApiRestResourceStackTemplate } from '#aws-amplify/cli-extensibility-helper';
export function override(resources: AmplifyApiRestResourceStackTemplate) {
// Change the default CORS response header Access-Control-Allow-Origin from "'*'" to the API's domain
resources.restApi.body.paths['/v1'].options['x-amazon-apigateway-integration'].responses.default.responseParameters['method.response.header.Access-Control-Allow-Origin'] = {
'Fn::Sub': "'https://www.example.com'"
};
}
This seems unreasonably hacky, but whatever.
But I can't seem to solve for the Access-Control-Allow-Credentials header... This doesn't work:
import { AmplifyApiRestResourceStackTemplate } from '#aws-amplify/cli-extensibility-helper';
export function override(resources: AmplifyApiRestResourceStackTemplate) {
// Change the default CORS response header Access-Control-Allow-Origin from "'*'" to the API's domain
resources.restApi.body.paths['/v1'].options['x-amazon-apigateway-integration'].responses.default.responseParameters['method.response.header.Access-Control-Allow-Origin'] = {
'Fn::Sub': "'https://www.example.com'"
};
// ADDING THIS ...
resources.restApi.body.paths['/v1'].options['x-amazon-apigateway-integration'].responses.default.responseParameters['method.response.header.Access-Control-Allow-Credentials'] = "true";
}
I get multiple errors, but it's basically complaining with this error for each of my REST endpoints:
Unable to put integration response on 'OPTIONS' for resource at path '/oauth/hubspot': Invalid mapping expression specified: Validation Result: warnings : [], errors : [Invalid mapping expression specified: true]
I get similar errors if I try any of the following:
// with quotes inside quotes
resources.restApi.body.paths['/v1'].options['x-amazon-apigateway-integration'].responses.default.responseParameters['method.response.header.Access-Control-Allow-Credentials'] = "'true'";
// this structure
resources.restApi.body.paths['/v1'].options['x-amazon-apigateway-integration'].responses.default.responseParameters['method.response.header.Access-Control-Allow-Credentials'] = {
'Fn::Sub': "'true'"
};
The thing is, I could easily do all this myself if Amplify would just let me override how I handle the OPTIONS request, and send it to my lambda function....
VICTORY!
I'd still be interested in any suggested approaches, but this worked for me:
// This file is used to override the REST API resources configuration
import { AmplifyApiRestResourceStackTemplate } from '#aws-amplify/cli-extensibility-helper';
export function override(resources: AmplifyApiRestResourceStackTemplate) {
delete resources.restApi.body.paths['/v1'].options;
delete resources.restApi.body.paths['/v1/{proxy+}'].options;
}
Basically, it's me telling Amplify to get out of the way and let me handle the OPTIONS request myself. So this leaves the "ANY" method on the endpoint so that the OPTIONS request flows through to the LAMBDA that's already configured. I already had the code in there to handle OPTIONS requests, so... It. Just. Worked.
I know it's been six months since you asked this question, but it's something i've just been smashing my head against now.
I had exactly the same issue:
I need CORS across several domains, but I can't use Access-Control-Allow-Origin: '*' because in the browser I am calling the api with { withCredentials: true }.
My Api's back into a lambda function which correctly handles the CORS preflight on the OPTION request. (ie. it returns Access-Control-Allow-Origin: https://permitted.origin.goes.here and associated headers).
But I get CORS errors because the AWS API Gateway response for OPTION is using a predefined MOCK response, which does not allow any other value for Access-Control-Allow-Origin than '*'.
(this was all generated by Amplify).
Anyways, I tried your method of deleting the OPTION handler, but that still did not work for me.
Eventually, after configuring it correctly in the AWS API Gateway interface, exporting the swagger and replicating that in the override.ts file, I finally got it cleanly working.
this was my code in override.ts:
import { AmplifyApiRestResourceStackTemplate } from '#aws-amplify/cli-extensibility-helper';
export function override(resources: AmplifyApiRestResourceStackTemplate) {
const { paths } = resources.restApi.body;
Object.keys(paths).forEach((path) => {
if (!!paths[path].options) {
const uri = paths[path]['x-amazon-apigateway-any-method']['x-amazon-apigateway-integration'].uri;
paths[path].options = {
"responses" : {
"200" : {
"description" : "200 response",
"headers" : {
"Access-Control-Allow-Credentials" : {
"type" : "string"
},
"Access-Control-Allow-Origin" : {
"type" : "string"
},
"Access-Control-Allow-Methods" : {
"type" : "string"
},
"Access-Control-Allow-Headers" : {
"type" : "string"
}
}
}
},
"x-amazon-apigateway-integration" : {
"httpMethod" : "POST",
"uri" : uri,
"responses" : {
"default" : {
"statusCode" : "200"
}
},
"passthroughBehavior" : "when_no_match",
"contentHandling" : "CONVERT_TO_TEXT",
"type" : "aws_proxy"
}
}
}
});
}
Now I can return secure cookies to a browser app from the AWS REST API without choking on CORS errors.
good luck!
I am trying to validate the json response. Have gone through the documentation in wiremock and also tried github example as below syntax.
https://github.com/tomakehurst/wiremock/blob/master/src/test/java/ignored/Examples.java#374
#Test
public void toDoListScenario() {
stubFor(get(urlEqualTo("/todo/items")).inScenario("To do list")
.whenScenarioStateIs(STARTED)
.willReturn(aResponse()
.withBody("<items>" +
" <item>Buy milk</item>" +
"</items>"))); }
How to enter the json response in Body Section.
{
employeeDetails : [
employeeName : ABCDE,
employeeID : 12345 ]
}
Is the below representation is correct. Please help me on this.
.withBody("employeeDetails:" +
"employeeID" : "12345" +
"employeeName" : "Preethi" + )
Just format the text as json:
.withBody("{\"employeeDetails\":[" +
"\"employeeID\" : \"12345\"" +
"\"employeeName\" : \"Preethi\"]}")
and set the header to
.withHeader("Content-Type", equalTo("application/json"))
I tried to follow the RT REST Guide but i can't able to search tickets with query . Every time it is getting empty items . But i have tickets with all query and it is a valid token . All other api is working with this token
I used the command
curl -si http://rt-test.backbonesecure.com/rt/REST/2.0/tickets?token=1-115-31ee899218dfb70735c500cd0a878857 -XPOST --data-binary '[{"field":"Status","value":"open"}]'
curl -H "Content-Type: application/json" -d "#abc.txt" -X POST http://rt-test.backbonesecure.com/rt/REST/2.0/tickets?token=1-115-31ee899218dfb70735c500cd0a878857
abc.txt contains the json query
{
"Queue": "General",
"Status": "new"
"Priority":"0"
"Owner":"Nobody"
}
Does anyone have any advice?
I am having luck using a query string. I haven't tried with a JSON search.
Firstly, I am quite sure that you are misusing the authentication token. It should be put into the header like this. I would recommend you get a simple request working, like the queues/all example.
Here is the request that I send:
POST http://localhost/rt/REST/2.0/tickets
Authorization: token <REDACTED>
User-Agent: libwww-perl/6.15
Content-Type: application/x-www-form-urlencoded
query=subject = 'Test Subject';page=1
And the reponse back:
{
"total" : 1,
"count" : 1,
"page" : 1,
"items" : [
{
"type" : "ticket",
"id" : "1415",
"_url" : "http://localhost/rt/REST/2.0/ticket/1415"
}
],
"per_page" : 20
}
I would like to have arrays or collections in my model, is this yet possible with waterline (mongoDB)? are there any alternatives around?
example:
{
name: Bundle,
col1 : {
name : anOtherModel,
subCol: {
text: aString,
...
}
},
col2 : {
name : anOtherModel,
subCol: {
text: aString,
...
}
}
}
to:
module.exports = {
attributes : {
name : {
type : 'STRING',
required : true
},
basicModules: {
type : 'ARRAY', // or 'COLLECTION'
required : false
}
}
};
I don't know if this is still an issue, but the trick is to neither POST as "form-data" nor "x-www-url-encoded". You have to POST the "raw" content:
Assume the situation:
http://www.example.com/mymodel
form-data
Your Header may look like this:
POST /mymodel/create HTTP/1.1
Host: www.example.com
Cache-Control: no-cache
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="basicModules"
[1,2,3,4]
----WebKitFormBoundaryE19zNvXGzXaLvS5C
the result is that a string "[1,2,3,4]" gets (type-)validated, which fails
x-www-url-encoded
In this case the Header is something like this:
POST /mymodel/create HTTP/1.1
Host: www.example.com
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
basicModules=%5B1%2C2%2C3%2C4%5D
which has exactly the same result as form-data. validation fails because of basicModules being the string "[1,2,3,4]"
raw
to make it work your Header has to look like this:
POST /mymodel/create HTTP/1.1
Host: www.example.com
Cache-Control: no-cache
{"basicModules":[1,2,3,4]}
which results in just exactly what you want, and type validation works.
so in the end, you can fill the most complex models that way in JSON. e.g.
POST /mymodel/create HTTP/1.1
Host: www.example.com
Cache-Control: no-cache
{"user": {
"name": {
"first":"John",
"last":"Doe"
},
"age":25,
"pets":[{
"name":"Garfield",
"type":"cat"
},
{
"name":"Rudolph",
"type":"reindeer"
}]
}
If you're looking for model associations, it's not there yet (look at this issue for proposed implementations) if you'd just like to have arrays of data stored in DB, you can have arrays as attribute (see the doc for reference on that). I haven't tested it but I guess it will serialize the array prior to saving it in the DB if it doesn't have a matching structure.
I have a javascript object to be sent to server as follow :
var input = {a: 'aaa', b: 'bbb', c: 'ccc'};
And I want to send 'a' property in url like this
http://localhost/rest/customer/aaa
That's fine with url substitution feature in amplifyjs as follow :
amplify.request.define('update-customer', 'ajax', {
url : 'rest/customer/{a}',
dataType: 'json',
type : 'PUT'
contentType : 'application/json; charset=utf-8;
});
amplify.request('update-customer', { a : input.a, data : input });
The point I am struggling with is that I would like to send b and c property as a form data in json format as a 'Request Payload', however it is failed becauseof the form data is sent as follow :
Request Payload :
data : {b : 'bbb', c : 'ccc'}
So what I want to achieve is to remove 'data' key in 'Request Payload' as follow :
Request Payload :
{b : 'bbb', c : 'ccc'}
I tested this in REST Client program and was successed.
To wrap up my question, How to send data attached in Request Body without key name using amplifyjs?
Thanks in advance.
Try with:
amplify.request.define('update-customer', 'ajax', {
url: 'rest/customer/{a},
dataType: 'json',
type: 'PUT',
contentType: 'application/json; charset=utf-8',
data: {
b : '{b}',
c : '{c}'
}
});
amplify.request('update-customer', { a : input.a, data : input });
This solution has a problem if input.b or input.c are null. Check this post for further details