Creating an index with REST API - apache

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

Related

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

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

UPDATE INTENT DIALOG FLOW VIA API V1

My problem is that when I want to update an intent via API DIALOGFLOW V1 it returns Unknown Error, BUT I can list and create the intent via API V1, here is my code for the update:
url : https://api.dialogflow.com/v1/intents/f5eedaaa-f7d1-4e4e-b1fa-6aa66c94ca6f?v=20150910
method : PUT
DATA : {"id":"f5eedaaa-f7d1-4e4e-b1fa-6aa66c94ca6f","name":"FORDEBUG","auto":false,"contexts":[],"responses":[{"resetContexts":false,"affectedContexts":[],"parameters":[],"messages":[{"type":0,"condition":null,"speech":["KOKOKOOOKK","KOJKFKF"]}],"defaultResponsePlatforms":[],"speech":[]}],"priority":500000,"webhookUsed":false,"webhookForSlotFilling":false,"fallbackIntent":false,"events":[],"userSays":[{"id":"d891eb29-7233-4f47-901c-751cbde5fff4","data":[{"text":"KOKOK","userDefined":false}],"isTemplate":false,"count":0,"updated":0,"isAuto":false},{"id":null,"data":[{"text":"FJFLFOPF"}]}],"followUpIntents":[],"liveAgentHandoff":false,"endInteraction":false,"conditionalResponses":[],"condition":null,"conditionalFollowupEvents":[],"templates":[]}
and here is the return that I have :
{
"id": "e5bf8ebf-f5e6-4568-8237-f69dcef6f5db",
"timestamp": "2021-06-07T16:53:36.748Z",
"lang": "en",
"status": {
"code": 400,
"errorType": "bad_request",
"errorDetails": "Unknown error errorid=0a4ffdc6-907a-4049-965d-509490bb428e"
}
}
Unfortunately Dialogflow V1 is already deprecated last May 31, 2020 and no further operations can be performed. It is suggested to migrate to Dialogflow V2 so you can continue using the service.
We are extending the V1 API shutdown deadline to May
31st, 2020. Migrate to the V2 API as described here.
If you use Dialogflow exclusively for Actions on Google, you don't
need to migrate your agent to the V2 API. However, note the following
changes:
The Dialogflow simulator will show responses in the V2 format and the
"Copy curl" button will generate requests in the V2 format. This
should have no impact on the functionality of the Actions on Google
simulator.
You will no longer be able to call API methods for the V1
intents and entities resources. You will still be able to modify your
agent using the Dialogflow Console.
Once you have migrated to V2, you can update an intent by batch or per intent.
EDIT 20210609
Here are the request body and call using curl. I'm not knowledgeable in php, but I suppose you can convert this to curl php.
But I assume that the content of the json will go to data:, the endpoint used in the curl command will be url: and method: will be either PATCH (for single intent) or POST (for batch intent update).
Updating a single intent using request_patch.json
{
"name":"projects/your-project-id/agent/intents/your-intent-id",
"displayName":"Image please",
"trainingPhrases":[
{
"type":"EXAMPLE",
"parts":[
{
"text":"Show an image"
}
]
},
{
"type":"EXAMPLE",
"parts":[
{
"text":"Show me an image"
}
]
},
{
"type":"EXAMPLE",
"parts":[
{
"text":"Show me an image please"
}
]
}
]
}
Curl command:
curl -X PATCH -H "Content-Type: application/json" \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
https://dialogflow.googleapis.com/v2/projects/your-project-id/agent/intents/your-intent-id \
-d #request_patch.json
Successful response:
{
"name": "projects/your-project-id/agent/intents/your-intent-id", "displayName": "Image please",
"priority": 500000
}
Updating batch intents using request_batch.json
{
"intentBatchInline":{
"intents":[
{
"name":"projects/your-project-id/agent/intents/your-intent-id",
"displayName":"Image please",
"trainingPhrases":[
{
"type":"EXAMPLE",
"parts":[
{
"text":"Show an image"
}
]
},
{
"type":"EXAMPLE",
"parts":[
{
"text":"Show me an image"
}
]
},
{
"type":"EXAMPLE",
"parts":[
{
"text":"Show me an image please"
}
]
}
]
}
]
}
}
Curl command:
curl -X POST -H "Content-Type: application/json" \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
POST https://dialogflow.googleapis.com/v2/projects/your-project-id/agent/intents:batchUpdate \
-d #request_batch.json
Successful response:
{
"name": "projects/your-project-id/operations/operation-id-here",
"done": true,
"response": {
"#type": "type.googleapis.com/google.cloud.dialogflow.v2.BatchUpdateIntentsResponse",
"intents": [
{
"name": "projects/your-project-id/agent/intents/your-intent-id",
"displayName": "Image please",
"priority": 500000
}
]
}
}

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.

