Neo4j Python REST API - neo4j

Query via Python REST-APi
message: Invalid input: ':'
Hello,
i am starting a query via my Python-Neo4j-Api.
But the code ist not working, resulting in the the error message above.
But the same query is working in the Neo4J Desktop App.
Why is it working in the Neo4j Desktop App, but not via my Api Query. Why is the : before param a Problem?
I am new to Python and Neo4j, please help.
King regards.
Trying to query via a Python-Neo4j-RestAPI.

Below is the syntax on passing parameters in neo4j python driver. Unfortunately, you cannot use labels or relationship types in the parameter. If you need to pass labels (like Human:Moviestar) then you can use string function in python like this: passing parameters in neo4j using python
name = "Tom Cruise"
placeOfBirth = "Syracuse, New York, United States"
query = "Create (n:Human:Moviestar { name: $name, placeOfBirth: $placeOfBirth})"
session = driver.session()
result = session.run(query, name=name, placeOfBirth=placeOfBirth)

I see that you have been working with the database though the browser application. So commands that are prefixed with ":" like :params or :connect are browser commands and is not valid cypher. Instead, in python pass your parameters as the second argument to your to your session.run() function or transaction. Then use variable substitution to in your cypher query.
params = {"name": "Tom Hanks" }
with driver.session as session:
result = session.run ("MATCH (p:person) where p.name = $name return p", params)

Related

Filtering on "null" or "no values"

I am trying to make a filter in Graph API, querying for employees without phone, but with no luck.
This is a part of the query I am working on.
https://graph.microsoft.com/beta/users?$filter=userType eq 'Member'&$select = businessPhones
This results in something like this:
{ "businessPhones": ["+473456789"]},
{ "businessPhones": ["+479876543"]},
{ "businessPhones": ["+471234567"]}
What I am trying to do is ask for users without a businessphone
{ "businessPhones": []}
Something like this
https://graph.microsoft.com/beta/users?$filter=userType eq 'Member' and businessPhones eq ''
However, I have no clue on how to do this. Anyone?
EDIT, thanks Tiny Wang for pointing out "no filtering support":
businessPhones does not support filtering. However, assignedLicenses does. If I want to query for users without any assignedLicenses
{ "assignedLicenses" : [] }
How can I accomplish that?
Pls note, according to the api properity doc, businessPhones isn't a properity supporting $filter, see https://learn.microsoft.com/en-us/graph/api/resources/user?view=graph-rest-beta#properties
==========================UPDATE============================
Per my testing, I think it's also an unachievable task. It seems there're some 'defect' exists in ms graph OData filter. In this case, we need to use not assignedLicenses/any() according to OData protocol.
But according to my testing result, the query doesn't support using assignedLicenses/any()->Error: Complex query on property assignedLicenses is not supported , not assignedLicenses/any()->Error: Unsupported Query", but only support like assignedLicenses/any(x:x/skuId eq 3b555118-xxxx-e2096870).
What's more, when executing below query, it returns error Complex query on property assignedLicenses is not supported.
https://graph.microsoft.com/beta/users?$filter=userType eq 'Member' and assignedLicenses/any(x:x/skuId eq 3b555118-xxxx-2096870)&$select=assignedLicenses
But when executing this, it worked, so weird.
https://graph.microsoft.com/beta/users?$filter=assignedLicenses/any(x:x/skuId eq 3b555118-xxxxxx-df1e2096870)&$select=assignedLicenses
I also tried to use $count property to do the filter, but also failed:
I had the same task. After some research, I figured out how to filter out null string properties such as jobTitle, department, etc. Check this link.
Based on the answer, I tried the following query, and It works for me.
https://graph.microsoft.com/v1.0/users?$filter=NOT (businessPhones/any(p:p ge ' '))&$count=true
Be sure that you specified whitespace between quotes ' '.

Searching Microsoft Graph api with spaces in the name

