question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Neo4jClient returns 403 FORBIDDEN: Request forbidden by administrative rules

See original GitHub issue

When trying to add a relationship between two nodes in a neo4j instance using Neo4jClient, I get the following error: Request forbidden by administrative rules.

`public async Task CreateFollowship(Guid followerId, Guid followedId) { await _neo4jClient.ConnectAsync();

    await _neo4jClient.Cypher
        .Match("(follower:User)", "(followed:User)")
        .Where($"(User follower) => follower.Id == {followerId}")
        .AndWhere($"(User followed) => followed.Id == {followedId}")
        .Create("follower-[:FOLLOWS]->followed")
        .ExecuteWithoutResultsAsync();

}`

The query generated is (by example):

MATCH (follower:User), (followed:User) WHERE (User follower) => follower.Id == "970486dc-5430-4532-8ed3-e30efa930105" AND (User followed) => followed.Id == "f6a15b31-e328-4113-8541-3de8108b116d" CREATE follower-[:FOLLOWS]->followed

I tried in other ways:

MATCH (follower:User), (followed:User) WHERE follower.Id == "970486dc-5430-4532-8ed3-e30efa930105" AND followed.Id == "f6a15b31-e328-4113-8541-3de8108b116d" CREATE follower-[:FOLLOWS]->followed

MATCH (follower:User), (followed:User) WHERE follower.Id IS "970486dc-5430-4532-8ed3-e30efa930105" AND followed.Id IS "f6a15b31-e328-4113-8541-3de8108b116d" CREATE follower-[:FOLLOWS]->followed

When running the command on the Neo4j Console using Cypher, i get different syntax errors with every attempt to fix. What is the correct syntax? An incorrect syntax is really the reason for the 403 error?

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Clooney24commented, Dec 10, 2022

HI @guilhermedjr, correct Cypher syntax is

MATCH (follower:User), (followed:User) 
WHERE follower.Id = "970486dc-5430-4532-8ed3-e30efa930105" AND followed.Id = "f6a15b31-e328-4113-8541-3de8108b116d" 
CREATE (follower)-[:FOLLOWS]->(followed)

Unless it is intended, I would recommend using MERGE instead of CREATE to prevent creating multiple similar relationsships between the nodes.

Using Neo4jClient in C# this would be (with Create replaced by Merge):

 await _neo4jClient.Cypher
        .Match("(follower:User), (followed:User)")
        .Where((User follower) => follower.Id == followerId)
        .AndWhere((User followed) => followed.Id == followedId)
        .Merge("(follower)-[:FOLLOWS]->(followed)")
        .ExecuteWithoutResultsAsync();

or alternatively by using string and parameters

 await _neo4jClient.Cypher
        .Match("(follower:User) (followed:User)")
        .Where("follower.Id = $followerId")
        .WithParam("followerId", followerId) 
        .AndWhere("followed.Id = $followedId")
        .WithParam("followedId", followedId) 
        .Merge("(follower)-[:FOLLOWS]->(followed)")
        .ExecuteWithoutResultsAsync();

Params could also be set using just one “.WithParams” instead of the two “.WithParam”, but I like using it one by one.

Where-Clauses also could be set using string interpolation ($“follower.Id = {followerId}”) but this is not recommended as it prevents query caching.

Be aware that Cypher doesn’t accept “==” (or “!=”) as operators, these only work in C#. Has to be “=” or “<>” in Cypher.

Response status 403 means “Bad Request” so it’s due to that incorrect syntax and not a bug in Neo4jClient.

Best, Reiner

0reactions
cskardoncommented, Dec 12, 2022

I don’t see why you would have a problem with Aura and not allowing write operations from an external source - if you can connect to the server - then it should work fine.

What is your entire connection setup - i.e. how are you creating the IGraphClient?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Neo4jClient returns 403 FORBIDDEN: Request ...
When trying to add a relationship between two nodes in a neo4j instance using Neo4jClient, I get the following error: Request forbidden by...
Read more >
Unable to perform any operation on Neo4j AuraDB ...
NET application, I get the following 403 error: Request forbidden by administrative rules. The operations work from my app using a Neo4jDesktop ...
Read more >
What Is the 403 Forbidden Error and How to Fix It (8 ...
It simply means that there is an issue with autorizing your request to access files or a particular page on your website. Author....
Read more >
3 Ways To Fix '403 Forbidden Request Forbidden By ...
How To Fix The Error '403 Forbidden Request Forbidden By Administrative Rules' · 1. Disable your .htaccess file · 2. Disable your plugins...
Read more >
How to Fix a 403 Forbidden Error on Your Site
The 403 Forbidden error indicates that the server understands the request but can't provide additional access. This means that the web page ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found