# Use HackMD API ###### tags: `hackmd` Recently I noticed some notes have write permission set to "signed_in". So I wnat to try use HackMD API to get all note write permission setting. Some examples to use the API. #### Test Authentication ``` $ curl -s "https://api.hackmd.io/v1/me" -H "Authorization: Bearer ${HMD_TOKEN}" | python3 -m json.tool { "id": "e7123506-b288-41ac-a747-99149541f918", "name": "Yu-Jung Cheng", "email": "thisisyujungcheng@gmail.com", "userPath": "yujungcheng", "photo": "https://lh3.googleusercontent.com/a-/AOh14GiPU4Ol25du0gFDK70AGKEXzve1w1-N5PLJzXPt", "teams": [] } ``` #### Get note list ``` $ curl -s "https://api.hackmd.io/v1/notes" -H "Authorization: Bearer ${HMD_TOKEN}" | jq .[].title "HackMD API" "ML - kernelized support vector machine" "Setup Ansible AWX" "English Vocablary" "Write startup script on Ubuntu 22.04" "Kustomize examples" "Container & Kubernetes Theory" "OpenShift command (oc) usage" "Python module usage examples" "GCM Encryption" "Setup Ceph storage via ceph-ansible" "Deploy OpenStack using Kolla-Ansible" ``` #### Get note writePermission Get all notes writePermission setting ``` $ curl -s "https://api.hackmd.io/v1/notes" -H "Authorization: Bearer ${HMD_TOKEN}" | jq '.[] | .title+" => "+.writePermission' "HackMD API => owner" "ML - kernelized support vector machine => owner" "Setup Ansible AWX => owner" "English Vocablary => owner" "Write startup script on Ubuntu 22.04 => owner" "Kustomize examples => owner" "Container & Kubernetes Theory => owner" "OpenShift command (oc) usage => owner" "Python module usage examples => owner" "GCM Encryption => owner" "Setup Ceph storage via ceph-ansible => owner" "Deploy OpenStack using Kolla-Ansible => owner" "Setup Ceph storage via cephadm => owner" "temp: dehydrated hook-script for dns-01 => owner" ``` Get "signed_in" writePermission notes ``` $ curl -s "https://api.hackmd.io/v1/notes" -H "Authorization: Bearer ${HMD_TOKEN}" | jq '.[] | .id+" | "+.writePermission+" | "+.title' | grep "signed_in" "aAVOdQtaQQahctoAmKpDhQ | signed_in | Todo list" "jObS44QeToe1ag15ELG9rw | signed_in | temp codes" "n23m4ZMXRUC-iWeq0I3O0Q | signed_in | rpm2cpio usage" "6MC8IZC_Tcy5ygo_UR2uxQ | signed_in | Pytest" "LjvZ2dxcTdqCqrdsO1u-ig | signed_in | Build a minimal Ceph cluster via cephadm" "O0KJ6z3kRFG9jiFP2ioTGg | signed_in | other / temp notes" "vWVzQ70rS9aS3hvlWeB7_w | signed_in | ML - neural networks (deep learning)" "HJIutTy_RmClqyLi2oJs6w | signed_in | Kernel Same-Page Merging (KSM)" "CcMqKw27R7WKaX4N6yT3mw | signed_in | Linux - configure static IP on tinycorelinux" ``` Get note publishedAt ``` $ curl -s "https://api.hackmd.io/v1/notes" -H "Authorization: Bearer ${HMD_TOKEN}" | jq '.[] | .writePermission+" | "+(.publishedAt|tostring)+" | "+.title' ``` #### Update a note write permission ``` $ curl -s -X PATCH "https://api.hackmd.io/v1/notes/rpaIwzgVQmKX3nxnNhoUhg" -H "Authorization: Bearer ${HMD_TOKEN}" -d "{'readPermission':'guest', 'writePermission': 'owner'}" Accepted ``` !!! It still not work even API returns "Accepted" string. Sent bug report. #### Reference https://hackmd.io/@hackmd-api/developer-portal
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up