How to create contact point in grafana using API? - api

I am trying to create a contact point in grafana for pagerduty using grafana API.
Tried with the help of these URLS: AlertProvisioning HTTP_API
API call reference
YAML reference of data changed to JSON and tried this way, the YAML reference
But getting error as
{"message":"invalid object specification: type should not be an empty string","traceID":"00000000000000000000000000000000"}
My API code below, replaced with dummy integration key for security.
curl -X POST --insecure -H "Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -H "Content-Type: application/json" -d '{
"contactPoints": [
{
"orgId": 1,
"name": "test1",
"receivers": [
{
"uid": "test1",
"type": "pagerduty",
"settings": {
"integrationKey": "XXXXXXXXXXXXXXXX",
"severity": "critical",
"class": "ping failure",
"component": "Grafana",
"group": "app-stack",
"summary": "{{ `{{ template \"default.message\" . }}` }}"
}
}
]
}
]
},
"overwrite": false
}' http://XXXXXXXXXXXXXXXX.us-east-2.elb.amazonaws.com/api/v1/provisioning/contact-points

I would recommend to enable Grafana swagger UI. You will see POST /api/v1/provisioning/contact-points model there:
Example:
{
"disableResolveMessage": false,
"name": "webhook_1",
"settings": {},
"type": "webhook",
"uid": "my_external_reference"
}

Related

Trying to POST data to ElasticSearch server 8.6, but getting error "no handler found for uri"

