Google Cloud Tasks always set HttpMethod to GET when using HttpRequest as payload_type - google-api

According to this documentation [ https://cloud.google.com/tasks/docs/creating-http-target-tasks ], one should be able to create tasks with type 'http_request' and 'http_method' set to 'POST', but the behavior is not the expected once the task is always created with method 'GET'.
After having this issue while using the Python Client Library, I've decided to try the API directly and check if it was an issue with the library or with the API itself.
Using the "Try this API" from the product's documentation page [ https://cloud.google.com/tasks/docs/reference/rest/v2beta3/projects.locations.queues.tasks/create ], I've tried to create similar tasks using both http_request and app_engine_http_request types and always setting the http_method to POST.
If I set the request body like this:
{
"task": {
"appEngineHttpRequest": {
"httpMethod": "POST",
"relativeUri": "/test",
"body": "c2hhbGxvdyBub3c="
}
}
}
...the task is created and the method is POST, like expected. But, if I set the request body to:
{
"task": {
"httpRequest": {
"httpMethod": "POST",
"url": "https://httpstat.us/404",
"body": "c2hhbGxvdyBub3c="
}
}
}
...the task is created, but with method GET instead of POST.
Here's what I get at my queue:
I believe this is a bug, and that's why I'm reporting it here with tag google-apis-explorer as recommended at the support page.
Anyway, if anyone could tell me if I'm doing something wrong or if there's any workaround in the meanwhile I would really appreciate.
Thanks!

Thank You for this post, this is a bug in the existing Cloud Tasks UI and we are in the process of fixing this bug.
In the meantime the correct HTTP method of the task can be determined by running the following command:
gcloud beta tasks describe
https://cloud.google.com/sdk/gcloud/reference/beta/tasks/describe
The above command will show the correct HTTP method for the task.

Related

Google Form Api. Adding Response validation to textQuestion

Currently, AFAIK, when performing google form batchUpdate using the google forms API v1, we are only able to set the shuffle property of choiceQuestions, while for textQuestions there are no options to set the response validations, like if I want to use regex match as validation.
For Example, the request body looks like this:
{
"requests": [
{
"createItem": {
"item": {
"questionItem": {
"question": {
"choiceQuestion": {
"shuffle": false
},
"textQuestion": {
"paragraph": false
/*no other parameters to set*/
}
}
}
}
}
}
]
}
Am I missing something? Or is this feature not implemented yet?
You are correct, this has not been implemented yet. For now, these are the only options that can be used with ChoiceQuestion This is kind of expected taking into consideration FORMS API was launched just last month.
So you may want to submit a Feature Request for that missing feature.
In the meantime, you can also consider tackling this using Google Apps Script and its Forms Advanced Service which includes response validation.

Azure Logic App throwing 302 Redirect Error having Server=BIG IP in Response Header for HTTP

I am getting Redirect 302 error for HTTP Request in Logic App. I am calling OneIdentityServer to get access token. Then I am calling Rest API passing access token as Header for key Authorization. I am getting 302 Redirect error in response with headers information like Server = BIG IP, Location= /my.policy
The same above request when triggered through Postman or SOAPUI is working fine, I am getting successful response. But the same is failing in Azure Logic App.
I have also implemented the above scenario in function app as well. It is working file when I run the function app code from visual studio using Postman. But when I test the same function app after publishing it to Azure portal, it is giving same error.
It seems like I have the same issue as you. I found one-way that did not work for me but maybe you could give it a shot if it fits your needs?
The solution that I found in a blogpost was first to add the action "Switch" to the logic app flow and then configure Switch to run after the HTTP is both successful and has failed.
Secondly, the Switch action should trigger on the output of the statuscode from the HTTP request.
If the statuscode equals 302 you should make another HTTP request but with URI being the output of the location header from the first HTTP request. This made my logic app result in statuscode 200 but the response for my logic app was that I needed to login to get access to the API.
But maybe it could be worth giving this solution a shot for your logic app?
Here's the link of the blogpost if you need deeper instructions: http://www.alessandromoura.com.br/2018/11/21/dealing-with-http-302-in-logic-apps/
Do you still have issues with this? Here is a screenshot of my http action: HTTP Action that is working.
I have put my URL in an variable since it changing for each pagination. I also found out that to use the authentication token from the first HTTP request I needed to parse the body to be able to access the token, here is the schema I used to parse the HTTP body from the request where you get access token:
{
"properties": {
"access_token": {
"type": "string"
},
"expires_in": {
"type": "string"
},
"expires_on": {
"type": "string"
},
"ext_expires_in": {
"type": "string"
},
"not_before": {
"type": "string"
},
"resource": {
"type": "string"
},
"token_type": {
"type": "string"
}
},
"type": "object"
}

Google Speech API: the requested URL was not found on this server

I am attempting some simple tests on the Google Speech API, and when my server makes a request to this url (below), I get the 404. that's an error response. Not sure why.
https://speech.googleapis.com/v1/speech:recognize?key=[MY_API_KEY]
The body of my request looks like this:
{
"config": {
"languageCode": "en-US",
"encoding": "LINEAR16",
"sampleRateHertz": 16000,
"enableWordTimeOffsets": true,
"speechContexts": [{
"phrases": ["Some", "Helpful", "Phrases"]
}]
},
"audio":{
"uri":"gs://mydomain.com/my_file.mp3"
}
}
And here is the response:
As you can see, that is a valid resource path, unless I'm totally mistaken about something (I'm sure I am): https://cloud.google.com/speech-to-text/docs/reference/rest/v1/speech/recognize
Update 1:, Whenever I try this with the Google API explorer tool, I get this quota exceeded message (even though I have not yet issued a successful request to the API).
{
"error": {
"code": 429,
"message": "Quota exceeded for quota metric 'speech.googleapis.com/default_requests' and limit 'DefaultRequestsPerMinutePerProject' of service 'speech.googleapis.com' for consumer '[MY_API_KEY]'.",
"status": "RESOURCE_EXHAUSTED",
"details": [
{
"#type": "type.googleapis.com/google.rpc.Help",
"links": [
{
"description": "Google developer console API key",
"url": "https://console.developers.google.com/project/[my_project_id]/apiui/credential"
}
]
}
]
}
}
Update 2: Interestingly, I was able to get some 200 ok's using the Restlet client, but even in those cases, the response body is empty (see screenshot below)
I have made a test by using the exact URL and Body content you added to the post, however, I was able to execute the API call correctly.
I noticed that if I add some extra character to the URL, it fails with the same 400 error since it doesn't exist. I would suggest you to verify that the URL of your request doesn't contain a typo and that the client you use is executing the API call correctly. Also, ensure that your calling code is not encoding the url, which could cause issues given the colon : that appears in the url.
I recommend you to perform this test by using the Try this API tool directly or Restlet client which are the ones that I used to replicate this scenario.

