Wikidata talk:REST API

From Wikidata
Jump to navigation Jump to search

Support ChatGPT Plugins via .well-known/ai-plugin.json =

[edit]

ChatGPT is right now starting to roll out a new Plugin system that allows it to access information from external APIs.

Here are the details:

You basically have to create the file `yourdomain.com/.well-known/ai-plugin.json` Where you describe your API in human language.

Do you think having an official Wikidata plugin for ChatGPT would be nice? It could increase the load on the API, but it also could make searches a lot easier.

---Stefangrotz (talk) 10:29, 28 March 2023 (UTC)[reply]

Datavalue types and consistency with the JSON dump

[edit]

I had a brief look at the JSON format changes and they look sensible to me, as the format seems simpler overall. Two questions I have:

  • When serializing snaks, it looks like you now expose the property's datatype, which is great, but no longer the datavalue type. That could be a problem for Wikidata-Toolkit, which relies on the datavalue type to parse the value correctly. You can argue that the property's datatype is sufficient because it is more precise, but the problem is that, if I understand correctly, datatypes are extensible, whereas datavalue types are not (or at least, I have never seen them being extended). So for a library like Wikidata-Toolkit we cannot know in advance all the datatypes it will be exposed to, whereas datavalue types are more firmly set. So far, the extensions which defined new datatypes all used the "string" datavalue type, but I am not sure we can really assume that it remains like that in the future.
  • Do you plan to align the JSON dump's format to the REST API serialization format? Or should Wikidata-Toolkit expect that both serialization formats will remain in use for the forseable future?

Pintoch (talk) 14:28, 20 January 2023 (UTC)[reply]

Thank you, @Pintoch! Noted about the datavalue type. I'll bring it up in the team.
There is currently no plan do adjust the dump but if that's something that is more widely requested I'd say it's not off the table. Lydia Pintscher (WMDE) (talk) 09:57, 25 January 2023 (UTC)[reply]
@Lydia Pintscher (WMDE): Great! I do think it's much easier for consumers if they can rely on a single JSON serialization format (on the long term), for:
  • the API
  • content-negociation on entity URIs (and therefore the Special:EntityData JSON endpoint)
  • the dumps
I think it's a fairly common use case to download the dumps and then use the API or Special:EntityData in the same application, as soon as you are building a system that relies on Wikidata's data and needs to be kept up to date. In that context, dealing with different JSON serialization formats depending on the source is bound to be quite painful. Arguably there are already some differences in the JSON format in the dumps and the action API, but those are very minor, mostly metadata fields at the root of entities being in the API and not in the dumps if I remember correctly. The structure changes you are introducing here are much more significant than that.
Pintoch (talk) 08:58, 28 January 2023 (UTC)[reply]

Base URL

[edit]

It would be nice if anywhere on Wikidata:REST API or the docs explained very clearly that the base url is /w/rest.php/wikibase/v0 . I spent 30 minutes trying to figure this out and only did by digging into the page for feedback on the beta API. --William Graham (talk) 23:10, 26 January 2023 (UTC)[reply]

Ufff. I'm sorry. That's a good point. Documentation here has been added and we're looking into the swagger part of it. Lydia Pintscher (WMDE) (talk) 15:48, 27 January 2023 (UTC)[reply]

Rate limit for "reading"

[edit]

There are rate limits for GET /entities/items/{item_id}? ValterVB (talk) 11:55, 13 February 2023 (UTC)[reply]

There is no limit for that, no. Lydia Pintscher (WMDE) (talk) 11:58, 14 February 2023 (UTC)[reply]
Are sure that there no rate limit for the `GET /entities/items/{items_id}` route?
My observations:
- I have a code that multiprocesses get requests from Wikidata via the REST API.
- If I turn off multiprocessing, then I can call about 5 GET requests per second and do not have any issues
- If I turn on multiprocessing with 2 CPUs, then I can call about 10-12 GET requests per second.
- After about 150-170 requests or 15 seconds, the rest API returns an error HTTP Error 429: Too Many Requests
Unfortunately, the REST API docs point to the action API rate limits, which only defines rate limits for `edit`, `move`, `upload`, `rollback`.
From what I can tell, other pages quote these exact numbers. I cannot find a rate limit value available for "get requests" for the REST API. Poetest (talk) 17:23, 26 February 2024 (UTC)[reply]
@Poetestare you still hitting this ratelimit? What endpoint are you calling exactly? I am not seeing it at all for the
https://www.wikidata.org/w/rest.php/wikibase/v0/entities/items/Q42 endpoint even when doing 100 RPS (just for a small test). RayScript (talk) 12:16, 25 March 2024 (UTC)[reply]

Help debugging

[edit]

I have been working on some documentation about using the API using powershell, however I am new to API and though it seems to work, it doesn't seems to make any changes (and I can't see any errors), could someone take a look? It in the work in progress section Powershell Back ache (talk) 09:10, 18 August 2023 (UTC)[reply]

