Update a session with Google Fit REST API - google-fit

I can create successfully sessions with the Fit REST API.
But when I try to update one (ie change the name), it creates a new session, even if I use the previously created session ID in the url and in the request body (I do the exact same request as the session creation but I change only the "name" property's value).
The result is that I have 2 sessions with the same ID.
If I try to delete the session and the "copy", I get a response error with the message "Session already deleted".
Is there any way to correctly update a session?

You may refer with this documentation about Users.sessions. You need to use the update method which updates or inserts a given session.
HTTP request:
PUT https://www.googleapis.com/fitness/v1/users/userId/sessions/sessionId
Check the example and explanations here.

Related

Jmeter: How to resolve Conflict message 409 in deleting a particular id

I created a container with post Request and now i want to delete the container with container Id parameter.This is the error message i am getting .
could you tell me the reason for this conflict message in Delete HTTP Request
Since this is DELETE request/operation, 409 status code probably means you are not allowed to delete the entity. Check your user permissions and the specific entity requirements.
Most probably you have recorded your script and somewhere in generated HTTP Request samplers there is hard-coded ID of 1216 and when you're trying to replay your test with > 1 user your web application responds with HTTP 409 status code
Alternatively you're trying to update an item with again recorded hard-coded timestamp and your application refuses to do it as it's older than the current time.
So you need to revisit your HTTP Request sampler and either correlate the item ID or parameterize the timestamp using __time() function or both

Create Etag string using Google apps script

I use Google people API to update a contact.
I save the resourceName of the created contact and when I update the contact, I just use this code
People.People.updateContact({"emailAddresses": [{
"type": "work",
"value": "example#gmail.com"
}]}, "people/c6679930577989153852")
But this throws error - GoogleJsonResponseException: API call to people.people.updateContact failed with error: Request must set person.etag or person.metadata.sources.etag for the source that is being updated.
How do I create an etag if I dont store the created etag at the time of contact creation?
Is there a way I can create a new etag using a function so I can force update the entire contact?
if so how do I create a updatePersonFields mask?
How to deal with the etag Contacts API error.
The server returns a 400 error with reason "failedPrecondition" if person.metadata.sources.etag is different than the contact's etag, which indicates the contact has changed since its data was read. Clients should get the latest person and merge their updates into the latest person.
Source
So you are right in thinking that you need the etag to be able to complete the operation you want.
However, generating it is not the right way to go.
You would need to first make a simple get request with any personFields to get the current etag value. Then you would use this etag value in the update.
This is to prevent you from overwriting and duplicating possibly important information.
Reference
updateContact
get

JWT authentication requires me to logout and to log back in to see updated information of a user

I have a node.js/express application that's using JWT as authentication.
When my user logins it displaying their information using "user_id", I have an update method that will update that users information "first_name", "last_name" by getting that "user_id".
When I run my update method, the information gets updated but it requires my user to log out and log in to see the updated information.
The best approach can be one of those two:
1 - Do an update request and, if this succeeded, return the updated information in the response.
2 - Do an update request and, if this succeeded, after receive the 200 status code do a "getOne" request passing the user_id.
You need to replace the state of your frontend.
I don't know what you use on the frontend, but if were some javascript framework, the two-way databind will do replace for you.
If you use another tech such PHP, you need to refresh the page with the new information.

GET request in Django

I have a doubt. When is a GET request sent. I mean, I have seen a lot of people using if request.method == 'GET', when they render the form for the first time, but when the form is submitted, they do a `POST' request.
While they explicitly mention when defining the form in html that the method will be 'POST', they don't do the same for 'GET' request which is made when an empty form is requested.
How does django know it's a GET request?
And, why is it done so?
Thanks,
I'm not an expert but I think Django "knows" this because like all things on the Internet it uses the HTTP protocol. There are several HTTP methods. If not specified the default method will always be GET
GET
A GET is usually used to retrieve information. Typically a GET function has no side-effects (this means that data in the database is not changed, that no files in the filesystem are modified, etc.).
Strictly speaking this is not always true, since some webservers log requests (themselves) and thus add an entry to the database that a specific user visited a specific page at a specific timestamp, etc.
A typical GET request is idempotent. This means that there is no difference between doing a query one time, or multiple times (two times, three times, five times, thousand times).
GET queries are therefore typically used to provide static content, as well as pages that contain data about one or more entries, search queries, etc.
POST
POST on the other hand typically ships with data (in the POST parameters), and usually the idea is that something is done with this data that creates a change in the persistent structures of the webserver. For example creating a new entry in some table, or updating the table with the values that are provided. Since these operations are not always idempotent, it can be dangerous if the user refreshes the page in the browser (since that could for example create two orders, instead of the single order the user actually wanted to create).
Therefore in Django a POST request will typically result in some changes to the database, and a redirect as result. This means that the user will typically obtain a new address, and perform a GET request on that page (and that GET is idempotent, hence it will not construct a new order).
PUT, PATCH and DELETE
Besides the popular GET and POST, there are other typical requests a client can make to a webserver. For example PUT, PATCH and DELETE.
PUT
PUT is the twin of a POST request. The main difference is that the URI it hits, specifies what entry to construct or update. PUT is usually an idempotent operation.
This means that if we would for example perform a POST server.com/blog/create to create a blog, PUT will typically look like PUT server.com/blog/123/. So we specify the id in advance. In case the object does not yet exists, a webserver will typically construct one. In case the entity already exists, a new entity will typically be constructed for that URI. So performing the same PUT operation twice, should have no effect.
Note that in case of a PUT request, typically one should specify all fields. The fields that are not specified will typically be filled in with default values (in case such values exist). We thus do not really "update" the entity: we destroy the old entity and create a new one in case that entity already exists.
PATCH
PATCH is a variant of PUT that updates the entity, instead of creating a new one. The fields that are thus missing in a PATCH request, typically remain the same as the values in the "old" entity so to speak.
DELETE
Like the name already suggests, if we perform a DELETE server.com/blog/123/ request, then we will typically remove the corresponding element.
Some servers do not immediately remove the corresponding element. You can see it as scheduling the object for deletion, so sometimes the object is later removed. The DELETE request, thus typically means that you signal the server to eventually remove the entity.
Actually Django is based on HTTP responses-requests. HTTP is fully textuall. So Django parses each request and finds in its header information about what kind of request is it. I may be mistaken in details, but as I understand when server receives request - Django creates it's object request, which contains all the data from HTTP. And then you decide if you need a specific action on GET or POST and you check the type of request with request.method.
P.S. And yes, by default each request is GET.

How to use responses from a Jmeter JDBC Request in a HTTP Request

Here's my situation:
I want to do this:
I have a list of URLs in a MySQL database which I want to hit using a HTTP Request to see if the response is a HTTP Status code of 404 or not.
I have done this:
Added and configured a JDBC Config Element.
Added and configured a JDBC Request Sampler. Basically a select statement that returns a table with 8 columns. I have provided 8 comma-separated variables for the 'Variable names' field, so that the results of the JDBC request can be identified with these variable names.
Created a HTTP Request Sampler that uses one of those variables ${url} in the 'Server Name or IP' field.
Though the JDBC request works flawlessly and returns a table with a bunch of rows, the problem with this is that the HTTP Request Sampler never picks up the variable from the JDBC Request result.
The HTTP Request looks like this in the 'View Results Tree':
GET http://${url}/
I have tried these solutions:
Add 'Save Responses to a File' listener to the JDBC Request. This creates a file of type '.plain' and not a CSV. Had it been a CSV, I could have utilized that CSV file by creating a CSV Data Set Config. So this attempt failed.
I have tried forcing the file name in the above attempt to always use 'C:\JMETERTest\data.csv'. But it ends up creating a new file named 'C:\JMETERTest\data.csv1.plain'. This attempt failed too.
I tried to reference the URL column as ${url_1} in the HTTP Request's Server Name field. It worked. But the problem now is that in the results tree, all the requests are going for the the URL from only the first row of the result set. I see that this is because of the row number '_1' specified in the ${url_1} above. I can use this if someone can suggest a way to parameterize the '_1' into a variable that I can loop through (probably using a 'Counter' element). I created a Counter Config Element by the Reference Name 'loopCounter'. And used this in the Server Name field of the HTTP Request:
${url_("${loopCounter}")}
But now my HTTP Requests look lamer:
GET http://${url_("${loopCounter}")}/
This did not work too.
Solution 3 looks more doable to be only if I could resolve the parameterization of the row number.
I am open to JMeter Plugin suggestions too.
I will update anything else that I try as we go on.
P.S. Please let me know if my question is not clear in anyway.
Have you tried wrapping the HTTP sampler in a ForEach controller (parent) where the variable for the controller is the URL variable obtained from the JDBC sampler?
Also, the output variable in the ForEach will be the variable you now use in the HTTP sampler.
That way it will iterate through each variable from the beginning of the index to the end and run the sampler once each time.
In 'Save responses to a File' Listener, Select Checkboxes "Don't add Suffix and Prefix". Checking these two options will ensure, you get exact Log file name.