"Resource Not Found" message received when sending a query to Keen IO API - rest

I am using Advanced REST Client tool to test a data pull from the Keen IO API, and think getting the request right, but not getting the data. Getting "resource not found" error. This can also be done via CURL.
Headers: Authorization:
Content-Type: application/json
actual request: GET /3.0/projects//queries/saved/Sponsorships/result HTTP/1.1
HOST: api.keen.io
authorization:
content-type: application/json
Base URL used: https://api.keen.io
Any ideas as to what may be doing wrong?

The saved query name is capitalized "Sponsorships". Make sure your saved query name is lower-cased, not camel or title-cased. To be sure that you are getting the correct saved query name.
Also, you may want to first obtain a list of all saved queries as a reference:
GET /3.0/projects/<project_name>/queries/saved HTTP/1.1
HOST: api.keen.io
authorization: <your_key>
content-type: application/json
You will get something like this:
[
{
"refresh_rate": 0,
"last_modified_date": "2016-12-20T01:09:54.355000+00:00",
"query_name": "",
"created_date": "2016-12-20T01:09:54.355000+00:00",
"query": {
"filters": [],
"latest": 100,
"analysis_type": "extraction",
"timezone": "UTC",
"timeframe": "this_30_days",
"event_collection": ""
},
"metadata": {
"visualization": {
"chart_type": "table"
},
"display_name": ""
},
"run_information": null
}
]

FWIW, I also have seen the "Resource not found" error when writing data to an event if the project is not correctly set up. For example, passing in the wrong project_id or write_key or if the project was deleted from your Keen.io account.

Related

How to send Query Params in Get Request in Robot Framework?

I am new to Robot Framework and am facing an issue while sending query params in Get Request method.
Following is the code that I tried with no luck :
Get Data With Filter
[Arguments] ${type} ${filter}
${auth} = Create List ${user_name} ${password}
${params} = Create Dictionary type=${type} filter=${filter}
Create Session testingapi url=${some_host_name} auth=${auth}
${resp} = Get Request testingapi /foo/data params=${params}
Log ${resp}
${type} has value new and ${filter} that I want is id:"1234"
I am expecting final url to formed as :
/foo/data?type=new&filter=id%3A1234
Instead of forming the expected url, I get the request url as :
GET Request using : uri=/foo/data, params={'type': 'new', 'filter': 'id:1234'}
I might be missing something very obvious but I cant figure out what it is. What can I change in this piece of code or any new code that needs to be added?
I think the logger is just outputting the params as the dictionary. The request should actually be made to foo/data?type=new&filter=id%3A1234
You can test it with the following request to Postman Echo (An HTTP testing service):
${auth} = Create List Mark SuperSecret
${params} = Create Dictionary type=Condos filter=2Bedrooms
Create Session testingapi url=http://postman-echo.com auth=${auth}
${resp} = Get Request testingapi /get params=${params}
${json} = To JSON ${resp.content} pretty_print=True
Log \n${json} console=yes
The response will correctly list the params you've encoded:
{
"args": {
"filter": "2Bedrooms",
"type": "Condos"
},
"headers": {
"accept": "*/*",
"accept-encoding": "gzip, deflate",
"authorization": "Basic TWFyazpTdXBlclNlY3JldA==",
"host": "postman-echo.com",
"user-agent": "python-requests/2.25.0",
"x-amzn-trace-id": "Root=1-5fb43ae9-1880b0a621c864b06ce1f54a",
"x-forwarded-port": "80",
"x-forwarded-proto": "http"
},
"url": "http://postman-echo.com/get?type=Condos&filter=2Bedrooms"
}

Keycloak RestAPI: Assign client role to group

