Reputation: 3840
I am trying to post a request to the telegra.ph api (a simple online publishing tool). In order to edit the content of the page, I am using python requests
. From the sample code I got from the api documentation, I so far have:
import requests
params = {
'path': '/mypage',
'title': 'My Title',
'content':[{"tag":"p","children":["WHAT IS GOING ON"]}],
'author_name': 'My Name',
'author_url': None,
'return_content': 'true'
}
url = 'https://api.telegra.ph/editPage'
r = requests.post(url, json=params)
r.raise_for_status()
response = r.json()
Very simple code, and it works fine. My issue is that I would now like to add a link to my content. I tried changing the tag from "p"
to "a"
but that results in no tags at all in the resulting page. Does anyone know what format they are using for their content, and how I can change the paragraph tag to a link tag?
Upvotes: 0
Views: 743
Reputation: 57
I used this to create a page with a link:
import requests
params = {
'access_token': "",
'path': '/mytestpage',
'title': 'My Title',
'content':[ {"tag":"p","children":["A link to Stackoverflow ",{"tag":"a","attrs":{"href":"http://stackoverflow.com/","target":"_blank"},"children":["http://stackoverflow.com"]}]} ],
'author_name': 'My Name',
'author_url': None,
'return_content': 'true'
}
url = 'https://api.telegra.ph/createPage'
r = requests.post(url, json=params)
r.raise_for_status()
response = r.json()
print response
You should be able to do something similar for editPage.
Tip: You can use something like Postman or Chrome dev tools to figure what is being posted using the telegra.ph UI.
Upvotes: 1