Wiremock Standalone with Dynamic response

I have a standalone instance of Wiremock server. The mappings are stored as json files under the mappings folder. I have a POST request that needs to return a dynamic ID(integer) in the response. Is there a way to configure this in the json file?
To make the above examples work, I had to run the standalone jar with the --global-response-templating. Then I saw, for example, {{now}} working which is what I wanted. Not sure if the documentation specifies this -- I tried the always-useful --help.
In WireMock there are a number of response template helper functions for generating random strings. In the below example I'm using the one for generating a UUID, but several other options exist.
Mapping file: dynamic_id.json
{
"request": {
"method": "POST",
"url": "/dynamic_id"
},
"response": {
"headers": {
"Content-Type": "application/json"
},
"status": 200,
"body": "{{randomValue type='UUID'}}",
"transformers": ["response-template"]
}
}
Using an empty POST http://wiremock/dynamic_id will return an id similar to: c2e6bf32-c9a3-45c0-b988-94fad04cc7a2.
Start WireMock:
java -jar wiremock-standalone-2.18.0.jar --port 8181 --verbose --local-response-templating
This seems like a perfect use-case for OpenTable's Wiremock Body Transformer.
It can be easily integrated with the Standalone Server like this:
java -cp "wiremock-body-transformer-1.1.6.jar:wiremock-2.3.1-standalone.jar" com.github.tomakehurst.wiremock.standalone.WireMockServerRunner --verbose --extensions com.opentable.extension.BodyTransformer
And allows you to easily specify a dynamic variable that you would want to match in the response.
Here is an example to get a random integer without having to specify anything in the request, however if you need to match a specific variable in the request to the response, then that is also very doable with this extension and numerous examples can be found in the readme.
{
"request": {
"method": "POST",
"urlPath": "/transform",
},
"response": {
"status": 200,
"body": "{\"randomInteger\": \"$(!RandomInteger)\"}",
"headers": {
"Content-Type": "application/json"
},
"transformers": ["body-transformer"]
}
}
As #Jeff mentions, If you are running it as a stand-alone process, you need to add this flag --global-response-templating. This will apply templating to each and every reponse. However, few of your responses may be jsut plain json with no templating required.
In that case use --local-response-templating. and add this field inside reponse json:
response:{
"transformers": ["response-template"]
}

Error trying to create session on an Excel file using Microsoft Graph

I'm trying to manipulate an Excel file using Ruby, while I seem to eb able to read it properly - I have trouble creating a session to start writing into it. There's not much help online on what this even means.
I'm trying to create a session like this, just like it suggests on the documentation (but not in ruby)
url = "https://graph.microsoft.com/v1.0/me/drive/items/#{#item_id}/workbook/createSession"
response = HTTParty.post(url, headers: { 'Authorization' => #access_token,
'Content-Type' => 'application/json' },
body: '{ "persistChanges" : true }')
But I get the following response.
{
"error": {
"code": "EditModeCannotAcquireLockUnknownUser",
"message": "",
"innerError": {
"request-id": "b088abbe-8353-4614-b9a7-d769ff85da50",
"date": "2017-08-15T17:12:41"
}
}
}
#response=#<Net::HTTPConflict 409 Conflict readbody=true>
I've just started with this, what could be the problem? the error indicates that some unknown user has locked the file - but the file is editable and the access_token is derived from my own user profile
Where do I go from here? has anybody manipulated excel files and formula using Microsoft Graph?
Turns out it's an issue with that particular file, I still don't know why though. it's not really an answer - but the lack of documentation for anything to do with this API is stunning. I'd appreciate links.

Resources