I have trying this:
url="https://{localhost}/auth/admin/realms/{realm_name}/groups/{group_id}/role-mappings"
payload=[{"id":"role_id","name":"Role_name","composite":"false","clientRole":"true","containerId":"client_id"}]
But, it doesnt work, i think it may be related to the wrong payload
Any ideas pls
We can use the python-keycloak lib: https://pypi.org/project/python-keycloak/
there is a function: assign_group_client_roles
The format is correct but you make sure the client has available payloaded role.
This is example for, "Hr" group added "RomoteApp" client the "tile limit" role.
In Keycloak UI, # Client > RemoteApp > Roles
Role name
time limit
Groups > hr
Client Roles: RemoteApp
Available Roles: time limit
Assigned Roles: not yet include "time limit"
POST commend by Postman - I am not yet can attache image due to low level of stan overflow
http://127.0.0.1:8080/auth/admin/realms/Test-realm/groups/9efef6bf-7edb-496e-bc0d-a8d4f5f4e3a9/role-mappings/clients/60a19179-f244-42f8-9950-04f2119a4e5b?client=RemoteApp&id=60a19179-f244-42f8-9950-04f2119a4e5b&realm=Test-realm
in body of postman with row JSON option ( Content-Type : application/json )
[
{
"id": "e17f9f7f-62dc-4998-b058-49b845ff5cef",
"name": "time limit",
"description": "time limit",
"composite": false,
"clientRole": true,
"containerId": "60a19179-f244-42f8-9950-04f2119a4e5b"
}
]
group list
{
"id": "9efef6bf-7edb-496e-bc0d-a8d4f5f4e3a9",
"name": "hr",
"path": "/hr",
"subGroups": []
}
client list
{
"id": "60a19179-f244-42f8-9950-04f2119a4e5b",
"clientId": "RemoteApp",
...
}
also don't remember the access token called by token endpoint w/ grant_type is password
http://127.0.0.1:8080/auth/realms/Test-realm/protocol/openid-connect/token

API request does not authenticate

Using this documentation I'm trying to test the request using Postman the example on the right side:
$ curl https://subscriptions.zoho.com/api/v1/organizations
-H 'Authorization: Zoho-oauthtoken 1000.41d9f2cfbd1b7a8f9e314b7aff7bc2d1.8fcc9810810a216793f385b9dd6e125f'
-H 'X-com-zoho-subscriptions-organizationid: 10234695'
Maybe I'm not setting the parameters right but this is how it looks for the moment.
A new GET Request, in the url input: https://subscriptions.zoho.com/api/v1/organizations
And under that, in the Headers tab I added two key-value pairs:
Authorization: Zoho-oauthtoken 1000.41d9f2cfbd1b7a8f9e314b7aff7bc2d1.8fcc9810810a216793f385b9dd6e125f
Authorization: X-com-zoho-subscriptions-organizationid: 1023469
The returned result:
<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
</body>
</html>
If I deleted the second key-value pair it returns this JSON:
{
"code": 57,
"message": "You are not authorized to perform this operation"
}
What is wrong with my approach?
Can you try this?
If you are sure of the api url, do validate the token and create a fresh token and
add it to header as below:
HeaderName : Authorization
HeaderValue: 1000.41d9f2cfbd1b7a8f9e314b7aff7bc2d1.8fcc9810810a216793f385b9dd6e125f
HeaderName : X-com-zoho-subscriptions-organizationid
HeaderValue: 10234695
I tried this and is getting,
{
"code": 14,
"message": "Invalid value passed for authtoken."
}
Might be the token got invalid.
Now I tried with a new token generated myself and I am getting now,
{
"code": 0,
"message": "success",
"organizations": [],
}
In short, you have to generate an auth token first and then hit the url with proper header value as shown above.
Thank you :)

Adding document in Couchbase and missing JSON body

