Confluence: how to create multiple pages tree from text file (markdown) via script? - confluence

I tried web search site:stackoverflow.com confluence create multiple pages tree from text file (markdown) but did not find the answer to below:
How to create multiple pages tree from text file (markdown)?
I could not find standard macro in confluence for the task too. As I understand Confluence support scripting so it should be possible in automated way. I need tree of pages created in Confluence from indent formatted file (e.g. markdown) like below:
List item
List item
List item

In Confluence, page tree contains different pages which they can be parent and child.
You can create a Parent Page via REST API. According to Atlassian documentation you can use following end point:
curl -u admin:admin -X POST -H 'Content-Type: application/json' -d '{"type":"page","title":"new page",
"space":{"key":"TST"},"body":{"storage":{"value":"<p>This is <br/> a new page</p>","representation":
"storage"}}}' http://localhost:8080/confluence/rest/api/content/ | python -mjson.tool
In same documentation, it shows how you can create child page:
curl -u admin:admin -X POST -H 'Content-Type: application/json' -d '{"type":"page","title":"new page",
"ancestors":[{"id":456}], "space":{"key":"TST"},"body":{"storage":{"value":
"<p>This is a new page</p>","representation":"storage"}}}'
http://localhost:8080/confluence/rest/api/content/ | python -mjson.tool
Thus, you can create different pages via REST api and decide which one need to be parent and which one should be a child page. You just have to feed the endpoint with the content of your text file with the preferred language.

Related

Custom location text for GitHub organization

How do I set a custom text for the location field of my GitHub organization? Such as the one below:
Under the settings of the organization, I can only find a drop-down menu that lets me select a country.
A little late to the game, but this solved my issue!
For organizations:
curl -H "Authorization: bearer GH_PAT_HERE" -d '{"location":"YOUR CUSTOM LOCATION"}' https://api.github.com/orgs/ORG_NAME
Additionally for users:
curl -H "Authorization: bearer GH_PAT_HERE" -d '{"location":"YOUR CUSTOM LOCATION"}' https://api.github.com/user
Credit: https://github.community/t/setting-custom-location-for-github-free-organizations/193506/2
The previous method didn't work for me in 2022, but I found something much simpler.
First, go to your organisation settings.
Next, open DevTools and find the element with ID organization_profile_location. Change its value to whatever you like.
Finally, press "Update profile" to save your changes. Use this method at your own risk, as it is not official.
According to Teddy van Jerry (someone in the comments), this isn't valid for requesting publisher verification.

APIs Explorer's Firestore's projects.databases.documents.list has incorrect regex

