GCP stackdriver enteries list pagination issue - google-cloud-platform

i am sending the followin request for enteries list API ,here is the link to API
https://cloud.google.com/logging/docs/reference/v2/rest/v2/entries/list
{
"filter": "(jsonPayload.event_type=\"GCE_OPERATION_DONE\" OR protoPayload.serviceName=\"storage.googleapis.com\" OR protoPayload.serviceName=\"clientauthconfig.googleapis.com\" OR protoPayload.serviceName=\"iam.googleapis.com\" OR protoPayload.serviceName=\"compute.googleapis.com\") AND (jsonPayload.event_subtype=\"compute.instances.insert\" OR jsonPayload.event_subtype=\"compute.instances.delete\" OR protoPayload.methodName=\"storage.buckets.create\" OR protoPayload.methodName=\"storage.buckets.delete\" AND protoPayload.resourceOriginalState.direction=\"EGRESS\" AND protoPayload.request.disabled=true)) AND timestamp>=\"2020-05-16T12:52:00.820Z\" AND timestamp < \"2020-05-16T13:52:00.820Z\"",
"resourceNames": [
"projects/project1"
],
"orderBy": "timestamp desc",
"pageSize": 1000,
"pageToken":xxxx"
}
I am getting the following respone
{
"error": {
"code": 400,
"message": "page_token doesn't match arguments from the request",
"status": "INVALID_ARGUMENT"
}
}
Can anyone Suggest what does message imply with an example

this error is faced when,
the page token of some other project is being used in place of project1

Try to test the API using following format for the requested body and also try without any parameters.
{
"projectIds": [
string
],
"resourceNames": [
string
],
"filter": string,
"orderBy": string,
"pageSize": integer,
"pageToken": string
}

Related

Cannot find the EntityType - SessionEntityType name is composed of Session name and EntityType.display_name

Even though I have provided the correct information in the SessionEntityTypes, the I am getting the following errors. Tried from both REST & Python options, please let me know if there is anything which I am missing in the integrations.
Request
HTTP Method: POST
{
"name": "projects/{projectId}/locations/asia-northeast1/agent/environments/draft/users/-/sessions/c973fe-e44-9b5-34e-b404439b7/entityTypes/speciality_types",
"entities": [
{
"value": "APPLE_KEY",
"synonyms": [
"apple",
"green apple",
"crabapple"
]
},
{
"value": "ORANGE_KEY",
"synonyms": [
"orange"
]
}
],
"entityOverrideMode": "ENTITY_OVERRIDE_MODE_SUPPLEMENT"
}
Response
{
"error": {
"code": 400,
"message": "com.google.apps.framework.request.BadRequestException: Cannot find the EntityType of SessionEntityType 'projects/{projectId}/locations/asia-northeast1/agent/environments/draft/users/-/sessions/c973fe-e44-9b5-34e-b404439b7/entityTypes/speciality_types'. Please note that the SessionEntityType name is composed of Session name and EntityType.display_name.",
"status": "INVALID_ARGUMENT"
}
}
Google Try this API
I am going to paraphrase the issue here in order to ensure I’m not missing any details: you are attempting to create a sessionEntity using the “Try this API” tool, which is the Create (POST) version 2.
The issue is that the “name” you are passing in the request body does not have a valid format for API v2.
The format you are using for the name is:
projects/<ProjectID>/locations/<LocationID>/agent/environments/<EnvironmentID>/users/<UserID>/sessions/<SessionID>/entityTypes/<EntityTypeDisplayName>
Below I’ve listed the two valid name formats for v2 and as you can see the locations/<Location ID> is not needed:
projects/<Project ID>/agent/sessions/<Session ID>/entityTypes/<Entity Type Display Name>
and
projects/<Project ID>/agent/environments/<Environment ID>/users/<User ID>/sessions/<Session ID>/entityTypes/<Entity Type Display Name>
The below request body works as intended, I tested it in the same “Try this API” tool:
{
"name":"projects/{projectId}/agent/environments/draft/users/-/sessions/c973fe-e44-9b5-34e-b404439b7/entityTypes/speciality_types",
"entities":[
{
"value":"APPLE_KEY",
"synonyms":[
"apple",
"green apple",
"crabapple"
]
},
{
"value":"ORANGE_KEY",
"synonyms":[
"orange"
]
}
],
"entityOverrideMode":"ENTITY_OVERRIDE_MODE_SUPPLEMENT"
}

Multiple Bodies in a POST operation