Define a dynamic not_analyzed field for a nested document

I have a document like below, the "tags" field is a nested document, and I want to make all child field for tags document to be index = not_analyzed. The problem is that field in tags will be dynamic. any tag could possible.
So how I can define dynamic mapping for this.
{
strong text'level': 'info',
'tags': {
'content': u'Nov 6 11:07:10 ja10 Keepalived_healthcheckers: Adding service [172.16.08.105:80] to VS [172.16.1.21:80]',
'id': 1755360087,
'kid': '2012121316',
'mailto': 'yanping3,chunying,pengjie',
'route': 15,
'service': 'LVS',
'subject': 'LVS_RS',
'upgrade': 'no upgrade configuration for this alert'
},
'timestamp': 1383707282.500464
}
I think you can use dynamic templates for this. For example following shell script creates dynamic_mapping_test index with dynamic template set when indexing field tags.*, mapping is set to type:string and index:not_analyzed.
echo "Delete dynamic_mapping_test"
curl -s -X DELETE http://localhost:9200/dynamic_mapping_test?pretty ; echo ""
echo "Create dynamic_mapping_test with nested tags and dynamic_template"
curl -s -X POST http://localhost:9200/dynamic_mapping_test?pretty -d '{
"mappings": {
"document": {
"dynamic_templates": [
{
"string_template": {
"path_match": "tags.*",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}
],
"properties": {
"tags": {
"type": "nested"
}
}
}
}
}' ; echo ""
echo "Display mapping"
curl -s "http://localhost:9200/dynamic_mapping_test/_mapping?pretty" ; echo ""
echo "Index document with new property tags.content"
curl -s -X POST "http://localhost:9200/dynamic_mapping_test/document?pretty" -d '{
"tags": {
"content": "this CONTENT should not be analyzed"
}
}' ; echo ""
echo "Refresh index"
curl -s -X POST "http://localhost:9200/dynamic_mapping_test/_refresh"
echo "Display mapping again"
curl -s "http://localhost:9200/dynamic_mapping_test/_mapping?pretty" ; echo ""
echo "Index document with new property tags.title"
curl -s -X POST "http://localhost:9200/dynamic_mapping_test/document?pretty" -d '{
"tags": {
"title": "this TITLE should not be analyzed"
}
}' ; echo ""
echo "Refresh index"
curl -s -X POST "http://localhost:9200/dynamic_mapping_test/_refresh"; echo ""
echo "Display mapping again"
curl -s "http://localhost:9200/dynamic_mapping_test/_mapping?pretty" ; echo ""
I suggest, all string "not_analyzed", and all numbers to long and "not_analyzed".
Because default string analyzed have more memory and file size.
I have reduced size and search fields' full word
range search long type.
{
"mappings": {
"_default_": {
"_source": {
"enabled": true
},
"_all": {
"enabled": false
},
"_type": {
"index": "no",
"store": false
},
"dynamic_templates": [
{
"el": {
"match": "*",
"match_mapping_type": "long",
"mapping": {
"type": "long",
"index": "not_analyzed"
}
}
},
{
"es": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}
]
}
}
}
I don't think there is any way to specify mapping while indexing the data. So, as an alternative, you can modify your tags document to have the following mapping:
{ tags: {
properties: {
tag_type: {type: 'string', index: 'not_analyzed'}
tag_value: {type: 'string', index: 'not_analyzed'}
}
}
}
Here, tag_type can contain the any of the values (content, id, kid, mailto, etc.), and tag_values can contain the actual value of the field that is named in tag_type.