Page MenuHomePhabricator

mw.Api is not working with wbcreateclaim
Open, Needs TriagePublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

Trying to add property with coordinates:

  • Read claim-id with wbgetentities.
  • Removed claim (P625) with wbremoveclaims.
  • Adding new value with wbcreateclaim.
var req = api.postWithToken('csrf', {
		action: 'wbcreateclaim',
		entity: 'Q30049941',
		property: 'P625',
		snaktype: 'value',
		value: {
			"latitude": ll.lat,
			"longitude": ll.lon,
			"globe": "http://www.wikidata.org/entity/Q2",
			"precision": 0.000001
		})
	})

What happens?:

The code didn't work. The submitted values were in PHP array syntax (e.g. value[globe]), and the API expected a JavaScript/JSON object.

What should have happened instead?:

The value should either be encoded as an object, or the other syntax should be supported.

By the way, it would be nice if the API responded with a 400 error to indicate a bad payload, but I guess that might require a more significant change...

Software version (skip for WMF-hosted wikis like Wikipedia): WD

Other information (browser name/version, screenshots, etc.):

The code that did work (workaround):

var api = new mw.Api();
var ll = {
	lat: 51.170230459745,
	lon: 16.146803039764
};
var req = api.postWithToken('csrf', {
		action: 'wbcreateclaim',
		entity: 'Q30049941',
		property: 'P625',
		snaktype: 'value',
		value: JSON.stringify({
			"latitude": ll.lat,
			"longitude": ll.lon,
			"globe": "http://www.wikidata.org/entity/Q2",
			"precision": 0.000001
		})
	})
	.done(function (re) {
		console.log(`code: ${re.code}, success: ${re.success}`, re);
	})
	.fail(function (re, r2, r3, r4) {
		//debugger;
		console.warn(re, {
			code: r2?.error?.code,
			info: r2?.error?.info,
			warn: JSON.stringify(r2?.warnings)
		});
	})
;