I am trying to use Couchbase REST API to add a document to the existing documents. I am just testing this in Postman while writing on the code.
POST:
http://<ip>:8091/pools/default/buckets/<bucketname>/docs/testdoc1?rev=1
Headers:
Accept: application/json
Authorization : xxxxx
Body:
Raw JSON (application/json)
{
"Name": "xxx",
"Address": "yyy",
"Phone number": "xxxx",
"Badge": "yyy",
"BadgeType": "xxx"
}
When I send above in Postman, It is adding this new doc. under couchbase documents/bucket, but on the body field it shows like, "Binary Document, base64 not available"
I tried even from my html code, but json body didn't receive at couchbase end.
<!DOCTYPE html>
<html>
<body>
<input type="submit" value="Start" onclick="submit()">
<script type="text/javascript">
var params = {
"Name": "xxx",
"Address": "yyy",
"Phone number": "xxxx",
"Badge": "yyy",
"BadgeType": "xxx"
}
function submit() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
alert(xhr.response);
}
}
xhr.open('post', 'http://<ip>:8091/pools/default/buckets/<buckname>/docs/testdochtml?rev=1', true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('Accept', 'application/json');
xhr.setRequestHeader('Authorization', 'Basic ' + 'xxxxxxx');
xhr.send(JSON.stringify(params));
}
</script>
<p>Click on the submit button.</p>
</body>
</html>
Can someone guide me why is that JSON not going to couchbase in a correct way?
First off: as far as I know, this endpoint is not supported and it is not documented. If you see somewhere that it is supported, let me know, because I think that needs corrected. You should use one of the SDKs (Java, .NET, Node, etc) instead.
That being said, I was able to get it working via Postman. You can't just send raw JSON as the document. You need to POST encoded form data. One of the values this endpoint expects is "value", which contains the encoded JSON document.
Here's an example of what I did (I called my bucket "so"):
POST /pools/default/buckets/so/docs/testdoc2 HTTP/1.1
Host: localhost
cache-control: no-cache
Postman-Token: ba87ef4e-4bba-42b4-84da-ae775b26dbcb
value=%7B%0A%09%22Name%22%3A+%22xxx%22%2C%0A%09%22Address%22%3A+%22yyy%22%2C%0A%09%22Phone+number%22%3A+%22xxxx%22%2C%0A%09%22Badge%22%3A+%22yyy%22%2C%0A%09%22BadgeType%22%3A+%22xxx%22%0A%7D%0A
Note that value above is just the URL-encoded JSON from your question (Postman encoded it for me, and Postman must have added the cache-control header on its own too, because I did not specify that):

Wiremock bodyFileName templating

I'm using Wiremock to stub out some API calls made by mobile clients.
Struggling to get templated filename from request.
Can anyone confirm if this should even work with Wiremock standalone pls?
"response": { "status": 200, "bodyFileName": "Account-{{jsonPath request.body '$.user.identity'}}.json”}
I've got static files to be returned fine, just seems like bodyFileName doesn't like templating.
Example:
I configure wm with following Json:
{
"request": {
"method" : "GET",
"url": "/users/D8428899330"
},
"response": {
"status": 200,
"bodyFileName": "user-{{request.path.[1]}}.json"
}
}
Then when I attempt the url, http://localhost:9696/users/D8428899330 I get the following error,
HTTP ERROR: 500 Problem accessing /users/D8428899330. Reason:
java.lang.RuntimeException: java.io.FileNotFoundException:
/Users/iainframe/Documents/__files/user-{{request.path.[1]}}.json (No
such file or directory)
Should indicate that the file user-D8428899330.json resides in the correct location as I've hard coded it and it returns it ok. The command to start WireMock is:
java -jar ~/Documents/wm.jar --port 9696 --global-response-templating --verbose --root-dir /Users/iainframe/Documents/
The following response definition works fine for me with Wiremock 2.25.1 using the response template transformer.
"response": {
"transformers": ["response-template"],
"status": 200,
"bodyFileName": "user-{{jsonPath request.body '$.userid'}}.json" }
and this also works fine:
"response": {
"transformers": ["response-template"],
"status": 200,
"bodyFileName": "user-{{request.path.[3]}}.json" }
Interesting, I was running into the same problem and was able to solve it by starting WireMock with --global-response-templating. But you are using that parameter too... If it matters, I'm using WireMock 2.33.2.