Unable to import grafana dashboard using exported json through CLI - grafana

I was trying to import dashboard using exported json file from one server to another server of grafana, but getting bellow error;
{"message":"Dashboard not found","status":"not-found"}
My curl command:
curl -X POST --insecure -H "Authorization: Bearer {API KEY}" -H "Content-Type: application/json" --data-binary #'{JSON file name}' http://{Host ip}:3000/api/dashboards/db
To export dashboard, I am using following curl command;
curl -f -k -H "Authorization: Bearer {API key}" "http://{Host IP}:3000/api/dashboards/db/mydashboard" | jq 'del(.overwrite,.dashboard.version,.meta.created,.meta.createdBy,.meta.updated,.meta.updatedBy,.meta.expires,.meta.version)' > {JSON file name}"
I am unable to find exact missing field OR value which is missing OR incorrectly passed through JSON file while importing. Is there any way to debug?
Is there any issue with my Export and import command.

As mentioned in this issue,
you must replace the "id": num field of the dashboard with null.
so you can change it for all of your dashboards (.json files) by command below: (works with GNU sed only)
sed -i '0,/"id": .*/{s/"id": .*/"id": null,/}' *.json

The simplest solution is to set the 'id' from root of the json to null.
"id": null,
Be aware, it's not the same field as uid in the end of the json (also root). That one must be unique, but not null.

Related

Add existing user to existing group apache ranger

im looking at apache Ranger rest API to add an existing internal user/users to an existing internal group.
I have been looking at the docs and cant seem to find something useful,is there an API for that?
Try following api call:-
curl -ivk -u admin:admin -H "Content-Type: application/json" -d '{"id":13,"createDate":"2020-12-23T07:55:04Z","updateDate":"2020-12-23T07:55:04Z","owner":"rangerusersync","updatedBy":"rangerusersync","name":"atlas","password":"*****","description":"atlas - add from Unix box","groupIdList":[6,59,4,131,133],"groupNameList":["atlas","hadoop","shadow"],"status":0,"isVisible":1,"userSource":1,"userRoleList":["ROLE_USER"],"otherAttributes":"{\"full_name\":\"atlas\",\"original_name\":\"atlas\"}"}' -X PUT https://RANGER_HOST:6182/service/xusers/users
Its little bit big but if user is already added to ranger then run following api to get the id information for users:-
curl -ivk -u admin:admin -H "Accept : application/json" -X GET https://RANGER_HOST:6182/service/xusers/users
Once you have IDs for all users, you can run following curl api to get the json formatted data which you can use to modify and then use PUT method in first API I mentioned:-
curl -ivk -u admin:admin -H "Accept: application/json" -X GET https://RANGER_HOST:6182/service/xusers/users/13
Above Curl api should return something like following:-
{"id":13,"createDate":"2020-12-23T07:55:04Z","updateDate":"2020-12-23T16:45:14Z","owner":"rangerusersync","updatedBy":"admin","name":"atlas","password":"*****","description":"atlas - add from Unix box","groupIdList":[133,6],"groupNameList":["apitest","atlas","hadoop","shadow","ssb"],"status":0,"isVisible":1,"userSource":1,"userRoleList":["ROLE_USER"],"otherAttributes":"{\"full_name\":\"atlas\",\"original_name\":\"atlas\"}"}
you have to modify "groupIdList":[133,6] from the above output copy entire output and pass it with PUT method as shown in the first api call mentioned above.

How to send a curl request to timekit.io API

I am trying to follow the documentation from timekit.io. I am attempting to do something as simple as send a curl request to do basic authentication as seen in this section of the docs. I have replaced the Timekit-App:name-of-app with the name of my app which I found in the app-settings of my timekit account. I also replaced the email & password with the one's I use to login into my account.
I simply copied and pasted the curl command as is into my terminal and I get a response that says {"error":"Content-type should be json!"} I am not sure if I am not supposed to copy and paste it as is, or what I may be doing wrong, but my understanding is I am supposed to get a json response with a email and a api token among some other data.
Here is my curl command.
curl -X POST \
-H 'Timekit-App: jl-fit' \
-d '{
"email": "email#email.com",
"password": "password"
}' \
https://api.timekit.io/v2/auth
Looks like you have discovered a bug in their docs/examples.
The API you're connecting to expects JSON content type, but curl by default (for POSTing data) uses application/x-www-form-urlencoded. You can fix it by adding the header field explicitly with: -H 'Content-Type: application/json'.
Also, when you use the -d/--data option, method defaults to POST, so it doesn't have to be specified explicitly.
All put together, this should work:
curl \
-H 'Content-Type: application/json' \
-H 'Timekit-App: jl-fit' \
-d '{"email": "email#email.com", "password": "password"}' \
"https://api.timekit.io/v2/auth"
When having multiple arguments, it can be convenient to keep them in an array (no need to escape newlines). For example:
args=(
-H 'Content-Type: application/json'
-H 'Timekit-App: jl-fit'
-d '{"email": "email#email.com", "password": "password"}'
"https://api.timekit.io/v2/auth"
)
curl "${args[#]}"

