I'm just strating with RabbitMQ and I try to send a json payload to it. Unfortunately I'm getting error:
{"error":"bad_request","reason":"payload_not_string"}
I read somewhere that I need to use "content_type": "application/json" but that has not helped either.
This is the body I'm trying to send:
{
"properties": {
"delivery_mode": 2,
"content_type": "application/json"
},
"routing_key": "git",
"payload": {
"action": "created",
"comment": {
"url": "https://api.github.com/repos/baxterthehacker/public-repo/comments/11056394",
"id": 11056394
}
},
"payload_encoding": "string"
}
And the full curl:
curl -i -X POST \
-H "Content-Type:application/json" \
-H "Authorization:Basic Z3Vlc3Q6Z3Vlc3Q=" \
-d \
'{
"properties": {
"delivery_mode": 2,
"content_type": "application/json"
},
"routing_key": "git",
"payload": {
"action": "created",
"comment": {
"url": "https://api.github.com/repos/baxterthehacker/public-repo/comments/11056394",
"id": 11056394
}
},
"payload_encoding": "string"
}' \
'http://localhost:8090/api/exchanges/%2f/amq.topic/publish'
Is it possible to send the json payload at all? I was thinking of sending Github webhooks to one of the queues.
The RabbitMQ team monitors this mailing list and only sometimes answers questions on StackOverflow.
The error you see is correct, your payload is not a string. I had to reproduce this and re-visit the HTTP API docs for this to become clear.
The value you are passing to the payload key in your JSON is more JSON - in order for it to be a string, you must escape it correctly and pass it like this:
$ curl -4vvv -u guest:guest -H 'Content-Type: application/json' localhost:15672/api/exchanges/%2f/amq.topic/publish --data-binary '{
"properties": {
"delivery_mode": 2,
"content_type": "application/json"
},
"routing_key": "git",
"payload":"{\"action\":\"created\",\"comment\":{\"url\":\"https://api.github.com/repos/baxterthehacker/public-repo/comments/11056394\",\"id\":11056394}}",
"payload_encoding": "string"
}'
The other alternative is to base-64 encode the JSON from GitHub and pass that as the payload - you won't have to escape anything if you do that.
Related
In my pipeline (bash, ubuntu-latest) i want to add into already created library a variable (last git commit hash) is it possible ??
Documentation not telling too much about it
You could use this API to update the variable group: https://learn.microsoft.com/en-us/rest/api/azure/devops/distributedtask/variablegroups/update?view=azure-devops-rest-6.0
Use this predefined variable "Build.SourceVersion" to get the latest commit ID: https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml
Bash script:
curl --location --request PUT 'https://dev.azure.com/{OrgName}/{ProjName}t/_apis/distributedtask/variablegroups/{variablegroupsID}?api-version=7.0' \
--header 'Authorization: Basic {Base64PAT}=' \
--header 'Content-Type: application/json' \
--data-raw '{
"variables": {
"test": {
"value": "$(Build.SourceVersion)"
}
},
"id": 5,
"type": "Vsts",
"name": "1013",
"description": "",
"createdBy": {
"displayName": "{displayName}",
"id": "{id}",
"uniqueName": "{uniqueName}"
},
"createdOn": "2022-10-13T07:41:40.3066667Z",
"modifiedBy": {
"displayName": "{displayName}",
"id": "{id}",
"uniqueName": "{uniqueName}"
},
"modifiedOn": "2022-10-13T07:41:40.3066667Z",
"isShared": false,
"variableGroupProjectReferences": [
{
"projectReference": {
"id": "{Proj id}",
"name": "{Proj Name}"
},
"name": "1013",
"description": ""
}
]
}'
Variable group sample:
Running the script via Azure Pipeline (bash, ubuntu-latest)
Result:
Update1
I want to compress the Data of the Shopware Storefront Search API. At the Moment I get about 50.000 Lines of API
How can I compress the Data and just get the JSON Fields I need?
For my App I need only the Fields
Product Number
Product Name
Product Price
Product Description
manufacturer Name
URL
$json->elements[$i]->productNumber;
$json->elements[$i]->name;
$json->elements[$i]->calculatedPrice->totalPrice;
$json->elements[$i]->description;
$json->elements[$i]->manufacturer->name;
$json->elements[$i]->cover->media->thumbnails[3]->url;
$json->elements[$i]->seoUrls[0]->seoPathInfo;
My API Call:
curl --location --request POST 'https://my-url.com/store-api/search?search=sofa&limit=4' \
--header 'sw-access-key: ***Shopware-Key***' \
--header 'Accept: application/json' \
--header 'sw-include-seo-urls: true' \
--header 'Content-Type: application/json' \
--header 'Cookie: _GRECAPTCHA=1' \
I tryed to insert a API Body
like the Example Code but gets ignored.
--data '{
"page": 1,
"limit": 1,
"filter": [
{
"type": "string",
"field": "string",
"value": "string"
}
],
"sort": [
{
"field": "string",
"order": "string",
"naturalSorting": true
}
],
"post-filter": [
{
"type": "string",
"field": "string",
"value": "string"
}
],
"associations": {},
"aggregations": [
{
"name": "string",
"type": "string",
"field": "string"
}
],
"grouping": [
"string"
],
"order": "string",
"p": 1,
"manufacturer": "string",
"min-price": 0,
"max-price": 0,
"rating": 0,
"shipping-free": false,
"properties": "string",
"manufacturer-filter": true,
"price-filter": true,
"rating-filter": true,
"shipping-free-filter": true,
"property-filter": true,
"property-whitelist": "string",
"reduce-aggregations": "string",
"no-aggregations": "string",
"only-aggregations": "string",
"search": "string"
}'
I do suggest using some kind of tool to compose your queries. Something like Postman will work. After you are done playing, you can export the working query from Postman to CURL as well.
I believe you are looking for the includes filter. Here is a documentation URL for the full article.
I played around a little, but could not filter out sub-queries per your request. I bet it is possible, but you'll have to play around with it yourself as it will require some time :)
curl --location --request POST 'http://website.com/store-api/product' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'sw-access-key: XXXX' \
--data-raw '{
"limit": 1,
"includes": {
"product": ["name", "productNumber", "calculatedPrice", "manufacturer", "cover", "description", "seoUrls"]
},
"associations": {
"manufacturer": {},
"seoUrls": {}
}
}'
Im trying to make this api POST request to view.publish endpoint on slack api
As the documentation explains, im using the token and user_id in params, but i dont know what do i need to do with the view param
i set "application/json;charset=UTF-8" as content-type in the headers and on the body the JSON of the payload i want to publish:
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "This is a section block with a button."
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Click Me",
"emoji": true
},
"value": "click_me_123",
"url": "http://scoreboard-azureslackbot-salvosoftware.s3-website.us-east-2.amazonaws.com/",
"action_id": "button-action"
}
}
]
}
This error is displayed when i make that api call:
{
"ok": false,
"error": "invalid_arguments",
"response_metadata": {
"messages": [
"[ERROR] failed to match all allowed schemas [json-pointer:/view]",
"[ERROR] must provide an object [json-pointer:/view]",
"[ERROR] must provide an object [json-pointer:/view]"
]
}
}
Documentation says that view must be a JSON-encoded string
Also this warning is displayed in the body tab:
This answer is from Aubrey, support team in slack.
No params needed.
In the Authorization tab you need beared authorization.
On the body you need to set is as raw -> JSON and this would be your JSON:
{
"user_id": {{YOUR_USER_ID}},
"view": {
"type": "home",
"blocks": [
{
{{YOUR_PAYLOAD}}
}
]
}
}
It helped me basing on this CURL command
curl -L -X POST 'https://slack.com/api/views.publish' \
-H 'Content-type: application/json' \
-H 'Authorization: Bearer {{YOUR TOKEN}}' \
--data-raw '{
"user_id": {{YOUR USER ID}},
"view": {
"type": "home",
"blocks": [{
{{YOUR PAYLOAD}}
}]
}
}'
I am trying to create a dashboard, for which i am getting all the details using API in Rundeck
and then want to write the data in Csv File,
here is an example trying to fetch data for weekly basis, which is not working [ error msg: {"error":true,"apiversion":35,"errorCode":"api.error.invalid.request","message":"Invalid API Request: /api/35/executions/1w"}],kindly let me know what am i doing wrong to fetch details on weekly, monthly and daily basis
format
#!/bin/sh
protocol="http"
rdeck_host="machinexyz.local"
rdeck_port="4440"
rdeck_api="35"
rdeck_token="token"
rdeck_project="projectRun"
xy="1w"
curl -s --location --request GET "$protocol://$rdeck_host:$rdeck_port/api/$rdeck_api/project/$rdeck_project/$xy" \
--header "Accept: application/json" \
--header "X-Rundeck-Auth-Token: $rdeck_token
Thanks
Following the documentation you could use the recentFilter parameter on your API call, I did an example (at the end I added the jq command to "beautify" the default output):
#!/bin/sh
# protocol
protocol="http"
# basic rundeck info
rdeck_host="localhost"
rdeck_port="4440"
rdeck_api="36"
rdeck_token="ni28E9M5s5H0s3kyCKQ0tbfPCI8jNZS1"
# specific api call info
rdeck_project="ProjectEXAMPLE"
time="1h"
# api call
curl -s --location --request GET "$protocol://$rdeck_host:$rdeck_port/api/$rdeck_api/project/$rdeck_project/executions?recentFilter=$time" \
--header "Accept: application/json" \
--header "X-Rundeck-Auth-Token: $rdeck_token" \
--header "Content-Type: application/json" | jq
Output:
{
"paging": {
"count": 2,
"total": 2,
"offset": 0,
"max": 20
},
"executions": [
{
"id": 2,
"href": "http://localhost:4440/api/36/execution/2",
"permalink": "http://localhost:4440/project/ProjectEXAMPLE/execution/show/2",
"status": "succeeded",
"project": "ProjectEXAMPLE",
"executionType": "scheduled",
"user": "admin",
"date-started": {
"unixtime": 1608296400032,
"date": "2020-12-18T13:00:00Z"
},
"date-ended": {
"unixtime": 1608296400374,
"date": "2020-12-18T13:00:00Z"
},
"job": {
"id": "f2a837d2-1a9c-4387-89d7-0243bbfe6ba9",
"averageDuration": 590,
"name": "HelloWorld",
"group": "",
"project": "ProjectEXAMPLE",
"description": "",
"href": "http://localhost:4440/api/36/job/f2a837d2-1a9c-4387-89d7-0243bbfe6ba9",
"permalink": "http://localhost:4440/project/ProjectEXAMPLE/job/show/f2a837d2-1a9c-4387-89d7-0243bbfe6ba9"
},
"description": "echo \"hi\"",
"argstring": null,
"serverUUID": "94ac86b1-56e9-4bc3-9a4c-50cd7c8a5b59",
"successfulNodes": [
"localhost"
]
},
{
"id": 1,
"href": "http://localhost:4440/api/36/execution/1",
"permalink": "http://localhost:4440/project/ProjectEXAMPLE/execution/show/1",
"status": "succeeded",
"project": "ProjectEXAMPLE",
"executionType": "scheduled",
"user": "admin",
"date-started": {
"unixtime": 1608295800075,
"date": "2020-12-18T12:50:00Z"
},
"date-ended": {
"unixtime": 1608295800914,
"date": "2020-12-18T12:50:00Z"
},
"job": {
"id": "f2a837d2-1a9c-4387-89d7-0243bbfe6ba9",
"averageDuration": 590,
"name": "HelloWorld",
"group": "",
"project": "ProjectEXAMPLE",
"description": "",
"href": "http://localhost:4440/api/36/job/f2a837d2-1a9c-4387-89d7-0243bbfe6ba9",
"permalink": "http://localhost:4440/project/ProjectEXAMPLE/job/show/f2a837d2-1a9c-4387-89d7-0243bbfe6ba9"
},
"description": "echo \"hi\"",
"argstring": null,
"serverUUID": "94ac86b1-56e9-4bc3-9a4c-50cd7c8a5b59",
"successfulNodes": [
"localhost"
]
}
]
}
I am trying to parse the JSON from the Pocket API to keep up with my bookmarks. The JSON recieved after a curl request looks like this:
"list": {
"1548784635": {
"item_id": "1548784635",
"resolved_id": "1548784635",
"given_url": "https://stackoverflow.com/questions/28164849/using-jq-to-par
se-and-display-multiple-fields-in-a-json-serially",
"given_title": "Using jq to parse and display multiple fields in a json se
rially - Stack Ov",
"favorite": "0",
"status": "0",
"time_added": "1542244328",
"time_updated": "1542244341",
"time_read": "0",
"time_favorited": "0",
"sort_id": 0,
"resolved_title": "Using jq to parse and display multiple fields in a json
serially",
"resolved_url": "https://stackoverflow.com/questions/28164849/using-jq-to-
parse-and-display-multiple-fields-in-a-json-serially",
"excerpt": "Using jq I'd like to display first and last name serially. Lik
e so - You can use addition to concatenate strings.",
"is_article": "1",
"is_index": "0",
"has_video": "0",
"has_image": "1",
"word_count": "313",
"lang": "en",
"top_image_url": "https://cdn.sstatic.net/Sites/stackoverflow/img/apple-to
uch-icon#2.png?v=73d79a89bded",
"tags": {
"fields": {
"item_id": "1548784635",
"tag": "fields"
},
"jq": {
"item_id": "1548784635",
"tag": "jq"
},
"multiple": {
"item_id": "1548784635",
"tag": "multiple"
}
},
"authors": {
"45850780": {
"item_id": "1548784635",
"author_id": "45850780",
"name": "abraham",
"url": "https://stackoverflow.com/users/26406/abraham"
},
"82251593": {
"item_id": "1548784635",
"author_id": "82251593",
"name": "San",
"url": "https://stackoverflow.com/users/3713971/san"
}
},
"image": {
"item_id": "1548784635",
"src": "https://i.stack.imgur.com/rZUli.jpg?s=32&g=1",
"width": "32",
"height": "32"
},
"images": {
"1": {
"item_id": "1548784635",
"image_id": "1",
"src": "https://i.stack.imgur.com/rZUli.jpg?s=32&g=1",
"width": "32",
"height": "32",
"credit": "",
"caption": ""
}
},
"domain_metadata": {
"name": "Stack Overflow",
"logo": "https://logo.clearbit.com/stackoverflow.com?size=800",
"greyscale_logo": "https://logo.clearbit.com/stackoverflow.com?size=800&
greyscale=true"
},
"listen_duration_estimate": 121
},
...
I am trying to get the output to look like this with the uri over the tags (trying to transform to csv):
https://stackoverflow.com/questions/28164849/using-jq-to-parse-and-display-multiple-fields-in-a-json-serially
fields, jq, multiple
I tried this but the tags are nested (the consumer_key & access_token are redacted):
curl https://getpocket.com/v3/get --insecure -X POST -H "Content-Type: application/json" -H "X-Accept: application/json" -d "{\"consumer_key\":\"*\", \"access_token\":\"*\", \"detailType\":\"complete\"}" | jq '.list[] | "\(.given_url) \(.tags)"'
Using your sample input after rectification to make it valid JSON:
jq -r '.list[] | [.given_url] + (.tags|keys_unsorted) | #csv' input.json
yields:
"https://stackoverflow.com/questions/28164849/using-jq-to-parse-and-display-multiple-fields-in-a-json-serially","fields","jq","multiple"
This is valid CSV. If you don't want all the double quotation marks, you can use string interpolation as in your attempt.
I added a ?. This works (even for entries without tags). The access_token and consumer_key are redacted in the curl command.
NOTE: the consumer_key & the access_token have each been replace with *
curl https://getpocket.com/v3/get --insecure -X POST -H "Content-Type: application/json" -H "X-Accept: application/json" -d "{\"consumer_key\":\"80793-861ab2c92e846c8324b417e8\", \"access_token\":\"b6b55049-fe0a-df88-8f78-eb9ccc\", \"detailType\":\"complete\"}" | jq -r '.list[] | [.given_url] + (.tags|keys_unsorted?) | #csv' | less
From the jq manual:
.[]?
Like .[], but no errors will be output if . is not an array or object.