How do I use the "If-Modified-Since" in the Salesforce v55.0 Rest API? - api

According to the documentation:
"An optional header specifying a date and time. The request returns
records that have been modified after that date and time."
I am making a request to the following endpoint:
/services/data/v55.0/sobjects/Contact/{id}
With the following headers:
GET
Content-Type: "application/json" Authorization: "Bearer
{access_token}" "If-Modified-Since": Thu, 08 Sep 2022 16:54:10 GMT
The header of the response contains the "Last-Modified" date/time of the SObject row that I requested and the date is "Thu, 08 Sep 2022 15:54:10 GMT".
How is it possible that the api is returning the data of the contact if it has not been modified since the time in my request?
Note: When I change the date/time in my request to "Thu, 08 Sep 2022 15:54:11 GMT", I see the correct behaviour and a 304 Not Modified is returned. However, should the time be moved forward by an hour the data is returned with a 200 OK

This can be a bug in the server implementation.
Another explanation that the server time is not properly set. Looks like in the case of salesforce this is true. A possible workaround is strictly using the value they send in the Last-Modified header instead of the current time of the client's computer. https://salesforce.stackexchange.com/a/375976

Related

Remove Request-Context from Response Header

Somehow in my request response header "Request-Context" coming and i tried to remove that using in web.config and Response.Headers.Remove("Request-Context"); in global.asax but that header is not getting removed.
In the value of that header I am getting some Appid and I am not sure from where that is coming.
Here is response header of my request.
Cache-Control:no-cache, no-store
Content-Encoding:gzip
Content-Length:140
Content-Type:application/json; charset=utf-8
Date:Tue, 20 Feb 2018 09:48:28 GMT
Pragma:no-cache
Request-Context:appId=cid-v1:b650ed48-297a-4ea2-af46-0a5a5d26a82b
Vary:Accept-Encoding
Any help appreciated. Thanks in Advance.
Request-Context is used for cross-component correlation when 2 of your applications use different instrumentation keys.
In this case, knowing caller or callee appId (passed in the header) allows to build application map and trace correlated telemetry across instrumentation keys
You may set RequestTrackingTelemetryModule.SetComponentCorrelationHttpHeaders to false to prevent header to be added to the response.
You can do it in applicationInsights xml file, just find RequestTrackingTelemetryModule element and add false under it.
Refer link: https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/739#issuecomment-367774652

How do you set up permanent caching for cloudfront?