I have the following question, I want to make a request for a POST, I have 13 different Body's in environment variables, how can I put all 13 at the same time in Postman to execute? Is there any way?
This is my code:
Some Bodies:
{ "et": "conta", "na": "List", "T": "list", "OPT": [ "TL-1", "TL-2" ], "DBY": "names user", "iM": false }
{ "et": "conta", "na": "Integer", "T": "integer", "DBY": "namesUser", "iM": false }
{ "et": "conta", "na": "MultiSelectList", "T": "multiSelect", "opt": [ "L1", "L2", "L3" ], "DBY": "names user", "iM": true }
What I am doing but I get error 400:
[
{{List}},
{{Integer}}
]
So I would like to know if there is any way to be able to execute the 13 Body's placing them all at the same time
Json arrays (https://restfulapi.net/json-array/) should be used for this
[
{
"et": "conta",
"na": "List",
"T": "list",
"OPT": [
"TL-1",
"TL-2"
],
"DBY": "names user",
"iM": false
},
{
(second array)
},
.
.
.
{
(thirteenth array)
}
]
Good to know: you can use this tool to verify your json; https://jsonlint.com/
Whether or not this results in a status 400 error depends on the implementation of the web api's post method (and you mentioned this happens). In .NET, the received json should be converted to a List<T> instead of type T.
If you posting to your own api, try changing it according to: https://forums.asp.net/t/2098779.aspx?How+to+change+WEB+API+to+accept+a+JSON+Array+for+multiple+entries+
If it's an external api, sending an array won't work. You have to send the data sequentially, but there are some tips and tricks preventing you from doing this manually in Postman: How to Send multiple request concurrently/Sequentially in postman with different set of values for each request?

Range query for long type in aws elasticsearch

I am trying to query an elasticsearch index in AWS to get all entries with a mass attribute greater than 1000, the datatype for the attribute is Long.
I found the range query and have tried that (see example below) but it's returning nothing but when I use other queries they return attributes with mass greater than 1000 so they're definitely in the index.
This is the Range query I'm trying:
{
"method": "POST",
"index": "users",
"type": "user",
"path": "_search?filter_path=filter",
"body": {
"size": 20,
"from": 0,
"query": {
"bool": {
"must":[{
"range": {
"mass": {
"gte": 1000
}
}
}]
}
}
}
}
I'm not getting any error messages, just zero hits.
So the problem that's causing to get you zero hits is the filter_path parameter you specify in
"path": "_search?filter_path=filter"
As stated in the official documentation the filter_path parameter is part of the common options regarding the REST API's. That means you can always add that parameter.
With Response Filtering you can reduce the response returned by Elasticsearch. Since you defined
_search?filter_path=filter
you probably get zero hits because there is no filter-element that can be returned.

Facebook Graph Api publishing to feed returns: "(#100) Param place must be a valid place tag ID"

I am searching at Facebook Graph Api, using graph api explorer, for some place using the following endpoint:
/search?type=place&q=centauro&fields=id,name,link
I am getting this as response:
"data": [
{
"id": "492103517849553",
"name": "Centauro",
"link": "https://www.facebook.com/Centauro-492103484516223/"
},
{
"id": "313439499156253",
"name": "Centauro",
"link": "https://www.facebook.com/Centauro-313439462489590/"
},
{
"id": "175812113006221",
"name": "Centauro",
"link": "https://www.facebook.com/Centauro-175812079672891/"
},
{
"id": "1423220914594882",
"name": "Centauro",
"link": "https://www.facebook.com/pages/Centauro/1423220891261551"
},...
When I try to publish using the field "id" returned:
/me/feed
with fields:
message: Testing
place: 492103517849553
I get the following reponse:
{
"error": {
"message": "(#100) Param place must be a valid place tag ID",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "DfEKOjZX8g+"
}
}
But if I use de final number of the link:
"link": "https://www.facebook.com/Centauro-492103484516223/"
492103484516223
And try again:
/me/feed
with fields:
message: Testing
place: 492103484516223
It works perfectly.
So, is there a way to get te correct place id for publishing? Or is it a bug?
I was also getting the “(#100) Param place must be a valid place tag ID” error, but got it to go away by providing a JSON string within the 'place' element.
So where the content of your request was this:
place: 492103484516223
Format the place information like this instead:
place: {"id": "492103484516223"}
Currently, this is how you can solve it.
import requests
IG_USER_ID = <YOUR INSTAGRAM USER ID>
USER_ACCESS = <YOUR USER ACCESS TOKEN WITH VALID PERMISSIONS>
CONTAINER1_ID = <ID OF FIRST CONTAINER>
CONTAINER2_ID = <ID OF SECOND CONTAINER>
URL = f"https://graph.facebook.com/v13.0/{IG_USER_ID}/media?caption=Fruit%20candies&media_type=CAROUSEL&children={CONTAINER1_ID}%2C{CONTAINER2_ID}&access_token={USER_ACCESS}"
r = requests.post(URL)

When predicting, what are the valid values for dataFormat?

Problem
Using the REST API, I have trained and deployed a model that I now want to use for prediction. I've defined the collections for prediction input and output and uploaded a json file formatted accordingly to the cloud storage. However, when trying to create a prediction job I cannot figure out what value to use for the dataFormat field, which is a required parameter. Is there any way to list all valid values?
What I've tried
My requests look like the one below. I've tried JSON, NEWLINE_DELIMITED_JSON (like when importing data into BigQuery), and even the json mime type application/json, in pretty much all different cases I can think of (upper and lower combined with snake, camel, etc.).
{
"jobId": "my_predictions_123",
"predictionInput": {
"modelName": "projects/myproject/models/mymodel",
"inputPaths": [
"gs://model-bucket/data/testset.json"
],
"outputPath": "gs://model-bucket/predictions/0/",
"region": "us-central1",
"dataFormat": "JSON"
},
"predictionOutput": {
"outputPath": "gs://my-bucket/predictions/1/"
}
}
All my attempts have only gotten me this back though:
{
"error": {
"code": 400,
"message": "Invalid value at 'job.prediction_input.data_format' (TYPE_ENUM), \"JSON\"",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "job.prediction_input.data_format",
"description": "Invalid value at 'job.prediction_input.data_format' (TYPE_ENUM), \"JSON\""
}
]
}
]
}
}
From Cloud ML API reference document https://cloud.google.com/ml/reference/rest/v1beta1/projects.jobs#DataFormat, the data format field in your request should be "TEXT" for all text inputs (including JSON, CSV, etc).