Error when calling the Anomaly Detection API - microsoft-cognitive

I've been messing with the Anomaly Detection API as part of the Microsoft Cognitive Services Labs. However, when I try to POST data to get a response, it always comes back as
400: TypeError('string indices must be integers'
Thinking this is an issue with the format of the data I'm giving it, I double check it with what they have as a sample:
{
"Period": 7,
"Points": [
{
"Timestamp": "2018-03-01T00:00:00Z",
"Value": 32858923
},
{
"Timestamp": "2018-03-02T00:00:00Z",
"Value": 29615278
},
{
"Timestamp": "2018-03-03T00:00:00Z",
"Value": 22839355
},
]
}
And here is some of the data that I'm sending to it that returns the error:
{
"Period": 1,
"Points":[
{
"Timestamp": "1962-01-01T00:00:00Z",
"Value": 589
},
{
"Timestamp": "1962-02-01T00:00:00Z",
"Value": 561
},
{
"Timestamp": "1962-03-01T00:00:00Z",
"Value": 640
}
]
}
Using Python to call the API with the requests package:
request = json.dumps(output)
config = json.load(open("config.json"))
url = "https://api.labs.cognitive.microsoft.com/anomalyfinder/v1.0/anomalydetection"
headers = {"Ocp-Apim-Subscription-Key": config["apiKey"]}
response = requests.post(url, headers=headers, json=request)
The output object is a dictionary that looks like this:
{'Period': 1,
'Points': [{'Timestamp': '1962-01-01T00:00:00Z', 'Value': 589},
{'Timestamp': '1962-02-01T00:00:00Z', 'Value': 561},
{'Timestamp': '1962-03-01T00:00:00Z', 'Value': 640}]}
Which was derived from the monthly milk production data set.
Is there something wrong with my data that I'm missing to cause it to return back that error?

Related

Sending a request to /adCreativesV2 entity doesn't return all the fields

We are in the process of designing a custom build report for our client and have recently stumbled upon a behavior which we could not puzzle. Basically, we are not getting returned the following fields
ad_creative_name
ad_creative_text
ad_creative_title
when sending a GET request as follows:
https://api.linkedin.com/v2/adCreativesV2/136236994?projection=(*,reference~(*))
We're getting a 200 OK response as per below:
"variables": {
"data": {
"com.linkedin.ads.SponsoredInMailCreativeVariables": {
"content": "urn:li:adInMailContent:5139314"
}
}
},
"test": false,
"servingStatuses": [
"RUNNABLE"
],
"type": "SPONSORED_INMAILS",
"version": {
"versionTag": "6"
},
"reference": "urn:li:adInMailContent:5139314",
"changeAuditStamps": {
"lastModified": {
"time": 1624098658000
},
"created": {
"time": 1624035613000
}
},
"review": {
"reviewStatus": "APPROVED"
},
"campaign": "urn:li:sponsoredCampaign:179783044",
"reference!": {
"message": "Unsupported URN domain: li:adInMailContent",
"status": 501
},
"id": 136236994,
"status": "ACTIVE"
}
From the response, you may also notice that we are also getting this warning
"message": "Unsupported URN domain: li:adInMailContent",
"status": 501
We've tried different API requests variations, including specifying different creatives that are active, but to no avail. Also, we were not able to find any info regarding the error above, so we are uncertain what might be causing it.
Thanks!

Not able to retrieve results from Open TSDB via HTTP

I have set up open TSDB using docker image. I am able to push data to database via HTTP post request.
[{
"metric": "sys.cpu.nice",
"timestamp": 1567764102,
"value": 18,
"tags": {
"host": "web01",
"dc": "lga"
}
},
{
"metric": "sys.cpu.abc",
"timestamp": 1567764602,
"value": 9,
"tags": {
"host": "web02",
"dc": "lga"
}
}
]
Same data is also visible on the portal but I want to retrieve this data form TSDB by API.
I used this but it's not returning actual data.
http://localhost:4242/api/search/lookup?m=sys.cpu.nice{host=*}
{
"type": "LOOKUP",
"metric": "sys.cpu.nice",
"tags": [{
"key": "host",
"value": "*"
}],
"limit": 25,
"time": 6.0,
"results": [],
"startIndex": 0,
"totalResults": 0
}
Could you please help to get data back from the database. I need to send this data to some other system.
Try using the /api/query endpoint
In your case you could try one of the following GET requests:
http://localhost:4242/api/query?m=sum:cmp.sys.db{host=server01,tenant01}&start=1h-ago
http://localhost:4242/api/query?m=zimsum:cmp.sys.db{host=server01,tenant01}&start=1h-ago

Making a POST call in R

I have a rest API to which I want to make a POST call.
The API is
"http://swift-rand-8888a.stg.corp.dummy.com/random/filter"
It doesn't need an Auth parameter.
The payload I am trying to send is:
Payload: { "name": "Filter_1533141396310", "shortName": "LHF",
"filterType": "==", "value": {
"name": "completed",
"defaultValue": "completed" }, "attribute": {
"vName": "status",
"vType": "LOCAL" }, "transformerDependency": "", "createdBy": "Aman" }
Header should be {Content-Type=[application/json]}
I am always getting "bad request error".
My code looks like:
dummy<-"Payload: {'name': 'Filter_1533141396310','shortName': 'LHF','filterType': '==','value': {'name': 'completed','defaultValue': 'completed'},'attribute': {'vName': 'status','vType': 'LOCAL'},'transformerDependency': '','createdBy': 'Prateek'}"
result <- POST("http://swift-rand-8888a.stg.corp.dummy.com/random/filter",
body = dummy,
add_headers("Content-Type=[application/json]"))
Output <- content(result)
Can someone help me with my mistake?