Sorry for the late reply. We looked into it a bit and there seems to be an issue with www.wikidata.org vs. wikidata.org. So if you switch to the other one it should work. We are looking into why this is happening in phab:T345572. Lydia Pintscher (WMDE) (talk) 15:42, 4 September 2023 (UTC)[reply]

Is there any endpoint to search entities in Wikibase?

[edit]

Browsing the documentation (https://doc.wikimedia.org/Wikibase/master/js/rest-api/#/items/getItem), I find ways to retrieve data by entering an item or property. Are you planning to add a search engine in the API? PAC2 (talk) 06:49, 21 February 2024 (UTC)[reply]

The REST API is currently not intended for searching for entities. It has come up a few times though and we will have to figure out how this should best be done. For now this is a task for the action API. Lydia Pintscher (WMDE) (talk) 18:21, 22 February 2024 (UTC)[reply]

openapi.json not found?

[edit]

The OpenAPI Swagger documentation mentions openapi.json, but it's giving me a 404: https://www.wikidata.org/w/rest.php/wikibase/v0/openapi.json. Am I looking at the wrong URL? Takumi Fujimoto (talk) 23:07, 2 March 2024 (UTC)[reply]

Thanks for raising this. For me https://www.wikidata.org/w/rest.php/wikibase/v0/openapi.json does load. Is it still an issue for you? It might have been a glitch during deployments. Lydia Pintscher (WMDE) (talk) 09:58, 2 April 2024 (UTC)[reply]

Successful PUT requests without authentication

[edit]

When I send a request with my access token in the Authorization header, it fails and returns the 403 (rest-write-denied) error. This is expected since I don't have bot rights on my user account. However, the same request is successful without including the access token and results in an anonymous edit being made and flagged as unpatrolled due to a new editor changing statement. For example, see this change: https://www.wikidata.org/w/index.php?title=Q55453192&diff=prev&oldid=2117048664. Is this the expected behaviour?

@Lucas Werkmeister (WMDE), this seems very similar to the issue you reported on Phabricator, except the PUT request succeeds either when the bot flag is set to false or no bot flag is included in the request. The request fails with a 403 (rest-write-denied) error when bot flag to true.

Simon Cobb (User:Sic19 ; talk page) 20:57, 2 April 2024 (UTC)[reply]

Hi Simon,
Thanks for raising this. To make sure we understand the issue correctly: you're trying to make an edit without authenticating but with a bot flag set in the request. And that request should be rejected but is not?
If that is the case, we just tried it here and it was rejected. Could you maybe share more details of the request so we can have a closer look? Thanks!
Cheers Lydia Pintscher (WMDE) (talk) 09:57, 3 April 2024 (UTC)[reply]
Hi Lydia,
No, that's not quite right. I can edit without authenticating when "bot": false is included in the request or if the bot key is omitted. For example, see the curl request below that made this edit: https://www.wikidata.org/w/index.php?title=Q63827214&oldid=2118713390
curl -X PUT \ --url 'https://www.wikidata.org/w/rest.php/wikibase/v0/statements/Q63827214$E72AA114-99C0-459C-9457-000637D19D67' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "statement": { "rank": "normal", "property": { "id": "P108" }, "value": { "type": "value", "content": "Q193196" }, "qualifiers": [], "references":[{"parts":[{"property":{"id":"P248","data-type":"wikibase-item"},"value":{"type":"value","content":"Q123508386"}},{"property":{"id":"P7793","data-type":"string"},"value":{"type":"value","content":"0000-0001-5000-2520.xml"}},{"property":{"id":"P854","data-type":"url"},"value":{"type":"value","content":"https://pub.orcid.org/v3.0/0000-0001-5000-2520/employment/295605"}},{"property":{"id":"P5017","data-type":"time"},"value":{"type":"value","content":{"time":"+2014-12-19T00:00:00Z","precision":11,"calendarmodel":"http://www.wikidata.org/entity/Q1985727"}}},{"property":{"id":"P813","data-type":"time"},"value":{"type":"value","content":{"time":"+2023-11-10T00:00:00Z","precision":11,"calendarmodel":"http://www.wikidata.org/entity/Q1985727"}}}]}] }, "tags": [], "bot": false }'
I agree that the request will fail with "bot": true. So, the situation is that I am unable to authenticate as sending my access token returns an error but I can edit without being logged in, which is not what I expected!. Hope that helps. Simon Cobb (User:Sic19 ; talk page) 00:00, 4 April 2024 (UTC)[reply]

Ideas for new calls

[edit]

It would be nice if there was a call to get a list of all the valid sites that can be used with sitelinks, i.e. enwiki, idwikiquote, etc. (The closest I've found to a reference on that is at [1]].)

It would also be nice to have a call for a list of all the language codes that work with labels/descriptions/aliases. And if it differs from the label languages, a list of all language codes that work with monolingual text data type.

And finally a way to get the acceptable units that can be used with the quantity data type. -- William Graham (talk) 01:30, 13 May 2024 (UTC)[reply]