Generating Historical Metrics in Google Ads - google-ads-api

According to the documentation To generate historical metrics: Create a KeywordPlan, KeywordPlanCampaigns, KeywordPlanAdGroups, KeywordPlanCampaignKeywords, and KeywordPlanAdGroupKeywords. Call KeywordPlanService.GenerateHistoricalMetrics with that keyword plan.
These plans come out as a 4-element, slash-delimited string, e.g. customers/1879809528/keywordPlanCampaigns/413340892. However, after modifying the sample code to call GenerateHistoricalMetrics I find that the API at that point expects a long, the KeywordPlanId.
Is this number the 4th item in the plan string? Apparently not, as this slice out of the trace logs indicates:
...
Response
--------
Headers: {
"content-disposition": "attachment",
"request-id": "ahE6lqAnzToj3H65rHtHbA",
"date": "Mon, 30 May 2022 06:39:19 GMT",
"alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\""
}
{ "results": [ { "resourceName": "customers/1879809528/keywordPlanCampaigns/413340892" } ] }
...
Response
--------
...
Fault: {
"StatusCode": 3,
"Details": "Request contains an invalid argument.",
"RequestId": "mMZTztmu4ufHpgJ77xph9Q",
"Failure": {
"errors": [
{
"errorCode": {
"keywordPlanError": "KEYWORD_PLAN_NOT_FOUND"
},
"message": "No plan with planId[413340892] exists"
}
],
"requestId": "mMZTztmu4ufHpgJ77xph9Q"
}
}
So how does one get from plan to metrics?

Looks like you are passing the wrong resource_name,
It should be resource_name of keywordPlan.
Example: 'customers/xxx/keywordPlans/590630346'

Related

Serilog expression to exclude http 200 and http 302?