Google Cloud Endpoints: Transcoding messages with protobuf.Any fields

I have a grpc service that takes as input a message that contains fields of type protobuf.Any and I can't figure out the way to write correct json input for it. I am running on GKE, with cloud endpoint ESP and my service running in the same pod.
The protos look like:
message AnyArray {
repeated google.protobuf.Any value = 1;
}
message Metric {
string metric = 1;
int64 timestamp = 2;
double value = 3;
map<string, AnyArray> metadata = 4;
}
I have tried multiple combinations for the input json with no luck, most of the times cloud endpoints returns "Proto field is not repeating, cannot start list." Failed examples:
{
"metadata": {
"sample-key": {
"value": [1, "one"]
}
},
"metric": "request-count",
"timestamp": 1528425789,
"value": 0
}
{
"metadata": {
"sample-key": {
"value": [{
"#type": "type.googleapis.com/google.protobuf.Duration",
"value": "1.212s"
}, {
"#type": "type.googleapis.com/google.protobuf.Duration",
"value": "1.212s"
}]
}
},
"metric": "request-count",
"timestamp": 1528425789,
"value": 0
}
Response from ESP
{
"code": 3,
"message": "metadata[0].value: Proto field is not repeating, cannot start list.",
"details": [{
"#type": "type.googleapis.com/google.rpc.DebugInfo",
"stackEntries": [],
"detail": "internal"
}]
}
Any help would be greatly appreciated.
Thanks!
google.protobuf.Any means any proto message type so your first example doesn't work. For the second example, google.protobuf.Duration have a special JSON mapping, so following example should work:
{
"metadata": {
"sample-key": {
"value": [{
"#type": "type.googleapis.com/google.protobuf.Duration",
"value": "1.212s"
}, {
"#type": "type.googleapis.com/google.protobuf.Duration",
"value": "1.212s"
}]
}
},
"metric": "request-count",
"timestamp": 1528425789,
"value": 0
}
Note you will have to include all possible proto message types for the google.protobuf.Any in the proto descriptor set provided Cloud Endpoints service, otherwise it will fail to translate unknown types.
Another possible approach is use google.protobuf.Struct for your metadata, which eliminates the limitation above, but you will have to convert it to your expected types in your gRPC service.
Using protobuf.Struct instead of protobuf.Any solved my problem as #lizan recommended. Thanks!

Google Analytics Reporting API V4 Lifetime value requests - invalid dimensions/metrics

I'm trying to make calls the Analytics Reporting API V4 and keep getting back unspecific error messages when trying to use certain dimensions and metrics. For example, I consistently get
{
"error": {
"code": 400,
"message": "Unknown dimension(s): ga:acquisitionTrafficChannel",
"status": "INVALID_ARGUMENT"
}
}
when passing ga:acquisitionTrafficChannel, despite it being documented as a valid dimension. Similarly, I get
{
"error": {
"code": 400,
"message": "Selected dimensions and metrics cannot be queried together.",
"status": "INVALID_ARGUMENT"
}
}
when passing ga:acquisitionSourceMedium (documented here), even when not passing any metrics whatsoever.
Are the docs out of date? Is there some documentation elsewhere about valid combinations of dimensions and metrics?
All the Lifetime Value reports and thus ga:acquisition... dimensions are only valid for App views not web views.
Secondly the cohort/LTV dimensions can only be queried in within a cohort requests for example:
POST https://analyticsreporting.googleapis.com/v4/reports:batchGet
{
"reportRequests": [
{
"viewId": "XXXX",
"dimensions": [
{
"name": "ga:cohort"
},
{
"name": "ga:acquisitionTrafficChannel"
}
],
"metrics": [
{
"expression": "ga:cohortSessionsPerUser"
}
],
"cohortGroup": {
"cohorts": [
{
"name": "cohort 1",
"type": "FIRST_VISIT_DATE",
"dateRange": {
"startDate": "2015-08-01",
"endDate": "2015-09-01"
}
},
{
"name": "cohort 2",
"type": "FIRST_VISIT_DATE",
"dateRange": {
"startDate": "2015-07-01",
"endDate": "2015-08-01"
}
}
],
"lifetimeValue": true
}
}
]
}
The error messages should probably be a bit clearer.
I ran into this problem as well. When I was in the Google Analytics Dashboard, I clicked on Acquisition->All Traffic->Channels and was fooled into thinking that I needed to combine the ga:acquisitionMedium dimension and ga:newUsers metric together.
When I clicked on ga:acquisitionMedium, it said that combining it with ga:newUsers was valid, despite the error that you mentioned in your question! In reality, I just needed to combine ga:medium and ga:newUsers together.
I know this is not the exact query that you were doing, but here is an example of how I queried New Users count where the dimension channel equaled "organic" (note that I am forming the JSON request with Javascript and then using JSON.stringify(req) to send it):
var req = {
reportRequests: [{
viewId: '<Your Google Analytics view ID>',
dimensions: [{ name: 'ga:medium' }],
dimensionFilterClauses: [{
filters: [{
dimensionName: 'ga:medium',
operator: 'EXACT',
expressions: ['organic']
}]
}],
dateRanges: [{ startDate: '2019-11-01', endDate: '2019-11-30' }],
metrics: [{ expression: "ga:newUsers" }]
}]
};
The above query returns 5,654, which is the same as seen in the "Acquisition" section of Google Analytics.
I definitely think the documentation and error message around this could be improved.

Resources