Currently, I use curl to send an HTTP PUT to my API:
curl -k -s -u icinga:icinga -H 'Accept: application/json' -X PUT 'https://localhost:5665/v1/objects/hosts/dbserver.example.com' -d '{ "templates": [ "generic-host" ], "attrs": { "zone": "vienna", "address": "xxx.xx.xx.x", "check_command": "hostalive", "vars.os" : "Linux", "vars.agent" : "ssh" } }' | python -m json.tool
This works like a charm.
I'm trying to convert this api call to an ansible playbook. I know that ansible offer the URI module, so I tried to use that, but perhaps something is not configured properly.
---
- name: Add new host
uri:
url: icinga2.example.com:5665/v1/objects/hosts/client.example.com
method: PUT
user: admin
password: xxxxxxx
body: { templates: [ "generic-host" ], attrs: { "zone": "vienna",
"address": "172.x.x.xx", "check_command": "hostalive", "vars.os" : "Linux", "vars.agent" : "ssh" } }
headers: "application/json"
register: icinga_log
when: inventory_hostname in groups ['vienna']
with_items: "{{ groups['icinga-monitoring'] }}"
Usually you could follow error messages that ansible produces and fix your syntax.
Try to start with this modification:
- name: Add new host
uri:
url: http://icinga2.example.com:5665/v1/objects/hosts/client.example.com
method: PUT
user: admin
password: xxxxxxx
body: '{ templates: [ "generic-host" ], attrs: { "zone": "vienna", "address": "172.x.x.xx", "check_command": "hostalive", "vars.os" : "Linux", "vars.agent" : "ssh" } }'
body_format: json
headers:
Content-Type: application/json
Related
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
}
]
}
}
I don't know how to pass the --user field of this curl request in vue-apollo
curl -v \
--user 'user#domain.com:password' \
-X POST \
-H "Content-Type: application/json" \
--data '{ "query": "{ companies{ uid name url }}" }' \
http://localhost:4000/graphql
where in vue-apollo can I set --user ?
I've tried in vue-apollo options object the following
const defaultOptions = {
// You can use `https` for secure connection (recommended in production)
httpEndpoint,
wsEndpoint: null,
persisting: false,
websocketsOnly: false,
ssr: false,
getAuth: () => `Basic user#domain.com:password`
};
but it doesn't work
I'm expecting the companies results
{
"data": {
"companies": [
{
"id": "someId",
"name": "Facebook",
"url": "facebook.com"
},
{
"id": "someId",
"name": "Twitter",
"url": "twitter.com"
}
]
}
}
The getAuth method in defaultOptions should return the encoded Basic authentication
getAuth: () => `Basic ZrT2mWt3gJKHRJ33tf20hJrq==`
const defaultOptions = {
// You can use `https` for secure connection (recommended in production)
httpEndpoint,
wsEndpoint: null,
persisting: false,
websocketsOnly: false,
ssr: false,
getAuth: () => `Basic ZrT2mWt3gJKHRJ33tf20hJrq==`
};
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.
curl -X POST \
https://rally1.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement/create \
-H 'cache-control: no-cache' \
-H 'postman-token: XXXXXXX' \
-H 'zsessionid: XXXXXXX' \
-d '{
"hierarchialrequirement": {
"Name": "Test US",
"Project": "project/XXXXXX",
"Description": "Test US" ,
"PortfolioItem" : {
"_ref" : "portfolioitem/feature/XXXXX" ,
"_type" : "PortfolioItem/Feature"
}
}
}'
Response :
{
"CreateResult": {
"_rallyAPIMajor": "2",
"_rallyAPIMinor": "0",
"Errors": [
"Could not read: Could not read referenced object portfolioitem/feature/XXXXXXXX"
],
"Warnings": []
}
}
i have tried multiple combos of PortfolioItem like
curl -X POST \
https://rally1.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement/create \
-H 'cache-control: no-cache' \
-H 'postman-token: XXXXX' \
-H 'zsessionid: XXXXX' \
-d '{
"hierarchialrequirement": {
"Name": "Test US",
"Project": "project/XXXXXX",
"Description": "TES US" ,
"PortfolioItem" : "portfolioitem/feature/XXXXXX"
}
}'
Response :
{
"CreateResult": {
"_rallyAPIMajor": "2",
"_rallyAPIMinor": "0",
"Errors": [
"Could not read: Could not read referenced object null"
],
"Warnings": []
}
}
i can create US but i just want to add parent feature to it while creating it .
I think you're just missing a leading / on your portfolioitem ref.
"PortfolioItem": "/portfolioitem/feature/12345"
Let me know if that doesn't work!
i was able to fix it by adding the following ref flags
"PortfolioItem": {
"_ref": "portfolioitem/feature/XXXXX",
"_type": "PortfolioItem/Feature"
}
it worked for me now
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