Access and modify all the resources of our Wiki.js using WikiJS API

Hi everyone 😎 , Today we are going to see how to access or modify WikiJS resources using WikiJS API. WikiJS exposes GraphQL API to access and modify the stuff according to our requirements.

So In this blog post, we going to see 

  • How to set up WikiJS's local environment using docker.
  • How to generate an API token in Wikijs.
  • Using API tokens how to access WikiJS resources and how to modify them.

First Local Setup using docker

Here I am using docker to set up my local isolated WikiJS environment. Below is my docker-compose.yml file written by WikiJS contributors.



To build the WikiJS environment we just need to run the following command 

docker-compose up -df  [PATH_OF_DOCKER_COMPOSE_YML_FILE]


To check the environment is in a running state run the following command

docker ps



Second Generate API token

After setup our local environment we are ready to create our initial Administrator account in our WikiJS.

1. On the browser type localhost:80


2. Create an Administrator account 

  • Email: localhost@gmail.com
  • Password: admin@123
  • Site URL: http://localhost
Click Install

3. After login we see initial page of WikiJS.


4. Click on the ADMINISTRATION button and we will be redirected to the administrator dashboard.



5. On the left navigation bar under System click on API access


By default GraphQL API is disabled so first, we have to click on the Enabled API button and thereafter we have to click on the New API Key button to generate an API token.


Now we are going to pass values in the New API Key form to generate a new API
  • Name: Testing
  • Expiration: 1 year
  • Full Access: Checked
Click Generate and copy the API token and paste this token to somewhere in a text file.
Note: Please copy the API token carefully.

Third, using API tokens to access WikiJS resources and modify them


After successfully creating our API token we are ready to use our token in our python script to perform the CURD operations.

Example 1 Performing Read operation: Get the list of pages in WikiJS


Example 2 Performing Read operation: Read a particular document


Example 3 Performing Write operation: Write content on the page
Note: Page is already created

Example 4 Performing Write operation: Create a page


Reference

Hope you enjoyed my blog post. 😎

Comments

Popular posts from this blog

How to pass parameters in webhook?

Fahrenheit to Celsius