Atlassian Confluence : Updating parent container of an attachment

I'd like to move an attachment to a different space (i.e, update the parent container of an attachment in a Confluence page) using Cloud REST API and "curl" command. I looked up REST API endpoint URL and found this:
PUT /rest/api/content/{id}/child/attachment/{attachmentId}
Could somebody provide an example for a correctly constructed JSON input to achieve this? I tried the one below to move an attachment called "test.jpeg" with ID "att000" and current version 5 to parent with ID 1234, but it fails:
curl -v -u 'admin:password' -X PUT -H 'Content-Type:application/json' -d '{"id":"att000","type":"attachment","title":"test.jpeg","version":{"number":5,"minorEdit":false},"ancestors":[{"id":1234}]' -H ‘X-Atlassian-Token:access-token' https://test.atlassian.net/wiki/rest/api/content/170234/child/attachment | python -m json.tool
Given below is the error message
< HTTP/1.1 415 Unsupported Media Type
.
.
.
No JSON object could be decoded
Thank you for your time!
I believe in your curl example you are uploading it under space which is not possible. Attachments in Confluence needs to be under content. Take a look at following example:
curl -v -S -u admin:admin -X POST -H "X-Atlassian-Token: no-check" -F "file=#myfile.txt" -F "comment=this is my file" "http://localhost:8080/confluence/rest/api/content/3604482/child/attachment" | python -mjson.tool
You have to set the container property in the request object.
Specify "container":{"id":"123456","type":"attachment"}
curl -v -u 'admin:password' -X PUT -H 'Content-Type:application/json' -d '{"id":"att000","type":"attachment","title":"test.jpeg","version":{"number":5,"minorEdit":false},"container":{"id":"123456","type":"attachment"}, "ancestors":[{"id":1234}]' -H ‘X-Atlassian-Token:access-token' https://test.atlassian.net/wiki/rest/api/content/170234/child/attachment | python -m json.tool
id => id of the page where attachment is being moved.

Creating JIRA issue using curl from command line

I've been through documentation here according to which I'm creating a issue for JIRA . I know I'm making some terribly small mistake .
I'm trying to create a new JIRA request from command line (later I'll integrate in my java code)
From my Mac terminal I'm trying to run :
curl -D- -u username:password -X POST --data {"fields":{"project":{"key": “PROJECTKEY"},"summary": "REST ye merry gentlemen.","description": "Creating of an issue using project keys and issue type names using the REST API","issuetype": {"name": "Bug"}}} -H "Content-Type: application/json" https://mycompanyname.atlassian.net/rest/api/2/issue/
I believe this has something to do with the "data".
Thanks in advance. The example has been taken from the documentation link itself.
OUTPUT : I'm getting nothing in my terminal, no error, no expected output .
PROJECTKEY is taken from the KEY column from the All Project list in my DASHBOARD.
Two things are off:
you need to put the data that you want to post in quotes
the first double quote surrounding PROJECT_KEY is a unicode character instead of a regular double quote, so change “PROJECTKEY" to "PROJECTKEY"
This should work:
curl -D- -u username:password -X POST --data '{"fields":{"project":{"key": "PROJECTKEY"},"summary": "REST ye merry gentlemen.","description": "Creating of an issue using project keys and issue type names using the REST API","issuetype": {"name": "Bug"}}}' -H "Content-Type: application/json" https://mycompanyname.atlassian.net/rest/api/2/issue/

Bad request when i try to lock file with Box api (curl method)

I try to lock a file via the API BOX but I encounted issue.
I use the code provided the api documenation (https://developers.box.com/docs/ Lock and Unlock section) but the code does not work.
curl https://api.box.com/2.0/files/xxxxxx\
> -H "Authorization: Bearer xxxxxx" \
> -d "lock": null \
> -X PUT
and the return of the API:
{"type":"error","status":400,"code":"bad_request","context_info":{"errors":[{"reason":"invalid_parameter","name":"entity-body","message":"Invalid value 'lock:'. Entity body should be a correctly nested resource attribute name\/value pair"}]},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Bad Request","request_id":"xxxxxxxxx"}curl: (6) Couldn't resolve host 'null'
I did the test by trying to locke a file : same problem.
Several questions:
Is that the lock function has already work? Do you know if box has
changed its code ?
Any help is welcome :)
Nicolas
I had an answer by Suppor team :
There was a typo in the docs. Please try the command again:
Lock:
curl https://api.box.com/2.0/files/FILE_ID
-H "Authorization: Bearer ACCESS_TOKEN"
-d '{"lock": {"type": "lock","expires_at": "2015-12-12T10:55:30-08:00","is_download_prevented": false}}'
-X PUT
Unlock:
curl https://api.box.com/2.0/files/FILE_ID
-H "Authorization: Bearer ACCESS_TOKEN"
-d '{"lock": null}'
-X PUT
https://support.box.com/hc/fr/requests/793456?flash_digest=c5350d2f104f3066b46cb83baa97c23dac863d2b