Summary: APIs Explorer "Try this API" for projects.databases.documents.list appears (!?) to have an overly restrictive/incorrect regex on parent and requirement on collectionId.
Neither gcloud firestore nor firebase firestore: provides functionality to list collections, I'm planning to write a simple app to do so.
As always, I explored the APIs methods using the excellent APIs Explorer but the projects.databases.documents.list "Try this API" appears (!?) to have an overly restrictive|incorrect regex on parent.
The documentation correctly states that:
https://firestore.googleapis.com/v1/{parent=projects/*/databases/*/documents/*/**}/{collectionId}
And:
Required. The parent resource name. In the format:
projects/{project_id}/databases/{database_id}/documents or
projects/{project_id}/databases/{database_id}/documents/{document_path}.
For example: projects/my-project/databases/my-database/documents or projects/my-project/databases/my-database/documents/chatrooms/my-chatroom
Using Google's first format example: projects/my-project/databases/my-database/documents does not work:
APIs Explorer only accepts the second format example for parent but then requires a value for collectionId which may not be desired:
APIs Explorer appends collectionId to the parent to from the URL. In the case of parent ending /documents (which isn't permitted), this would make sense to access the chatrooms collection or in the case that parent ends /documents/chatrooms/my-chatroom to then get the messages collection (with my-chatroom) but the requirement prohibits using APIs Explorer (!) to query projects/my-project/databases/my-database/documents/chatrooms; collectionId is required and would need to be chatrooms but a parent of projects/my-project/databases/my-database/documents is not permitted.
Using one of my projects (${PROJECT}) and (default) for {database_id}, I can use the documentation's examples correctly in curl:
TOKEN=$(gcloud auth print-access-token)
PROJECT=...
PARENT=projects/${PROJECT}/databases/(default)/documents
COLLECTION=...
curl \
--header "Authorization: Bearer ${TOKEN}" \
--header 'Accept: application/json' \
--write-out '%{response_code}' \
--output /dev/null \
--silent \
https://firestore.googleapis.com/v1/${PARENT}/${COLLECTION}
200
The APIs works correctly navigating down through subcollections too.
Posting this here in the hopes that, if APIs Explorer is indeed incorrect, fixing it can help other developers not encounter this issue and be discouraged.
Note: Since I'm posting feedback, the tool doesn't correctly adjust cURL, HTTP or JavaScript generated examples to reflect the checkbox value on "API Key"; when the "API Key" is deselected, the parameter should not be included in the calls.
It seems to be a problem with the regular expression in the API explorer. I need to enter the parent as projects/fire-template-24/databases/(default)/documents/users/ (including the forward slash) and also enter the collectionId as it's required (users in my case). This seems to be making a query at:
https://[GOOGLE+APIS_URL]/projects/[ID]/databases/(default)/documents/users//users?key=[API_KEY]
This returns an error about the extra trailing slash which the API explorer forced me to add and collectionId field is also appended to it with another /.
The following regular expression seems to be working:
^projects\/[^/]+\/databases\/[^/]+\/documents(\/[^/]+(\/[^/]+\/[^/]+)*)$
The above RegEx doesn't required a forward slash in parent and matches a collection path only. If the collectionId is removed then it should work. Working example of the RegEx can be found here.
I could also observe the same in the API explorer page. I observed that there is an existing issue in the Public Issue Tracker for the same. As mentioned in the #2 comment of the issue, this issue report has been forwarded to the Firestore Engineering team to investigate, but there is no ETA for a resolution. I would suggest you star the issue so that you will get notified whenever there is any update on the issue.

Is it possible to copy sheets over for new budget year, including outbound links?

I have about 75 sheets I have created for our 2019 fiscal year that list budget and actual values for certain company expenses, which link out to a few different summary sheets based on region. I wanted to copy all sheets and blank them out to roll out for the 2020 fiscal year. When I use the Smartsheet API to copy a sheet, it only allows me to copy over inbound links, not outbound ones. Is there a way to copy over outbound links, even to a new sheet?
For reference, I ran the copy sheet code located on the Smartsheet API github page:
curl https://api.smartsheet.com/2.0/sheets/[sheet ID]/copy?include=data,attachments,cellLinks
-H "Authorization: Bearer [token]"
-H "Content-Type: application/json"
-d '{
"destinationType": "home",
"destinationId": null,
"newName": "newSheetName"
}'
-X POST
At this time when making a copy of a sheet, via the API or the UI in your browser, it will only save the inbound cell links. Outbound cell links will be removed with the cell data remaining in place in the newly created sheet. There currently isn't a method to keep the cell links in place via the copy. They would need to be recreated after the copy is done.

Supporting multiple locales for a shared page in facebook

I'm attempting to have multiple title and descriptions for a same endpoint, one per language.
Trying to follow this documentation: https://developers.facebook.com/docs/opengraph/guides/internationalization#objects
I have a server that detects when the client is a bot, for example facebook bot, and it renders a single file with the title and description metas, and the following localization metas. I have a file for each language, and I set og:locale depending on the localization fb_locale that I recieve on the queryparams.
meta(property="og:locale" content="en_gb")
meta(property="og:locale:alternate" content="es_es")
meta(property="og:locale:alternate" content="it_it")
How can I have multiple language for the same endpoint?
This is my testing app and endpoint I'm trying to translate: https://webapp-server-21b.herokuapp.com/marcp
It seems that it crawls it properly, but does not display the preview in the language I expect when I share it on FB or in the debugger of facebook.
If I perform :
curl -X POST -F "id=https://webapp-server-21b.herokuapp.com/marcp" -F "scrape=true" -F "locale=en_gb" "https://graph.facebook.com" -s
or:
curl -X POST -F "id=https://webapp-server-21b.herokuapp.com/marcp" -F "scrape=true" -F "locale=es_es" "https://graph.facebook.com" -s
I get the expected title in the corresponding expected language, but when I share on facebook or in the debugger it's always in english, the default locale.
Thanks!

How to create a child page in Confluence by copying an existing page and using the REST API

I use the following code to create a child page under an existing parent:
curl -v -u admin:password -X POST -H 'Content-Type: application/json' -d'{"type":"page","title":"Created by API", "ancestors":[{"id":97585021}], "space":{"key":"Some_Key"},"body":{"storage":{"value":"<p>This is a test page created by API. Pls ignore</p>","representation":"storage"}}}' https://confluence.ges.symantec.com/rest/api/content/ | python -mjson.tool.
Using this I'm successfully able to create a child page under the parent content id 97585021.
What I would like to do next is: create a page under the parent id 97585021 using another page that acts as a template. The template page is in Confluence under the same content id 97585021. So I would like all pages to be created as a copy of this page.
How can I achieve this?
First step, simply get the page body content of your template in Confluence:
https://confluence.ges.symantec.com/rest/api/content/1234?expand=body.storage
Ref.: https://docs.atlassian.com/confluence/REST/latest/#content-getContentById
With the extracted body content, make some modifications if necessary, and finally create your child page by doing the exact same request you did.