I've read through the documentation and attempted to setup permanent cloudfront caching. The idea is that once you download an image you shouldn't need to download it again. I'm looking at my network tab and I don't think it is. Can someone tell me if this file has the correct cache settings?
https://d2t4fc8ff77neh.cloudfront.net/cardSrcMedia/1abqkohet_plain_red_heart_graphic_with_a_drop_shadow_0071-0910-0216-0922_SMU.jpg
My headers:
var headers = {
'Content-Length': options.data.length,
'Vary': 'Accept-Encoding',
'Expires': 1000 * 60 * 60 * 24 * 365 * 5,
'x-amz-acl': 'public-read',
'Content-Type': options.type
}
It looks like your image is being cached by CloudFront, but your expires header value isn't valid.
From the HTTP 1.1 spec (https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html):
The format is an absolute date and time as defined by HTTP-date in
section 3.3.1; it MUST be in RFC 1123 date format
and
HTTP/1.1 clients and caches MUST treat other invalid date formats,
especially including the value "0", as in the past (i.e., "already
expired").
and
To mark a response as "never expires," an origin server sends an
Expires date approximately one year from the time the response is
sent. HTTP/1.1 servers SHOULD NOT send Expires dates more than one
year in the future.
It's probably better to use a Cache-control header as this supersedes the Expires header. Something like this should produce the same effect:
Cache-Control: max-age=31536000

Cache control headers, cache for long time, but still validate?

I have a url that I'd like to cache (forever per se) but I'd also like to have the browser re-validate it everytime. I don't know if it's possible, something either like Last-Modified (see below) or if the size is different.
I'm just trying to find out how/what "sets" the Last-Modified response header. I did a test example for "max-age=86400" and I have an image showing:
Cache-Control:max-age=86400, public
Date:Fri, 29 Jan 2016 04:21:31 GMT
Expires:Fri, 29 Jan 2016 04:21:32 GMT
Last-Modified:Fri, 29 Jan 2016 03:59:25 GMT
Yet the browser is still caching it, and that's fine as I would expect that, but my problem (and question) is about the Last-Modified part. For one, the image is a different size and it was modified since 03:59:25, so I'm expecting the browser to re-check if the file was changed or if it should serve the cached image. if I 'stat' the file at the terminal the Modify time is not 03:59 anymore, so I'm curious if that Last-Modified time is because that's when it was "Last-Modified" when my browser cached it?

Google calendar API 400 error

I'm trying to execute a simple freebusy query on the Google Calendar API. I have my authorization all working fine, can see lists of users' calendars, etc. When I try to submit a free/busy query, I get a 400 error with (as far as I can tell) not details at all about what it doesn't like.
This is true both in my own code and when I use the Google Calendar API "Try It" feature.
Here is my request (created using the Try It widget), and the response:
Request
POST https://www.googleapis.com/calendar/v3/freeBusy?key={YOUR_API_KEY}
Content-Type: application/json
Authorization: Bearer ya29.AHES6ZTr-2wksEvp0iGPTnHTirTIItib5WwxmSAySq1ghfI98Cz88kA
X-JavaScript-User-Agent: Google APIs Explorer
{
"items": [
{
"id": "[my calendar id goes here]#group.calendar.google.com"
}
],
"timeMin": "2012-01-31T09:00:00",
"timeMax": "2012-01-31T10:00:00",
"timeZone": "GMT"
}
Response
400 Bad Request
cache-control: private, max-age=0
content-encoding: gzip
content-length: 122
content-type: application/json; charset=UTF-8
date: Sun, 16 Jun 2013 13:08:32 GMT
expires: Sun, 16 Jun 2013 13:08:32 GMT
server: GSE
{
"error": {
"errors": [
{
"domain": "global",
"reason": "badRequest",
"message": "Bad Request"
}
],
"code": 400,
"message": "Bad Request"
}
}
I think it might have something to do with the dateTime objects/formatting? But I don't have any idea what. I'd really appreciate some help; I've been banging my head against this for a week!
Ok, I figured it out and I am leaving the answer for anyone else who is LOSING THEIR MIND over this.
Despite what Google's documentation says about format for datetime in this case, the only format I could get to work was this:
2008-03-07T17:06:02.000Z
so that's
YYYY-MM-DDTHH:MM:SS.MMMZ
What is the Z for? I don't know, but it has to be there.
I had the same problem, but I managed to solve it simply by removing the "Z" from DateTime and in TimeZone putting GMT with the time difference:
'dateTime': '2020-10-31T17:00:00.000',
'timeZone': 'GMT-03:00'
The date time value should be in UTC "TZ" format. Almost all CRMs and public API accept time in this format. If you convert the datetime to UTC time using major language (such as C or Java) library functions/methods they would return a datetime instance in YYYY-MM-DDTHH:MM:SS.MMMZ format.
In short, you are missing the time zone offset in both the timeMin and timeMax variables, this is required even if you have the timeZone variable set.
For example, I live in the America/New_York timezone so my offset would be -05:00, which needs to be appended to the values you currently have. So for me the values would look like,
{
...
"timeMin": "2012-01-31T09:00:00-05:00",
"timeMax": "2012-01-31T10:00:00-05:00",
...
}
To be more specific, Google Calendar API requires that timeMin and timeMax
Must be an RFC3339 timestamp with mandatory time zone offset, for
example, 2011-06-03T10:00:00-07:00, 2011-06-03T10:00:00Z. Milliseconds
may be provided but are ignored. If timeMax is set, timeMin must be
smaller than timeMax.
So you can either have 2012-01-31T09:00:00-5:00 or 2012-01-31T09:00:00Z with the milliseconds as optional (since its ignored anyway).
The Google Calendar Events list API documentation is where I got all the info from.

getting directly only the contents after the first nth character in vb.net

Is there any way we could get directly say the 1000 characters after the first 5000 characters, skipping everything before that after sending in an HTTP request to an HTTPS page using either GET or POST in VB.NET?
The reason why I ask this question is because in one of the webpage I am trying the get through my program, the website is sending response data in chunks with the first chunk containing some javascript garbage that I have no interest in, the only data I care is in the second chunk and
I have no idea how to get the second chunk after receiving the first one since it is within the same HTTP request
It would save some time and Internet traffic if I can skip the first chunk that I do not need.
Is that possible or I am just day dreaming?
Many thanks!
ADDED:
Here is how a typical header of the response I am getting from the webpage I am trying to get:
Date: Mon, 20 Jun 2011 13:21:56 GMT
Set-Cookie: JSESSIONID=1AF1AF9EF936E1CB2FA85B750EDC67C4; Path=****some path******; Secure
Content-Type: text/html; charset=ISO-8859-1
Transfer-Encoding: chunked
Set-Cookie: **********some cookie***************
path=/
Vary: Accept-Encoding, User-Agent
Not sure if that helps, but as you can see, the chunk size is not visible to me, there is no "Trailer" in the header as well.
Fun little problem. Look at RANGE in the following GET request.
GET /file.txt HTTP/1.1
Host: localhost
Range: bytes=5000-6000
Connection: Close
Edit: Found a HTTP example.
Here is an example in PHP. (Sorry I couldn't find any VB.NET examples).