I'm using serilog and it's nicely logging http requests to my asp.net core web application.
However I want to filter out the noise of http 200 and http 302 (basically only interested in 5xx and 4xx).
I've tried a lot of variations on the following:
... snip ...
"Using": [ "Serilog.Expressions" ],
"Filter": [
{
"Name": "ByExcluding",
"Args": {
"expression": "#l = 'Information' and Properties.StatusCode in ['200', '302']"
}
}
],
... snip ...
But to no success.
The LogEvent properties looks like (:
{
"TimeStamp": "2021-12-09T09:00:18.1586954",
"Level": "Information",
"Message": "HTTP \"GET\" \"/xxx/yyy\" responded 200 in 50.2048 ms",
"MessageTemplate": "HTTP {RequestMethod} {RequestPath} responded {StatusCode} in {Elapsed:0.0000} ms",
"Properties": {
"RequestMethod": "GET",
"RequestPath": "/xxx/yyy",
"StatusCode": 200,
"Elapsed": 50.2048,
"SourceContext": "Serilog.AspNetCore.RequestLoggingMiddleware",
"RequestId": "8000050f-0006-eb00-b63f-84710c7967bb"
},
"Renderings": {
"Elapsed": [
{
"Format": "0.0000",
"Rendering": "50.2048"
}
]
}
}
Serilog is paying attention if I use a filter like "#l = 'Information'", but any attempt to filter based upon LogEvent properties does not work.
Any help would be appreciated!
Serilog.Expressions doesn't require dotting through a Properties subobject: all of the event's properties are top-level names.
StatusCode is also a number, not a string, so you don't need quotes within the array of status code values to exclude.
Your expression should look like:
#l = 'Information' and StatusCode in [200, 302]

Hasura query action exception

Got a small problem (I guess). I created c# rest web API on docker swarm environment. Rest API is working properly - tested via the postman. Then I tried to compose Hasura service on the same docker swarm environment. The console is working properly also. The problem is with query action.
Code:
Action definition:
type Query {
getWeatherForecast : [WeatherForecastResonse]
}
New types definition:
type WeatherForecastResonse {
date : String
temperatureC : Int
temperature : Int
summary : String
}
Handler:
http://{api ip}:{api port}/WeatherForecast
While trying to execute query:
query MyQuery {
getWeatherForecast {
temperature
summary
date
temperatureC
}
}
All I got from response is error with json:
{
"errors": [
{
"extensions": {
"internal": {
"error": "invalid json: Error in $: not enough input",
"response": {
"status": 405,
"body": "",
"headers": [
{
"value": "Mon, 14 Jun 2021 13:54:00 GMT",
"name": "Date"
},
{
"value": "Kestrel",
"name": "Server"
},
{
"value": "0",
"name": "Content-Length"
},
{
"value": "GET",
"name": "Allow"
}
]
},
"request": {
"body": {
"session_variables": {
"x-hasura-role": "admin"
},
"input": {},
"action": {
"name": "getWeatherForecast"
}
},
"url": "http://{api ip}:{api port}/WeatherForecast",
"headers": []
}
},
"path": "$",
"code": "unexpected"
},
"message": "not a valid json response from webhook"
}
]
}
I got desired response by using postman white calling: http://{api ip}:{api port}/WeatherForecast (GET method)
Where should I improve, to finally get desired result from rest api?
P.S. hasura version: v2.0.0-alpha.4 (tried also with v1.3.3)
UPDATE:
Released a new version of web API. Inside WeatherForecastController included a new method with POST attribute. Query remained the same, but now graphql query returns what I want.
So the question is: Is it possible to call/access web api methods with GET attribute with Hasura action query?
From the version v2.1.0 and above we can do this using the REST Connectors.Hasura Actions RESTConnectors Methods
Go to the Actions tab on the console and create or modify an action. Scroll down to Configure REST Connectors.
In the Configure REST Connectors section, click on Add Request Options Transform
Along with this you can do a lot of other configurations.
No, currently it's not possible, Hasura always makes POST requests to the action handler:
When the action is executed i.e. when the query or the mutation is called, Hasura makes a POST request to the handler with the action arguments and the session variables.
Source: https://hasura.io/docs/latest/graphql/core/actions/action-handlers.html#http-handler

Microsoft Graph returns "Internal Server Error" on request?

I am trying to get my Microsoft Teams assignments through Microsoft Graph. I submit this GET request https://graph.microsoft.com/beta/education/me/classes/{id}/assignments as shown in the docs, with my authentication token as a header. However, below is the reply I get. I am doing this with python, however I have also tried from Graph Explorer which yields the same result.
{
"error": {
"code": "InternalServerError",
"message": "Object reference not set to an instance of an object.",
"innerError": {
"date": "2020-09-07T16:44:48",
"request-id": "011086a0-9240-4896-9363-d403a1a0fb05"
}
}
}
Does anybody have any insight? Is this a problem with Microsoft?
You need to remove the /me. The correct URI is https://graph.microsoft.com/beta/education/classes/{id}/assignments.
From the documentation
POST https://graph.microsoft.com/beta/education/classes/11019/assignments
Content-type: application/json
Content-length: 279
{
"dueDateTime": "2014-02-01T00:00:00Z",
"displayName": "Midterm 1",
"instructions": {
"contentType": "text",
"content": "Read chapters 1 through 3"
},
"grading": {
"#odata.type": "#microsoft.education.assignments.api.educationAssignmentPointsGradeType",
"maxPoints": 100
},
"assignTo": {
"#odata.type": "#microsoft.education.assignments.api.educationAssignmentClassRecipient"
},
"status":"draft",
"allowStudentsToAddResourcesToSubmission": true
}

Schema Extensions : "Unsupported or invalid query filter clause specified for property 'companyName' of resource 'User'."

I'm currently building an application that requires me to retrieve users from the Graph API depending of a custom property, in that case, extoe82ql2v_test/companyName but so far, the API responded with Unsupported or invalid query filter clause specified for property 'companyName' of resource 'User'."
The request to retrieve the extension :
https://graph.microsoft.com/v1.0/schemaExtensions?$filter=id eq 'extoe82ql2v_test'
The result :
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#schemaExtensions",
"value": [
{
"id": "extoe82ql2v_test",
"description": "Extend data for users",
"targetTypes": [
"User"
],
"status": "InDevelopment",
"owner": "d9a847ce-ca03-4779-88d6-c7e4f98297fe",
"properties": [
{
"name": "companyName",
"type": "String"
},
{
"name": "managerMail",
"type": "String"
},
{
"name": "arrivalDate",
"type": "DateTime"
},
{
"name": "expiryDate",
"type": "DateTime"
}
]
}
]
}
The request to retrieve the users depending of extoe82ql2v_test/companyName :
https://graph.microsoft.com/v1.0/users?$select=extoe82ql2v_test,givenName,surname,mail,mobilePhone,department,companyName,accountEnabled&$filter=extoe82ql2v_test/companyName eq 'test'
The result :
{
"error": {
"code": "Request_UnsupportedQuery",
"message": "Unsupported or invalid query filter clause specified for property 'companyName' of resource 'User'.",
"innerError": {
"date": "2020-07-24T20:46:51",
"request-id": "639b8131-70dd-4436-b624-88167fe105eb"
}
}
}
The same query with the Microsoft Graph .NET SDK :
var res = await _graphClient.Users.Request()
.Select($"extoe82ql2v_test,givenName,surname,mail,mobilePhone,department,companyName,accountEnabled")
.Filter($"extoe82ql2v_test/companyName eq 'test'").GetAsync()
I don't understand what the issue is as I followed what the official documentation said about filtering custom properties
Any help is greatly appreciated
Edit : Here is how $select without a $filter looks like
Request :
https://graph.microsoft.com/v1.0/users?$select=givenName,surname,mail,mobilePhone,department,companyName,accountEnabled,extoe82ql2v_test
Response :
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(givenName,surname,mail,mobilePhone,department,companyName,accountEnabled,extoe82ql2v_test)",
"value": [
{
"givenName": "Antoine",
"surname": "D",
"mail": "antoine.d#contoso.com",
"mobilePhone": null,
"department": null,
"companyName": null,
"accountEnabled": true,
"extoe82ql2v_test": {
"#odata.type": "#microsoft.graph.ComplexExtensionValue",
"expiryDate": "2020-12-31T00:00:00Z",
"arrivalDate": "2020-07-22T00:00:00Z",
"managerMail": "antoine.d#contoso.com",
"companyName": "test"
}
}
]
}
Edit 2:
I successfully filtered the users with another custom attributes, extoe82ql2v_test/managerMail, it's progress but I still need to apply a filter on extoe82ql2v_test/companyName and make it works
Edit 3:
Filtering on extoe82ql2v_test/expiryDate and extoe82ql2v_test/arrivalDate also works, both of these attributes are useless to filter but at least I know they work. As for extoe82ql2v_test/companyName, I wonder if it is because this attribute exists in both the schema extensions and the User Graph object ?
I just faced the same problem and made it work by adding "$count=true" in the query parameters.
I also noticed it seems to need ConsistencyLevel=eventual in the request header.
For example:
https://graph.microsoft.com/v1.0/users?$filter=CompanyName eq 'xxxx'&$select=id,displayName,CompanyName
Bad Request - 400 - 146ms
{
"error": {
"code": "Request_UnsupportedQuery",
"message": "Unsupported or invalid query filter clause specified for property 'companyName' of resource 'User'.",
...
}
https://graph.microsoft.com/v1.0/users?$count=true&$filter=CompanyName eq 'xxxx'&$select=id,displayName,CompanyName (with header ConsistencyLevel=eventual)
OK - 200 - 404ms
\o/
(I got the hint by looking at this question Microsoft Graph API cannot filter /users by companyName?)

microsoft graph api assign license giving error

I am trying to assign license to a user with Office 365 business premium skuid but getting following error.
Request body:
{
"addLicenses": [
{
"skuId": "skuid"
}
],
"removeLicenses": []
}
Response
{
"error": {
"code": "Request_BadRequest",
"message": "Another object with the same value for property proxyAddresses already exists.",
"innerError": {
"request-id": "b94663b1-f58f-4e30-a457-3db66a0f0b51",
"date": "2020-03-13T11:22:35"
},
"details": [
{
"target": "proxyAddresses",
"code": "ObjectConflict"
}
]
}
}
But the user whom I am assigning license is unique.
Any help is much appreciated.
I can reproduce your issue via the following steps:
I already have a user account: allen3#tenant.onmicrosoft.com. It has an alias (proxyAddress): allenwu#tenant.onmicrosoft.com.
Now I create a new account through Microsoft Graph API with allenwu#tenant.onmicrosoft.com as the userPrincipalName.
POST https://graph.microsoft.com/v1.0/users
Content-type: application/json
{
"accountEnabled": true,
"displayName": "allent3",
"mailNickname": "allent3",
"userPrincipalName": "allenwu#tenant.onmicrosoft.com",
"passwordProfile" : {
"forceChangePasswordNextSignIn": false,
"password": "password-value"
}
}
The magic happened: the account was created successfully!
But when I assign license to the account allenwu#tenant.onmicrosoft.com with Microsoft Graph API, it gives me the same error as yours.
So I think this error prompt is reasonable. (Although it is unreasonable for the account to be created successfully.)
Please check if your tenant has the same problem as me. Hope it's helpful.

Resources