Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating claims of local media to items through api interface #27

Open
plasticadmiral opened this issue Oct 18, 2023 · 1 comment
Open
Labels
question Further information is requested

Comments

@plasticadmiral
Copy link

plasticadmiral commented Oct 18, 2023

Is there an appropriate syntax to claim an image programmatically to an item ?

When i try doing the following,

site = pwb.Site('localwiki:en')
#site.login()

token = pwb.data.api.Request(site=site, parameters={'action': 'query', 'meta': 'tokens'}).submit()
csrf_token = token['query']['tokens']['csrftoken']


result = pwb.data.api.Request(site=site, parameters={'action': 'wbcreateclaim', 'token': csrf_token,
                              'entity': 'P1','property': 'P50', 'snaktype': 'value', 
                              'datatype': 'localMedia', 'type': 'statement',
                             'value': {'value': 'Neo.jpg', 'type': 'localMedia'}}).submit()

I get the following error

APIError: invalid-snak: Invalid snak data.
[param: action=wbcreateclaim&entity=P1&property=P50&snaktype=value&datatype=localMedia&type=statement&value=value%7Ctype&assert=user&maxlag=1&format=json&token=6caed2ab16ab837896c5a17b01d6fee7652fb29e%2B%5C;
 messages: [{'name': 'wikibase-api-invalid-snak', 'parameters': [], 'html': {'*': 'Invalid snak data.'}}];

When i create the claim over the web interface, the json data of the item contains the claim as the following

'claims': <class 'pywikibot.page._collections.ClaimCollection'>(
    {
        'P50': [Claim.fromJSON(DataSite("en", "localwiki"), 
                               {'mainsnak': {'snaktype': 'value', 
                                             'property': 'P50', 
                                             'datatype': 'localMedia', 
                                             'datavalue': {'value': 'Jpg3.jpg', 'type': 'localMedia'}
                                            }, 
                                'type': 'statement', 
                                'id': 'P1$ceabb6c6-4ba1-f31b-d2e1-b18cdb78050e', 
                                'rank': 'normal'}), 
                Claim(DataSite("en", "localwiki"), 'P50'), 
                Claim(DataSite("en", "localwiki"), 'P50')]    
    }
)
@plasticadmiral plasticadmiral added the question Further information is requested label Oct 18, 2023
@JeroenDeDauw
Copy link
Member

I don't recall the specifics, but the format should be the same as for commons media files. I suggest you ask on the Wikibase Telegram or similar support channel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants