Add reviews JSON error 403

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
User avatar
Dinver
Posts: 27
Joined: 26 Oct 2020, 08:42

Add reviews JSON error 403

Post by Dinver » 25 Nov 2020, 15:57

When trying to leave a review to the purchased goods: "You can only add a review if you have ordered a product"

Code: Select all

const url = '/jsonapi/customer?related=review'
		const params = {'data': [{
			'attributes': {
				'review.domain': 'product',
				'review.refid': $('#modalReview .review-form-hidden').val(),
				'review.name': $('#modalReview .review-form-name').val(),
				'review.rating': $('#modalReview .review-form-radio:checked').val(),
				'review.comment': $('#modalReview .review-form-textarea').val()
			}
		}]}
		$.ajax({
			url: url,
			method: 'POST',
			headers: {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			dataType: 'json',
			data: JSON.stringify(params)
		}).done(function(result) {
			console.log(result)
		})

User avatar
aimeos
Administrator
Posts: 7873
Joined: 01 Jan 1970, 00:00

Re: Add reviews JSON error 403

Post by aimeos » 26 Nov 2020, 13:37

Seems like the documentation isn't up to date. There have been another check introduced so it's required to pass the ID of the ordered product too to avoid fake reviews. Please try:

Code: Select all

const params = {'data': [{
	'attributes': {
		'review.domain': 'product',
		'review.orderproductid': $('#modalReview .review-form-ordprodid').val(),
		'review.refid': $('#modalReview .review-form-hidden').val(),
		'review.name': $('#modalReview .review-form-name').val(),
		'review.rating': $('#modalReview .review-form-radio:checked').val(),
		'review.comment': $('#modalReview .review-form-textarea').val()
	}
}]}
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
Dinver
Posts: 27
Joined: 26 Oct 2020, 08:42

Re: Add reviews JSON error 403

Post by Dinver » 26 Nov 2020, 14:56

aimeos wrote: 26 Nov 2020, 13:37 Seems like the documentation isn't up to date. There have been another check introduced so it's required to pass the ID of the ordered product too to avoid fake reviews. Please try:

Code: Select all

const params = {'data': [{
	'attributes': {
		'review.domain': 'product',
		'review.orderproductid': $('#modalReview .review-form-ordprodid').val(),
		'review.refid': $('#modalReview .review-form-hidden').val(),
		'review.name': $('#modalReview .review-form-name').val(),
		'review.rating': $('#modalReview .review-form-radio:checked').val(),
		'review.comment': $('#modalReview .review-form-textarea').val()
	}
}]}
Thansk! It is working :)

User avatar
aimeos
Administrator
Posts: 7873
Joined: 01 Jan 1970, 00:00

Re: Add reviews JSON error 403

Post by aimeos » 26 Nov 2020, 15:49

Great, documentation has been updated too.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply