Hi,
I’m making API calls for UID of the specific page in Roam Research.
The code I use in the terminal:
#!/bin/bash
# Call the Roam Research API and extract the UID
output=$(curl -s -X POST "https://peer-58.api.roamresearch.com:3001/api/graph/GraphName/q" \
-H "accept: application/json" \
-H "Authorization: Bearer roam-graph-token-XXX" \
-H "Content-Type: application/json" \
-d "{
\"query\" : \"[:find (pull ?b [:block/uid :node/title]) :in $ ?search-string :where [?b :node/title ?page-title] [(clojure.string/includes? ?page-title ?search-string)]]\",
\"args\": [\"@bokszanski2016\"]
}")
uid=$(echo $output)
echo $uid
The result I get for the specific page ‘@bokszanski2016’ is in JSON format:
{
"result": [
[
{
":node/title": "@bokszanski2016",
":block/uid": "nCh-Ttau4"
}
]
]
}
I want to use runCommand in Tinderbox to run the code using $Name (name of the note in Tinderbox and Roam Research is the same) and parse the result into URL attribute.
I’ve tried to run this code
$MyString= runCommand("curl -s -X POST 'https://peer-58.api.roamresearch.com:3001/api/graph/GraphName/q' -H 'accept: application/json' -H 'Authorization: Bearer roam-graph-token-XXX' -H 'Content-Type: application/json' -d '{\"query\" : \"[:find (pull ?b [:block/uid :node/title]) :in $ ?search-string :where [?b :node/title ?page-title] [(clojure.string/includes? ?page-title ?search-string)]]\",\"args\": [\""+$Name+"\"]}'");
but I get
/bin/sh: line 1: unexpected EOF while looking for matching `''
/bin/sh: line 2: syntax error: unexpected end of file
I think the problem is in "+$Name+"
, but I’m not sure… Should I escape the quotes, if so, how do you do it?
Let’s say I somehow managed to make it work, how can I parse the result to make and pseudo-URL look like this one: roam://#/app/GraphName/page/nCh-Ttau4
?
Will the code below work in my case?
$RoamResearchPage="roam://#/app/GraphName/page/" + $MyString.json[:block/uid];
Really appreciate any help!
Arek