Try using Pleasant's API (python / FastAPI)

Overview

https://qiita.com/donraku/items/147fbea348657a4ffbf1 Based on the contents of ↑, I decided to use Pleasanter's "API function" using python this time. I tried to adopt a framework when using python.

Prerequisites

These details are omitted.

Conclusion

I was able to register data in Pleasant using python. (With API) I found that the framework's Fast API is quite usable.

Details

Choose a python framework

Considering future development, I decided to use the framework. I took a quick look and adopted the Fast API because it looks good. Installation work is omitted.

Click here for information. https://fastapi.tiangolo.com/ja/

Preparing for development with FastAPI

Based on the manual, create the smallest source and start the web server. The web server is uvicorn.

Click here for the source. This is all you need.

main.py


from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def read_root():
    return {"Hello": "World"}

Start the web server from the command prompt. Since the port conflicted with the default, specify 8010. It will start immediately.

>uvicorn main:app --reload --port 8010
INFO:     Uvicorn running on http://127.0.0.1:8010 (Press CTRL+C to quit)
INFO:     Started reloader process [26816] using statreload
INFO:     Started server process [22304]
INFO:     Waiting for application startup.
INFO:     Application startup complete.

Check the display on the browser. Display is OK.

image.png

Documents can also be created without permission. It's pretty amazing. By the way.

image.png

Register with Pleasant from FastAPI (python)

Create an endpoint called "/ test_create" as a trial, and register the data in Pleasant in it.

main.py


import requests
import json
from fastapi import FastAPI
from requests_ntlm import HttpNtlmAuth


app = FastAPI()


@app.get("/")
def read_root():
    return {"Hello": "World"}


@app.get("/test_create")
def test_create():

    url = 'http://192.168.10.10/pleasanter/api/items/12389/create'

    json_str = '''\
    {
        "ApiVersion": 1.1,
        "ApiKey": "ea55625bb586d27df01c281e5ef5464e4bbe6bc86d1451a24fd430351198ce0bbabc467cdd1d0ebdf4045ec22922dfce7a9f47a8241559229a7d5129d2329879",
        "ClassHash": {
            "ClassA": "Name 2",
            "ClassB": "Affiliation 3",
            "ClassC": "Place 4"
        },
        "DateHash": {
            "DateA": "2020/11/08 08:00",
            "DateB": "2020/11/08 17:00"
        },
        "Body": "I work normally"
    }
    '''
    json_data = json.loads(json_str)

    headers = {'content-type': 'application/json; charset=UTF-8'}
    response = requests.post(url, json=json_data, headers=headers,
                             auth=HttpNtlmAuth('xxx\xxx', 'xxx'))

    return (response.text)

image.png

When executed using the document above. .. ..

image.png

success! !! "{" Id \ ": 12410, " Status Code \ ": 200, " Message \ ": " \\ "Name 2 \" has been created. \ "}"

image.png

Check on the Pleasant screen and OK!

I was able to register, so that's it.

Recommended Posts

Try using Pleasant's API (python / FastAPI)
Try using Python argparse's action API
Try using the Wunderlist API in Python
Try using the Kraken API in Python
Try using Tweepy [Python2.7]
Try using the BitFlyer Ligntning API in Python
Try using ChatWork API and Qiita API in Python
Try using the DropBox Core API in Python
[Python] Try using Tkinter's canvas
Try using the Twitter API
Try using the Twitter API
Try using the PeeringDB 2.0 API
Try using Janus gateway's Admin API
Data acquisition using python googlemap api
[Python3] Google translate google translate without using api
Try python
Try using LevelDB in Python (plyvel)
Try using the Python Cmd module
Create a CRUD API using FastAPI
Run Ansible from Python using API
Try using Leap Motion in Python
Try using Amazon DynamoDB from Python
Mouse operation using Windows API in Python
Try mathematical formulas using Σ with python
Try using Dialogflow (formerly API.AI) Python SDK #dialogflow
Tweet using the Twitter API in Python
Try using Dropbox API v2 with Go
Try using Python with Google Cloud Functions
Try using Junos On-box Python # 2 Commit Script
Get Youtube data in Python using Youtube Data API
I tried using UnityCloudBuild API from Python
Try to operate Excel using Python (Xlwings)
Quickly try Microsoft's Face API in Python
Try using Junos On-box Python # 1 Op Script
Try hitting the YouTube API in Python
Creating Google Spreadsheet using Python / Google Data API
Try using Tkinter
Try using docker-py
Try using PDFMiner
Start using Python
Try using geopandas
Try using Selenium
Try using scipy
Python> try: / except:
Try using pandas.DataFrame
Try using django-swiftbrowser
Try using matplotlib
Try using tf.metrics
Try using PyODE
Scraping using Python
Procedure to use TeamGant's WEB API (using python)
[Python] Get all comments using Youtube Data API
Get image URL using Flickr API in Python
Try using the Python web framework Tornado Part 1
Let's judge emotions using Emotion API in Python
Recent ranking creation using Qiita API with Python
Manipulate objects using Blender 2.8's low-level Python API
Try using the collections module (ChainMap) of python3
Anonymous upload of images using Imgur API (using Python)
Try using tensorflow ① Build python environment and introduce tensorflow
Try using kabu station API of kabu.com Securities