http request using json-pointer slack view.publish JSON-encoded string - api

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}}
}]
}
}'

Related

How to get exact index match of list of objects using curl command?

Here I'm using curl command to call api for fetch exact index match of list of objects like [{},{}]
This is the result of Api Json data
{
"results": [
{
"description": "ncc",
"id": "9cac6ca5-29e2-4062-9326-5f443a5bdc8a",
"artifactId": "e65262ea-68a3-41f3-82b9-18844139c9b7",
"artifactType": "packages",
"displayTypeName": "Workflow Package",
"operationId": "execute_workflow",
"input": [
{
"name": "vnfName",
"value": "NCC",
"group": "default"
},
{
"name": "healthAdditionalParams",
"value": {},
"group": "default"
},
{
"name": "healingAdditionalParams",
"value": {},
"group": "default"
}
],
"additionalParameters": [],
"targetResourceId": "4659b03b-760c-4891-8fda-80305e61468a",
"output": [],
"state": "EXECUTING",
"externalId": null,
"jobId": 493,
"workflowExecutionId": "8afb4eab-4e93-4d67-99fa-face2abb72a8",
"realm": "ncom",
"lastModifiedTime": 1642587522000,
"creationTime": 1642587522000,
"lastModifiedUser": "adminuser",
"deletedAt": null,
"batchOperationsMetadataId": "084cae73-ffa1-4da6-bc92-21ab62a00349",
"scheduleId": null
}]}
I used the below curl command to read these data
curl --location --request -v -k -X GET 'http://localhost/api/v1/aes/?query=state:eq:EXECUTING&query=input[0].value:eq:NCC'\
--header 'Content-Type:application/json'\
--header 'Accept:application/json'\
--header 'Authorization:Bearer eyJhb...'\
When I call above curl command I facing issue so anyone help me to find exact match of input[0].value:eq:'NCC'

Confluence rest API doesn't create page with new editor

I'm trying to create new content page from confluence REST api.
Any page created with REST API show up in old editor view. I have tried editor2 option instead of storage and also i tried with metadata(Example), but no luck.
Is there any solution by which i can create page in new editor (v2) from REST API of confluence.
Found this example on Atlassian.net and it works for me:
curl -u 'user:apitoken' -H 'content-type: application/json' \
'https://hello.atlassian.net/wiki/rest/api/content' \
-d '{
"type": "page",
"title": "Page created via API",
"space": {
"key": "TEST"
},
"body": {
"storage": {
"value": "<h1>Test page</h1>",
"representation": "storage"
}
},
"metadata": {
"properties": {
"editor": {
"value": "v2"
}
}
}
}'

curl send JSON payload

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.

When creating a table with the rest api, how long before it is available?

I am creating a table with curl (successfully):
$ curl https://www.googleapis.com/bigquery/v2/projects/s2g-bd1-001/datasets/integration_tests/tables?key=$BQKEY -H 'Authorization: Bearer '$BQAUTH -H 'Content-Type: application/json' -d '{"kind": "bigquery#table", "tableReference": {"projectId": "s2g-bd1-001", "datasetId": "integration_tests", "tableId": "0479414158500731"}, "friendlyName": "afriendlyname", "description": "afriendlydescription", "schema": {"fields": [{"name": "field1", "type": "STRING"} ] } }'
{
"kind": "bigquery#table",
"etag": "\"p8M0C9D2VWWNeiiBOvzKozM5ryM/W3ReJVrhvIimKGxRGXUdDJZI93w\"",
"id": "s2g-bd1-001:integration_tests.0479414158500731",
"selfLink": "https://www.googleapis.com/bigquery/v2/projects/s2g-bd1-001/datasets/integration_tests/tables/0479414158500731",
"tableReference": {
"projectId": "s2g-bd1-001",
"datasetId": "integration_tests",
"tableId": "0479414158500731"
},
"friendlyName": "afriendlyname",
"description": "afriendlydescription",
"schema": {
"fields": [
{
"name": "field1",
"type": "STRING"
}
]
},
"creationTime": "1403588096488",
"lastModifiedTime": "1403588096488"
}
But then I get a 404 trying to get it back...
$ curl https://www.googleapis.com/bigquery/v2/projects/s2g-bd1-001/datasets/integration_tests/tables/0479414158500731?key=$BQKEY -H 'Authorization: Bearer '$BQAUTH
{
"error": {
"errors": [ {
"domain": "global",
"reason": "notFound",
"message": "Not Found: Table s2g-bd1-001:integration_tests.0479414158500731"
} ],
"code": 404,
"message": "Not Found: Table s2g-bd1-001:integration_tests.0479414158500731"
}
}
To be sure, the table has been created because another call to post it returns a 409:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "duplicate",
"message": "Already Exists: Table s2g-bd1-001:integration_tests.0479414158500731"
}
],
"code": 409,
"message": "Already Exists: Table s2g-bd1-001:integration_tests.0479414158500731"
}
}
I was able to create a few like this and be able to see them, but then suddenly the tables just didn't materialize anymore, even though the post succeeds. I should add that I am able to create tables through the web console successfully.
What's going on?!
When you receive the response for the table creation, it is then created synchronously. That means once you receive your response you should be able to interact with it immediately. You can see that with the creationTime field in the response.
I'm unsure why you are receiving a 404 for the get method. Maybe add some try logic and wait a second or two in between. The response is the table resource so you might also use that instead of retrieving it again.
PS: Did you omit the POST in the curl when you posted it?

Creating an index with REST API

I'm trying to create an index within a set under a specific namespace, but am unsure how to do it.
My resources have this as an HTTP example:
POST /example/v1/index/{namespace}/{set}/{indexName}
and for an example input:
{
"fields": [
{ "indexField": "firstName", "indexReverseOrder": true },
{ "indexField": "lastName" }
],
"options": {
"isUnique": true
}
}
this consumes
application/json;charset=UTF-8
but when I write this out as
curl -X POST exampleurl.com/example/v1/index/example_namespace/example_set/example
set -d " {
"fields": [
{ "indexField": "firstName", "indexReverseOrder": true },
{ "indexField": "lastName" }
],
"options": {
"isUnique": true
} }" -H "Content-type : application/json;charset=UTF-8"
I get the following HTTP status code
HTTP/1.1 415 Unsupported Media Type
Can anyone explain to me what's going on and how I might fix this? Also, let me know if you don't have enough information about the API to understand it, thanks!
EDIT:
As some sort of a reference, for this API when I create a set in a namespace I do:
curl -X POST http://exampleurl.com/example/v1/store/example_namespace -d "example_set" -H "Content-type: application/json;charset=UTF-8"
and this is successful. I thought indexes would be similar to this, but apparently not.
The error is due to the bash shell misinterpreting the double quotes before the json
curl -X POST exampleurl.com/example/v1/index/example_namespace/example_set/example
set -d " {
"fields": [
{ "indexField": "firstName", "indexReverseOrder": true },
{ "indexField": "lastName" }
],
"options": {
"isUnique": true
} }" -H "Content-type : application/json;charset=UTF-8"
should be:
curl -X POST exampleurl.com/example/v1/index/example_namespace/example_set/example
set -d ' {
"fields": [
{ "indexField": "firstName", "indexReverseOrder": true },
{ "indexField": "lastName" }
],
"options": {
"isUnique": true
} }' -H "Content-type : application/json;charset=UTF-8"
The difference is the single quotes encapsulating the json. The bash shell will give an error in trying to execute the command.
You have a typo in your media type:
application/json;charset=UTF=8
Should be:
application/json;charset=UTF-8