I'm trying to send data to an ElasticSearch server using CURL. There is an index called 'datastream2' which has a lot of fields sorta like this:
"datastream2": {
"mappings": {
"properties": {
"UA": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 512
}
}
},
"accLang": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}...
I'd like to use CURL to send data to this index.
I've been using CURL for the attempted POST like this:
curl -v -X POST http://66-228-66-111.ip.linodeusercontent.com:9200/datastream2/newdocname -H "Content-type: application/json" --user elastic:u34XXXc2qYNGnVS4XXXA -d '{"UA":"Mozilla","acclang":"eng"}'
but it's failing with the message:
{"error":"no handler found for uri [/datastream2/newdocname] and method [POST]"}%
I will admit that I'm not sure what to put after the indexname of '/datastream2/' , but I've tried various different values. Some documentation says to list the type (which I'm not sure where to find) and some docs say that this is no longer necessary on ElasticSearch 8+ .
Any ideas how I can get this data posted into ElasticSearch?
You just need to replace newdocname by _doc and it will work
curl -v -X POST http://66-228-66-111.ip.linodeusercontent.com:9200/datastream2/_doc

How can assign permission to user for specific folder in nuxeo using rest api

I upload many files to Nuxeo server using rest API. Now I need to add permission to users. I use http://localhost:8080/nuxeo/api/v1/id/file-id/#acl endpoint with payload:
{
"username": "username",
"permission": "ReadWrite"
}
But it is not working. The error is:
{
"entity-type": "exception",
"status": 405,
"message": "javax.ws.rs.WebApplicationException"
}
How can I do it? Is there any endpoint for that?
Permission can be added by the Document.AddPermission operation available on the http://localhost:8080/nuxeo/api/v1/automation/Document.AddPermission endpoint.
Here is a curl example call used to add ReadWrite permission for editor user to the document with ID 2d28e87f-0753-4cfc-9f9b-b17d424aa6a7:
curl -X POST -u Administrator:Administrator \
http://localhost:8080/nuxeo/api/v1/automation/Document.AddPermission \
-H "Content-Type: application/json" \
-d '{"params":{"users":["editor"],"permission":"ReadWrite"},"input":"2d28e87f-0753-4cfc-9f9b-b17d424aa6a7"}'
And here is an example payload when you want to add permission for external user:
{
"params": {
"users":[],
"email": "some-external#user.com",
"permission": "Read",
"begin": "2020-06-01T00:00:00+02:00",
"end": "2020-06-30T00:00:00+02:00",
"notify": true,
"comment": "notify#me.com"},
"context": {},
"input": "2d28e87f-0753-4cfc-9f9b-b17d424aa6a7"
}

Ansible- AWX login token API

I have installed Ansible-AWX and configured certain playbooks. I want to use the AWX API to run the ansible playbooks on a .net console application. However in order to do so I need a oauth token to login using the postman API. The problem is I am not able to generate the token. I have tried using the AWX cli and few other approaches still no positive results.
Any leads would be appreciated.
Give it a shot here: curl -ku username:password -H "Content-Type: application/json" -X POST -d '{"description":"Tower CLI", "application":null, "scope":"write"}' http:///api/v2/users/1/personal_tokens/ | jq -r .token
https://github.com/ansible/tower-cli/issues/478#issuecomment-370528556
$ curl -ku ryan:ryan -H "Content-Type: application/json" -X POST -d '{"description":"Tower CLI", "application":null, "scope":"read"}' https://awx.example.org/api/v2/users/1/personal_tokens/ | python -m json.tool
{
"application": null,
"created": "2018-03-05T19:06:56.224538Z",
"description": "Tower CLI",
"expires": "2018-03-06T05:06:56.223889Z",
"id": 4,
"modified": "2018-03-05T19:06:56.234208Z",
"refresh_token": null,
"related": {
"activity_stream": "/api/v2/tokens/4/activity_stream/",
"user": "/api/v2/users/1/"
},
"scope": "read",
"summary_fields": {
"user": {
"first_name": "",
"id": 1,
"last_name": "",
"username": "ryan"
}
},
"token": "ABy5N1fBiPujilEJjAUtmPlK8mTdGr",
"type": "o_auth2_access_token",
"url": "/api/v2/tokens/4/",
"user": 1
}

How to add test steps in a test case work item using Rest API - TFS2018 / Python

I am using Microsoft's TFS 2018 and I have started writing some Selenium test cases using Python 3.7 in Visual Studio 2018.
I have managed to use the REST API of TFS to return my TFS projects and create new test cases.
What I couldn't find is how to use this API to pass a list with all the test steps of this test case. I am not sure how and if you can add them in the body of the request as a string or array.
At the moment I am trying to make this work on Postman first and then I am going to try in python as well.
This is the request:
curl -X POST \
'https://TFSLINK:443/DefaultCollection/TFS/_apis/wit/workitems/$Test%20Case?api-version=4.1' \
-H 'Authorization: Basic MYKEY' \
-H 'Content-Type: application/json-patch+json' \
-H 'cache-control: no-cache' \
-d '[
{
"op": "add",
"path": "/fields/System.Title",
"from": null,
"value": "Sample task 2"
}
]'
Is there a way to achieve adding steps ? The API didn't mention anything about this.
In the response I get after creating a test case I get a section called 'fields' which should have included the steps but I can't see them in my response.
{
"id": 731,
"rev": 1,
"fields": {
"System.AreaPath": "TFS",
"System.TeamProject": "TFS",
"System.IterationPath": "TFS",
"System.WorkItemType": "Test Case",
"System.State": "Design",
"System.Reason": "New",
"System.AssignedTo": "Marialena <TFS\\marialena>",
"System.CreatedDate": "2019-01-09T08:00:50.51Z",
"System.CreatedBy": "Marialena <TFS\\marialena>",
"System.ChangedDate": "2019-01-09T08:00:50.51Z",
"System.ChangedBy": "Marialena <TFS\\marialena>",
"System.Title": "Sample task 2",
"Microsoft.VSTS.Common.StateChangeDate": "2019-01-09T08:00:50.51Z",
"Microsoft.VSTS.Common.ActivatedDate": "2019-01-09T08:00:50.51Z",
"Microsoft.VSTS.Common.ActivatedBy": "Marialena <TFS\\marialena>",
"Microsoft.VSTS.Common.Priority": 2,
"Microsoft.VSTS.TCM.AutomationStatus": "Not Automated"
},
"_links": {
"self": {
"href": "https://TFSLINK/DefaultCollection/_apis/wit/workItems/731"
},
"workItemUpdates": {
"href": "https://TFSLINK/DefaultCollection/_apis/wit/workItems/731/updates"
},
"workItemRevisions": {
"href": "https://TFSLINK/DefaultCollection/_apis/wit/workItems/731/revisions"
},
"workItemHistory": {
"href": "https://TFSLINK/DefaultCollection/_apis/wit/workItems/731/history"
},
"html": {
"href": "https://TFSLINK/web/wi.aspx?pcguid=07b658c4-97e5-416f-b32d-3dd48d7f56cc&id=731"
},
"workItemType": {
"href": "https://TFSLINK/DefaultCollection/18ca0a74-cf78-45bf-b163-d8dd4345b418/_apis/wit/workItemTypes/Test%20Case"
},
"fields": {
"href": "https://TFSLINK/DefaultCollection/_apis/wit/fields"
}
},
"url": "https://TFSLINK/DefaultCollection/_apis/wit/workItems/731"
}
I have tried creating this PATCH request to update the steps but it didn't work
curl -X PATCH \
'https://TFSLINK:443/DefaultCollection/TFS/_apis/wit/workItems/730?api-version=4.1' \
-H 'Authorization: Basic MYKEY' \
-H 'Content-Type: application/json-patch+json'
-d '[
{
"op": "add",
"path": "/fields/Microsoft.VSTS.TCM.Steps",
"from": null,
"value": "Test"
},
{
"op": "add",
"path": "/fields/Steps",
"from": null,
"value": "Test"
}
]'
And maybe this is a another topic but if the above is achievable, can you also pass the results after you run the test and update the test plan perhaps ? If this is unrelated please help me only with the test steps and ignore this question.
Many thanks.
This is the way to add test steps in Test Case with Rest API:
{
"op": "add",
"path": "/fields/Microsoft.VSTS.TCM.Steps",
"value": "<steps id=\"0\" last=\"1\"><step id=\"2\" type=\"ValidateStep\"><parameterizedString isformatted=\"true\">Input step 1</parameterizedString><parameterizedString isformatted=\"true\">Expectation step 1</parameterizedString><description/></step></steps>"
}
For a few steps (3 on this example):
{
"op": "add",
"path": "/fields/Microsoft.VSTS.TCM.Steps",
"value": "<steps id=\"0\" last=\"4\"><step id=\"2\" type=\"ValidateStep\"><parameterizedString isformatted=\"true\"><P>step 1 \"Action\"</P></parameterizedString><parameterizedString isformatted=\"true\"><P>step 1 \"Expected\"<BR/></P></parameterizedString><description/></step><step id=\"3\" type=\"ValidateStep\"><parameterizedString isformatted=\"true\"><P>step 2 \"Action\"<BR/></P></parameterizedString><parameterizedString isformatted=\"true\"><P>step 2 \"Expected\"<BR/></P></parameterizedString><description/></step><step id=\"4\" type=\"ValidateStep\"><parameterizedString isformatted=\"true\"><P>step 3 \"Action\"<BR/></P></parameterizedString><parameterizedString isformatted=\"true\"><P>step 3 \"Expected\"<BR/></P></parameterizedString><description/></step></steps>"
}

check status of job requested through travis API v3

So I've submitted a request using travis api v3 guide and got response like:
{
"#type": "pending",
"remaining_requests": 10,
"repository": {
"#type": "repository",
"#href": "/repo/111111111",
"#representation": "minimal",
"id": 111111111,
"name": "my-111111111",
"slug": "me/my111111111"
},
"request": {
"repository": {
"id": 222222,
"owner_name": "me",
"name": "my-111111111"
},
"user": {
"id": 333333
},
"id": 444444,
"message": "Cool message",
"branch": "master"
},
"resource_type": "request"
}
So what is the way to get status of those jobs now? I suppose that I need to use id 444444, but I am getting error below, not sure what I am doing wrong:
curl -s -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Travis-API-Version: 3" \
-H "Authorization: token mycooltoken" \
https://api.travis-ci.org/repo/111111111/requests/444444
{
"#type": "error",
"error_type": "not_found",
"error_message": "resource not found (or insufficient access)"
}
Can somebody point me where to look for examples or any other idea?
Oh sorry for confusion - somehow I overlooked that I must change POST to GET; with that simple fix everything worked fine.