I'm using Microsoft Graph to do a search on the displayName for a substring of the name. The $search="displayName:MySearchTerm" format works perfect. But trying to search on the displayName with a space in the term doesn't seem to work as expected.
Using the sandbox application here
https://developer.microsoft.com/en-us/graph/graph-explorer?request=groups?$expand=members&method=GET&version=v1.0
If I use the following query format:
https://graph.microsoft.com/v1.0/groups?$search="displayName:Product vi"&$select=displayName&$orderBy=displayName
how can I get it to return only those records that have the term Product vi in the displayName field.
It shouldn't return any records in the sandbox because the term Product vi does not appear exactly in any part of the displayName but it currently returns the record "displayName": "Video Production"
I've tried the following without success:
$search="displayName:"Product vi""
$search="displayName:\"Product vi\""
$search="displayName:\\"Product vi\\""
$search="displayName:\\\"Product vi\\\""
$search="displayName:'Product vi'"
$search="displayName:\'Product vi\'"
The $filter format is no good to me as it doesn't search the middle of the displayName for the string.
How do I format the url to get the desired results if it is even possible?
The trick is to use comma instead of the space in $search clause.
https://graph.microsoft.com/v1.0/groups?$search="displayName:Product,vi"&$select=displayName&$orderBy=displayName
If $search clause contains "displayName:Product,vi" then Graph API will search on displayName for "Product vi"
It can require a special request header:
ConsistencyLevel: eventual
Try with %22
instead of
%20
good code...

Neo4j - encountering FetchURLError whenever using any query with GET or POST

I am using Neo4j Desktop application and trying a cypher query to export RDF. I am using the default available load-movie.cypher data in local DB as a trial but everytime I run the query it gives FetchURLError so I dont know what I am doing wrong.Also to add that all other match queries are working fine. Here is the query that I tried:-
:POST /rdf/neo4j/cypher
{"cypher":
"MATCH g = (:Person {name: 'Keanu Reeves'})-->(:Movie { title: 'The Matrix'})
RETURN g",
"format" : "RDF/XML"}
Then I tried a simple GET query :-
:GET /rdf/neo4j/describe/11
But the response is always:
FetchURLError - Could not fetch URL: "Failed to fetch".
This could be due to the remote server policy. See your web browsers error console for more information.
Need some help in resolving the issue.
I recently ran into the same problem and for me it worked by writing the full URL. E.g.:
:GET http://localhost:7474/rdf/neo4j/describe/11

Breeze.js Passthrough Predicate Odata Url

I am attempting to create an odata url with multiple breeze.js passthrough predicates using documentation from the folowing link: http://www.getbreezenow.com/documentation/query-using-json.
However the generated url looks nothing like an odata url eg:
var query = breeze.EntityQuery.from('User').using(this.manager).where("{ { 'userName': { '=': '123456' } } }");
var url = query._toUri(this.manager);
url is "User?$filter=%7B%20%7B%20'userName'%3A%20%7B%20'%3D'%3A%20'123456'%20%7D%20%7D%20%7D&$orderby=UserName" rather than "User?$filter=(UserName eq '123456')&$orderby=UserName".
I don't think you want a passthru query because this just passes your where clause thru intact without any processing. This is what happens when you quote the entire where clause.
If you want your query converted to 'odata' syntax then try the following:
var query = breeze.EntityQuery.from('Customers').using(em)
.where({ 'userName': { '==': '123456' } });
Note that the 'where' argument is NOT in quotes ( it is a standard javascript object), and the operator is '==', not '=';
or even simpler
var query = breeze.EntityQuery.from('Customers').using(em)
.where( { userName: '123456' });
Further info:
There are two forms of urls that can be generated from any breeze query. An OData form and a JSON form. If you want OData, (the default) then you either do nothing because it is the default or you can tell breeze explicitly with:
breeze.core.config.initializeAdapterInstance("uriBuilder", "odata");
If you want the json form, you would use
breeze.core.config.initializeAdapterInstance("uriBuilder", "json");
It also possible that you added a line to use the 'json' uriBuilder. Just omit this line if you want OData urls. You can still construct the query via the json syntax, but the URL will be output using OData syntax.
The Json form ( or uri) is useful for non OData servers.

Searching in Neo4j

My web application has users and Coworker relationship. I want to search users which has Coworker relationship with specific user. I used this query:
var query = _client
.Cypher
.Start(new
{
//user = Node.ByIndexLookup(IndexHelper.USER_INDEX, "Email", email)
}
).Match(String.Format("user-[:{0}]-(coworkers)", CoWorker.TypeKey))
.Where((User coworkers) => coworkers.Email.Contains(term))
.Return<Node<User>>("coworkers");
But It throws invalid parameter at
Where((User coworkers) => coworkers.Email.Contains(term)).
How can I replace this condition to search coworker with term? Thanks for reading.
Cypher doesn't actually support a contains operator like this, hence why the exception says there is no .NET equivalent.
The nearest you could do is use a regex:
WHERE coworkers.Email =~ ".*something.*"
But that would be horribly inefficient because you would run a regex across every node.

Resources