Page MenuHomePhabricator

Error: Invalid Claim while trying to set P2096 and P18 for a wikidata Item
Closed, ResolvedPublic

Description

I am trying to use the wbsetclaim . I am getting the following error from the API. I am trying to use this API for the first time. It would be great if someone could take a look at the error and help me.

{
    "error": {
        "code": "internal_api_error_Deserializers\\Exceptions\\DeserializationException",
        "info": "[5b3b0826-e761-43e6-b577-1afa39901a47] Caught exception of type Deserializers\\Exceptions\\DeserializationException",
        "errorclass": "Deserializers\\Exceptions\\DeserializationException"
    },
    "servedby": "mw1314"
}

This is the claim object that I have:

{
  "id": "Q7110921$150c615e-9708-4836-b5c5-3ecc55efd1f4",
  "mainsnak": {
    "datatype": "string",
    "datavalue": {
      "value": "File:Test.jpg",
      "type": "string"
    },
    "property": "P18",
    "snaktype": "value"
  },
  "rank": "normal",
  "references": [
    {
      "snaks": {
        "P2096": {
          "datatype": "monolingualtext",
          "datavalue": {
            "value": {
              "value": {
                "language": "en",
                "text": "Test"
              }
            },
            "type": "monolingualtext"
          },
          "property": "P2096",
          "snaktype": "value"
        }
      },
      "snaks-order": [
        "P2096"
      ]
    }
  ],
  "type": "statement"
}

Here's the request logs:

POST https://www.wikidata.org/w/api.php?format=json&errorformat=plaintext&action=wbsetclaim&errorlang=uselang
2020-06-22 09:19:53.661 3220-3391/fr.free.nrw.commons D/OkHttp: Content-Type: application/x-www-form-urlencoded
2020-06-22 09:19:53.661 3220-3391/fr.free.nrw.commons D/OkHttp: Content-Length: 789
2020-06-22 09:19:53.661 3220-3391/fr.free.nrw.commons D/OkHttp: Cache-Control: no-cache
2020-06-22 09:19:53.662 3220-3391/fr.free.nrw.commons D/OkHttp: claim=%7B%22id%22%3A%22Q7110921%2497aa5957-4130-4c2b-8b21-a55597a86c94%22%2C%22mainsnak%22%3A%7B%22datatype%22%3A%22string%22%2C%22datavalue%22%3A%7B%22value%22%3A%22File%3ATest.jpg%22%2C%22type%22%3A%22string%22%7D%2C%22property%22%3A%22P18%22%2C%22snaktype%22%3A%22value%22%7D%2C%22rank%22%3A%22normal%22%2C%22references%22%3A%5B%7B%22snaks%22%3A%7B%22P2096%22%3A%7B%22datatype%22%3A%22monolingualtext%22%2C%22datavalue%22%3A%7B%22value%22%3A%7B%22value%22%3A%7B%22language%22%3A%22en%22%2C%22text%22%3A%22Test%22%7D%7D%2C%22type%22%3A%22monolingualtext%22%7D%2C%22property%22%3A%22P2096%22%2C%22snaktype%22%3A%22value%22%7D%7D%2C%22snaks-order%22%3A%5B%22P2096%22%5D%7D%5D%2C%22type%22%3A%22statement%22%7D&tags=wikimedia-commons-app&token=c2ec63aae855281af5515fd7921bc3a65ef0da2a%2B%5C
2020-06-22 09:19:53.662 3220-3391/fr.free.nrw.commons D/OkHttp: --> END POST (789-byte body)
2020-06-22 09:19:53.667 3220-3391/fr.free.nrw.commons D/CookieManager: Domain:www.wikidata.org
2020-06-22 09:19:53.667 3220-3391/fr.free.nrw.commons D/CookieManager: Adding centralauth cookies

Sandbox:

https://www.wikidata.org/wiki/Special:ApiSandbox#action=wbsetclaim&format=json&claim=%7B%22id%22%3A%22Q7110921%24150c615e-9708-4836-b5c5-3ecc55efd1f4%22%2C%22mainsnak%22%3A%7B%22datatype%22%3A%22string%22%2C%22datavalue%22%3A%7B%22value%22%3A%22File%3ATest.jpg%22%2C%22type%22%3A%22string%22%7D%2C%22property%22%3A%22P18%22%2C%22snaktype%22%3A%22value%22%7D%2C%22rank%22%3A%22normal%22%2C%22references%22%3A%5B%7B%22snaks%22%3A%7B%22P2096%22%3A%7B%22datatype%22%3A%22monolingualtext%22%2C%22datavalue%22%3A%7B%22value%22%3A%7B%22value%22%3A%7B%22language%22%3A%22en%22%2C%22text%22%3A%22Test%22%7D%7D%2C%22type%22%3A%22monolingualtext%22%7D%2C%22property%22%3A%22P2096%22%2C%22snaktype%22%3A%22value%22%7D%7D%2C%22snaks-order%22%3A%5B%22P2096%22%5D%7D%5D%2C%22type%22%3A%22statement%22%7D&token=943bc0fb9741e372e27627211a9271765ef0de05%2B%5C

Event Timeline

While this error should definitely be investigated, note that P2096 should be a qualifier, not a reference.

Thanks, @matej_suchanek. That was indeed the cause of the error.

I am now able to call the API successfully. For reference, this is the claim that I am using now.

{
    "id": "Q7110921$35f7634d-f4b9-4d51-aac8-1143ea95230c",
    "mainsnak": {
        "datavalue": {
            "value": "Test.jpg",
            "type": "string"
        },
        "property": "P18",
        "snaktype": "value"
    },
    "qualifiers": {
        "P2096": {
            "datavalue": {
                "value": {
                    "language": "en",
                    "text": "Test"
                },
                "type": "monolingualtext"
            },
            "property": "P2096",
            "snaktype": "value"
        }
    },
    "qualifiers-order": [
        "P2096"
    ],
    "rank": "normal",
    "type": "statement"
}
maskaravivek claimed this task.