I am trying to link to an article that has an alias associated with it. I have not been able to find any documentation on how this is done.
Here is what I have done so far:
Step 1: Created an Article by posting it to the /articles API:
curl -X 'POST' \
'https://mysubdomain.vanilladevelopment.com/api/v2/articles' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H 'x-transient-key: mykey' \
-d '{
"body": "demo",
"draftID": 0,
"format": "text",
"knowledgeCategoryID": 512,
"name": "Article Title"
}'
I received positive confirmation that an article was created:
{
"articleID": 987,
"articleRevisionID": 1348,
"knowledgeCategoryID": 512,
"breadcrumbs": [
{
"name": "Learners",
"url": "https://mysubdomain.vanilladevelopment.com/english/kb/documentation-learners"
}
],
"knowledgeBaseID": 4,
"name": "Article Title",
"body": "demo",
"outline": [],
"excerpt": "demo",
"seoDescription": null,
"seoName": null,
"slug": "987-article-title",
"sort": 14,
"score": 0,
"views": 0,
"url": "https://mysubdomain.vanilladevelopment.com/english/kb/articles/987-article-title",
"insertUserID": 9,
"dateInserted": "2022-08-19T13:34:33+00:00",
"updateUserID": 9,
"dateUpdated": "2022-08-19T13:34:33+00:00",
"status": "published",
"featured": false,
"dateFeatured": null,
"locale": "en",
"translationStatus": "up-to-date",
"foreignID": null
}
Step 2: Created an alias to the article using the articles/{id}/aliases API
curl -X 'PUT' \
'https://mysubdomain.vanilladevelopment.com/api/v2/articles/987/aliases' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H 'x-transient-key: mykey' \
-d '{
"aliases": [
"andy987"
]
}'
I received positive confirmation that the alias was created:
{
"articleID": 987,
"articleRevisionID": 1348,
"knowledgeCategoryID": 512,
"breadcrumbs": [
{
"name": "Learners",
"url": "https://mysubdomain.vanilladevelopment.com/english/kb/documentation-learners"
}
],
"knowledgeBaseID": 4,
"name": "Article Title",
"body": "demo",
"outline": [],
"excerpt": "demo",
"seoDescription": null,
"seoName": null,
"slug": "987-article-title",
"sort": 14,
"score": 0,
"views": 0,
"url": "https://mysubdomain.vanilladevelopment.com/english/kb/articles/987-article-title",
"insertUserID": 9,
"dateInserted": "2022-08-19T13:34:33+00:00",
"updateUserID": 9,
"dateUpdated": "2022-08-19T13:34:33+00:00",
"aliases": [
"andy987"
],
"status": "published",
"featured": false,
"dateFeatured": null,
"locale": "en",
"translationStatus": "up-to-date",
"foreignID": null
}
My question is how do I refer to the alias (i.e. andy987) from within another article ? I have tried:
https://mysubdoamin.vanilladevelopment.com/english/kb/articles/andy987
https://mysubdoamin.vanilladevelopment.com/english/kb/andy987
https://mysubdoamin.vanilladevelopment.com/andy987
and none of these work.
<<<<<<<<<<
Related
I see that jq can calculate addition as simply as jq 'map(.duration) | add' but I've got a more complex command and I can't figure out how to perform this add at the end of it.
I'm starting with data like this:
{
"object": "list",
"data": [
{
"id": "in_1HW85aFGUwFHXzvl8wJbW7V7",
"object": "invoice",
"account_country": "US",
"customer_name": "clientOne",
"date": 1601244686,
"livemode": true,
"metadata": {},
"paid": true,
"status": "paid",
"total": 49500
},
{
"id": "in_1HJlIZFGUwFHXzvlWqhegRkf",
"object": "invoice",
"account_country": "US",
"customer_name": "clientTwo",
"date": 1598297143,
"livemode": true,
"metadata": {},
"paid": true,
"status": "paid",
"total": 51000
},
{
"id": "in_1HJkg5FGUwFHXzvlYp2uC63C",
"object": "invoice",
"account_country": "US",
"customer_name": "clientThree",
"date": 1598294757,
"livemode": true,
"metadata": {},
"paid": true,
"status": "paid",
"total": 57000
},
{
"id": "in_1H8B0pFGUwFHXzvlU6nrOm6I",
"object": "invoice",
"account_country": "US",
"customer_name": "clientThree",
"date": 1595536051,
"livemode": true,
"metadata": {},
"paid": true,
"status": "paid",
"total": 20000
}
],
"has_more": true,
"url": "/v1/invoices"
}
and my jq command looks like:
cat example-data.json |
jq -C '[.data[]
| {invoice_id: .id, client: .customer_name, date: .date | strftime("%Y-%m-%d"), amount: .total, status: .status}
| .amount = "$" + (.amount/100|tostring)]
| sort_by(.date)'
which nicely gives me output like:
[
{
"invoice_id": "in_1H8B0pFGUwFHXzvlU6nrOm6I",
"client": "clientThree",
"date": "2020-07-23",
"amount": "$200",
"status": "paid"
},
{
"invoice_id": "in_1HJlIZFGUwFHXzvlWqhegRkf",
"client": "clientTwo",
"date": "2020-08-24",
"amount": "$510",
"status": "paid"
},
{
"invoice_id": "in_1HJkg5FGUwFHXzvlYp2uC63C",
"client": "clientThree",
"date": "2020-08-24",
"amount": "$570",
"status": "paid"
},
{
"invoice_id": "in_1HW85aFGUwFHXzvl8wJbW7V7",
"client": "clientOne",
"date": "2020-09-27",
"amount": "$495",
"status": "paid"
}
]
and I want to add a sum/total at the end of that, something like Total: $1775, so that the entire output would look like this:
[
{
"invoice_id": "in_1H8B0pFGUwFHXzvlU6nrOm6I",
"client": "clientThree",
"date": "2020-07-23",
"amount": "$200",
"status": "paid"
},
{
"invoice_id": "in_1HJlIZFGUwFHXzvlWqhegRkf",
"client": "clientTwo",
"date": "2020-08-24",
"amount": "$510",
"status": "paid"
},
{
"invoice_id": "in_1HJkg5FGUwFHXzvlYp2uC63C",
"client": "clientThree",
"date": "2020-08-24",
"amount": "$570",
"status": "paid"
},
{
"invoice_id": "in_1HW85aFGUwFHXzvl8wJbW7V7",
"client": "clientOne",
"date": "2020-09-27",
"amount": "$495",
"status": "paid"
}
]
Total: $1775
Is there a neat/tidy way to enhance this jq command to achieve this?
Or even, since I'm invoking this in a shell script, a dirty/ugly way with bash?
If any of your output is going to be raw, you need to pass -r; it'll just be ignored for data items that aren't strings.
Anyhow -- if you write (expr1, expr2), then your input will be passed through both expressions. Thus:
jq -Cr '
([.data[]
| {invoice_id: .id,
client: .customer_name,
date: .date | strftime("%Y-%m-%d"),
amount: .total,
status: .status}
| .amount = "$" + (.amount/100|tostring)
] | sort_by(.date)),
"Total: $\([.data[] | .total] | add | . / 100)"
'
In case you decide after all to emit valid JSON, here is a modular answer to the question that makes it easy to formulate alternative approaches, and which postpones the conversion of .amount to dollars for efficiency:
def todollar:
"$" + tostring;
def json:
[.data[]
| {invoice_id: .id,
client: .customer_name,
date: .date | strftime("%Y-%m-%d"),
amount: (.total/100),
status: .status} ]
| sort_by(.date) ;
json
| map_values(.amount |= todollar),
"Total: " + (map(.amount) | add | todollar)
As noted elsewhere, you will probably want to use the -r command-line option.
I've been working on creating a script utilizes curl and variables. Doing some searches I found how to place a variable in the data portion of the curl but now I'm getting errors from the curl command.
(Some parts of the code removed to keep passwords out, everything is working except for entering the data into the --data portion of curl)
curlData=$(cat <<EOF
{
"rebootClient": false,
"createPseudoClientRequest": {
"registerClient": true,
"clientInfo": {
"clientType": 0,
}
},
"packages": [
{
"packageId": 702,
"packageName": "File System",
"packageId": 51,
"packageName": "MediaAgent"
}
],
},
"entities": [
{
"clientId": 0,
}
]
}
EOF
)
shopt -u nocasematch #Sets options back to being case sensitive
echo "$csName"
curl -vv --location --request POST "http://$csName:81/SearchSvc/CVWebService.svc/InstallClient" --header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header "Authtoken: $token" \
-d "$curlData"
Doing a bash -x everything looks correct
"rebootClient": false,
"createPseudoClientRequest": {
"registerClient": true,
"clientInfo": {
"clientType": 0,
}
},
"packages": [
{
"packageId": 702,
"packageName": "File System",
"packageId": 51,
"packageName": "MediaAgent"
}
],
"clientAuthForJob": {
},
"entities": [
{
"clientId": 0,
"clientName": "srybrcost",
}
]
}'
But every time I get Request body is empty or format is invalid
I know I can use html and markdown in my incoming webhook, but when I try to embed a link, it does not work. Need help, please
curl -H "Content-Type: application/json" -d "{\"text\": \"<a href=' www.microsoft.com'>visit</a >\"}" <my webhook url>
curl -H "Content-Type: application/json" -d "{\"text\": \"[visit](www.microsoft.com)\"}" <my webhook url>
Standard markdown can be used:
curl --header "Content-Type: application/json" \
--data "{\"text\": \"[visit](https://www.microsoft.com)\"}" \
<my webhook url>
Note that OP omitted the URI scheme, which prevents Teams from identifying the URL as a valid one.
I got the similar issue before, and I found I could use adaptive cards. It's much more powerful! Below is the sample payload.
{
"#type": "MessageCard",
"#context": "http://schema.org/extensions",
"themeColor": "0076D7",
"summary": "a summary",
"sections": [{
"activityTitle": "A title",
"activitySubtitle": "a subtitle",
"markdown": true
}],
"potentialAction": [{
"#type": "ActionCard",
"name": "Visit",
"actions": [{
"#type": "OpenUri",
"name": "Visit",
"targets": [
{ "os": "default", "uri": "https://www.microsoft.com" }
]
}]
}]
}
I'm working in a Jenkinsfile and trying to parse the following return output. I can get the uuid but I can't get name. Looking for some guidance.
Jenkinsfile
node('ansible'){
stage('Get VM List'){
def content = sh (returnStdout: true, script: "curl -X GET --header 'Content-Type: application/json' --header 'Accept: application/octet-stream' 'http://someurlapi'").trim()
def vmList = readJSON text: content;
//Works
echo vmList[0].uuid
}}
Return Output
[
{
"num": XX,
"ip": "XX.XX.XX.XX",
"type": "KVM",
"name": "machinename",
"state": "Running",
"ram": 4096,
"ram-display": "4 GiB",
"zpool": {
"name": "zpool",
"compression": "lz4",
"mountpoint": "\/mnt",
"mounted": true
},
"uuid": "d7622bd3-ed3d-5000-ae01-89ab294933r1",
"autostart": false,
"cpu": 2
}]
I figured it out I changed it to
echo vmList[0]["name"]
When attempting to index the following document:
{
"branch": "master",
"classes": [
{
"content_count": 2,
"documentation": "",
"extends": [],
"generic": "",
"implements": [],
"line": 10,
"line_count": 36,
"modifiers": [
"public"
],
"name": "removeDuplicateFromString"
}
],
"commit_hash": "e53249ba2381d2f20f3d4493ad70e2da0abb3b05",
"contributors": [
{
"id": "7676016",
"name": "varunu28",
"url": "https://github.com/varunu28"
}
],
"enums": [],
"fields": [],
"filename": "removeDuplicateFromString.java",
"imports": [
{
"name": "java.io.BufferedReader",
"wildcard": false
},
{
"name": "java.io.InputStreamReader",
"wildcard": false
}
],
"interfaces": [],
"license": "",
"methods": [
{
"cyclomatic_complexity": 1,
"documentation": "",
"generic": "",
"line": 11,
"line_count": 9,
"modifiers": [
"public",
"static"
],
"name": "main",
"params": [
{
"name": "args",
"type": "String[]"
}
],
"parent": "removeDuplicateFromString",
"type_": "void"
},
{
"cyclomatic_complexity": 5,
"documentation": "",
"generic": "",
"line": 29,
"line_count": 16,
"modifiers": [
"public",
"static"
],
"name": "removeDuplicate",
"params": [
{
"name": "s",
"type": "String"
}
],
"parent": "removeDuplicateFromString",
"type_": "String"
}
],
"number_forks": 1695,
"number_stars": 4000,
"number_watchs": 394,
"package": "",
"path": "Others",
"repository": "TheAlgorithms/Java"
}
I get the following error:
{"error":{"root_cause":[{"type":"settings_exception","reason":"Failed to load settings from [{\"interfaces\":[],\"imports\":[{\"name\":\"java.io.BufferedReader\",\"wildcard\":false},{\"name\":\"java.io.InputStreamReader\",\"wildcard\":false}],\"package\":\"\",\"methods\":[{\"parent\":\"removeDuplicateFromString\",\"line_count\":9,\"line\":11,\"documentation\":\"\",\"name\":\"main\",\"cyclomatic_complexity\":1,\"modifiers\":[\"public\",\"static\"],\"params\":[{\"name\":\"args\",\"type\":\"String[]\"}],\"type_\":\"void\",\"generic\":\"\"},{\"parent\":\"removeDuplicateFromString\",\"line_count\":16,\"line\":29,\"documentation\":\"\",\"name\":\"removeDuplicate\",\"cyclomatic_complexity\":5,\"modifiers\":[\"public\",\"static\"],\"params\":[{\"name\":\"s\",\"type\":\"String\"}],\"type_\":\"String\",\"generic\":\"\"}],\"number_forks\":1695,\"classes\":[{\"implements\":[],\"line_count\":36,\"extends\":[],\"line\":10,\"documentation\":\"\",\"name\":\"removeDuplicateFromString\",\"content_count\":2,\"modifiers\":[\"public\"],\"generic\":\"\"}],\"repository\":\"TheAlgorithms/Java\",\"branch\":\"master\",\"commit_hash\":\"e53249ba2381d2f20f3d4493ad70e2da0abb3b05\",\"enums\":[],\"path\":\"Others\",\"license\":\"\",\"filename\":\"removeDuplicateFromString.java\",\"number_watchs\":394,\"contributors\":[{\"name\":\"varunu28\",\"id\":\"7676016\",\"url\":\"https://github.com/varunu28\"}],\"fields\":[],\"number_stars\":4000}]"}],"type":"settings_exception","reason":"Failed to load settings from [{\"interfaces\":[],\"imports\":[{\"name\":\"java.io.BufferedReader\",\"wildcard\":false},{\"name\":\"java.io.InputStreamReader\",\"wildcard\":false}],\"package\":\"\",\"methods\":[{\"parent\":\"removeDuplicateFromString\",\"line_count\":9,\"line\":11,\"documentation\":\"\",\"name\":\"main\",\"cyclomatic_complexity\":1,\"modifiers\":[\"public\",\"static\"],\"params\":[{\"name\":\"args\",\"type\":\"String[]\"}],\"type_\":\"void\",\"generic\":\"\"},{\"parent\":\"removeDuplicateFromString\",\"line_count\":16,\"line\":29,\"documentation\":\"\",\"name\":\"removeDuplicate\",\"cyclomatic_complexity\":5,\"modifiers\":[\"public\",\"static\"],\"params\":[{\"name\":\"s\",\"type\":\"String\"}],\"type_\":\"String\",\"generic\":\"\"}],\"number_forks\":1695,\"classes\":[{\"implements\":[],\"line_count\":36,\"extends\":[],\"line\":10,\"documentation\":\"\",\"name\":\"removeDuplicateFromString\",\"content_count\":2,\"modifiers\":[\"public\"],\"generic\":\"\"}],\"repository\":\"TheAlgorithms/Java\",\"branch\":\"master\",\"commit_hash\":\"e53249ba2381d2f20f3d4493ad70e2da0abb3b05\",\"enums\":[],\"path\":\"Others\",\"license\":\"\",\"filename\":\"removeDuplicateFromString.java\",\"number_watchs\":394,\"contributors\":[{\"name\":\"varunu28\",\"id\":\"7676016\",\"url\":\"https://github.com/varunu28\"}],\"fields\":[],\"number_stars\":4000}]","caused_by":{"type":"illegal_state_exception","reason":"only value lists are allowed in serialized settings"}},"status":500}
From which I've gathered that the main issues are either described in the part saying that:
{"type":"illegal_state_exception","reason":"only value lists are allowed in serialized settings"}}
Or:
"error":{"root_cause":[{"type":"settings_exception","reason":"Failed to load settings from [{\"interfaces\":[],\"imports\": ........
But I cannot find any information about this error or what it could be caused by. I've tried indexing both using a predefined index with mappings and to a non-existing index. Nothing seems to work.
Why can't I index this document?
It turns out that, as Farid mentioned in the comments section, I was using the wrong command when indexing from the command line.
The correct command to run is
curl -X POST -H 'Content-Type: application/json' [index location] -d [data]
Where the key is that you use POST and not PUT which is what I was doing.
Adding this for the ones using Kibana Dev Tools.
The key is to use an document type after an index name when adding the document
POST /{index name}/{document type}
{
request body (document) goes here.
}