Advertisement
Guest User

wp api test

a guest
Feb 20th, 2022
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const request = require('request').defaults({jar: true})
  2.  
  3. const url = "https://en.wikipedia.org/w/api.php"
  4. const csrf_token = // output of mw.user.tokens.get('csrfToken') from my JS console
  5.  
  6. const params = {
  7.     action: "edit",
  8.     title: "User:Satricious/sandbox",
  9.     appendtext: "test edit",
  10.     token: csrf_token,
  11.     format: "json"
  12. }
  13.  
  14. request.post({ url: url, form: params }, (error, res, body) => {
  15.     if (error) return
  16.  
  17.     console.log(body)
  18. })
  19.  
  20. /* The output I get:
  21.  
  22. {"error":{"code":"badtoken","info":"Invalid CSRF token.","*":"See https://en.wikipedia.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/> for notice of API deprecations and breaking changes."},"servedby":"mw1343"}
  23.  
  24. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement