Hi Everyone,
I'm trying to post a vote through a REST POST call using json (or hal_json).
The GET request works just fine and I'm able to get the output which is something similar to this:
url: http://localhost:8001/entity/vote/19?_format=json
{
"id":[
{
"value": 19
}
],
"uuid":[
{
"value": "c81b488a-d5a1-49f4-97ea-4681c3248414"
}
],
"type":[
{
"target_id": "like",
"target_type": "vote_type",
"target_uuid": "cacd122f-8bfe-484c-9585-ee64ddb47c3d"
}
],
"entity_type":[
{
"value": "post"
}
],
"entity_id":[
{
"target_id": 52
}
],
"value":[
{
"value": 1
}
],
"value_type":[
{
"value": "points"
}
],
"user_id":[
{
"target_id": 13,
"target_type": "user",
"target_uuid": "94227fde-1ef5-43ef-a229-943d0fd54fa4",
"url": "/en/user/13/stream"
}
],
"timestamp":[
{
"value": "2018-07-16T08:03:28+00:00",
"format": "Y-m-d\\TH:i:sP"
}
],
"vote_source":[
{
"value": "::1"
}
]
}The problem is that when i try to post a vote on a post/comment by using the following code, it returns an error which is:
422 Unprocessable Entity
and it says this:
"Unprocessable Entity: validation failed.\nentity_id.0.target_id: The referenced entity (node: 70) does not exist.
code used in the post:
url: http://localhost:8001/entity/vote?_format=json
authenticated with X-CSRF-Token
{
"type":[
{
"target_id": "like",
"target_type": "vote_type"
}
],
"entity_type":[
{
"value": "post"
}
],
"entity_id":[
{
"target_id": 70
}
],
"value":[
{
"value": 1
}
],
"value_type":[
{
"value": "points"
}
],
"user_id":[
{
"target_id": 13,
"target_type": "user",
"url": "/en/user/13/stream"
}
],
"timestamp":[
{
"value": "2018-07-16T08:03:28+00:00",
"format": "Y-m-d\\TH:i:sP"
}
],
"vote_source":[
{
"value": "::1"
}
]
}
So basically it is saying that the entity 70th is a node (when in reality it's a simple post) and it doesn't work.
If i try to post a vote on an actual node instead, it works like a charm.
Some suggestions?
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 2988057-15.patch | 10.24 KB | v.hilkov |
Comments
Comment #1
Anonymous (not verified) commenteddinozof created an issue. See original summary.
Comment #2
Anonymous (not verified) commentedSmall update !
while trying to debug the problem i found out that if an entity node exists and has the same ID of the comment to which i'm trying to add the like, then it works!
so basically:
if i'm trying to add a like to the post which ID is 15 and exists a node that has the same id (15) then the REST post request get accepted and the likes get added to the correct post.
otherwise it will report a 422 error of Unprocessable entity.
best
Comment #3
dstorozhukComment #4
dstorozhukComment #5
dstorozhukComment #6
dstorozhukReplace wrong formatted patch.
Comment #7
dstorozhukIn general - we need to lock the entity type witch which this vote could be used. My patch is about that.
Comment #8
dstorozhukComment #9
dstorozhukComment #10
pifagorComment #11
tr commentedComment #12
tr commentedPatch no longer applies. Needs reroll.
Comment #13
ravi.shankar commentedHere I have added re-roll of patch #6.
Comment #14
tr commentedNeeds another re-roll.
Comment #15
v.hilkov commentedRe-roll of patch #13.
Comment #16
sadikyalcin commented#15 didn't work for me. Does anyone have a working patch? Drupal 8.9.12, Votingapi 8.x-3.0-beta2
Comment #17
tr commentedWhat is that supposed to mean? What didn't work? What errors? Be specific.
Comment #18
sadikyalcin commentedGetting the 422 Unprocessable Entity as described by OP: "Unprocessable Entity: validation failed.\nentity_id.0.target_id: The referenced entity (node: 3) does not exist". I'm voting on a comment with the id 3 not a node.
Comment #19
v.hilkov commentedHi @sadikyalcin
Did you changed vote entity type to whatever entity type you are voting to? This can be done at /admin/structure/vote-types

Your vote type setting form should look like this:
Comment #20
sadikyalcin commentedHi @V.Hilkov,
I don't see the entity type setting. I only have name, value type, description and use as a reaction checkbox.
Comment #21
sadikyalcin commentedIgnore #20. Re-patched and the setting is back now.