DocumentDb feedResponse.ResponseContinuation JSON - c#

When I get continuation token while querying Documents on DocumentDb NoSQL database I get feedResponse.ResponseContinuation JSON
{
"token":"+RID:r+xQAPHUJQANAAAAAAAAAA==#RT:1#TRC:10#FPC:AQ0AAAAAAAAAIAAAAAAAAAA=",
"range":{"min":"","max":"FF"}
}
Could you please explain what each field means? And how the values are set/ calculated? Is the "token" value encrypted?
Thanks.

Could you please explain what each field means? And how the values
set/ calculated ? Is "token" value encrypted?
Presence of continuation token in response headers means there's more data available for the request you made.
You should not try to interpret this value and treat it as Opaque. By opaque what I mean to say is that you should not build your business logic around this continuation token's value because in my experience, you will receive different values under different circumstances.
For example, we receive following tokens under different circumstances:
In one instance, we received the following:
{"token":"-RID:4pVnPNKLRAAGAAAAAAAAAA==#RT:1#TRC:2","range":{"min":"","max":"FF"}}.
Yet, in another instance we received the following:
{"token":null,"range":{"min":"05D1A53CB92960","max":"05D1B53CB92960"}}.
And then there's another one:
+RID:4pVnAO6fMNADAAAAAACAAQ==#RT:1#TRC:2#FPC:ALMABAAAAIABAwAAAAAAgAE=
As you can see, there's no rhyme or reason behind the value of this token.
What your code should do is check for the existence of continuation token in response headers and if it is there then include this in your next request to get next set of data.

Related

Inconsistent string/array formatting in JWT payload

I am creating JWT's (Json Web Token) using System.IdentityModel.Token.JWT
Essentially feeding a bunch of claims into the WriteToken() method and getting a token string back.
The problem is that the formatting is inconsistent. If I add a "role" claim with a value, it's formatted as a string. If I add one more "role" claim it's formatted as an array. And the consumer has to do special processing to figure out what it is.
The docs say :
"For each Claim a JSON pair { 'Claim.Type', 'Claim.Value' } is added. If duplicate claims are found then a { 'Claim.Type', List } will be created to contain the duplicate values."
How can I avoid this and always get an array?

How do I get only the new/updated events from a calendar in Office365?

I'm a junior developer trying to figure out the Outlook365 REST API.
I'm using the office365 rest api to sync my events from my calendar.
On my first request, I get all the events from a time range. This returns a deltaToken.
After that I add more events to my calendar and make another call using the last deltaToken returned from my calls. This request returns all the events (including the new ones) and 2 deltaTokens (the first is the one I've sent, and the second is a new one).
I only want to get the new events, not all of them. If I'm making the request using the deltaToken from my previous request, does that not mean that I've already synced all my previous events and shouldn't the next calls get only the new / modified events?
Below is a response. Is it ok to have 2 deltaTokens in my response?
{"#odata.context":"https://outlook.office.com/api/beta/$metadata#Me/CalendarView,
"value":[list of events],
"#odata.deltaLink":"https://outlook.office.com/api/beta/Me/CalendarView/?startDateTime=2017-07-25T00%3a00%3a00Z&endDateTime=2017-09-01T00%3a00%3a00Z&deltatoken=GGXXX&%24deltatoken=GWXXX"
}
It sounds like you are not finalizing your first sync. The way sync works in the API is a little counter-intuitive. It isn't as simple as checking for a deltaToken to see if you're done.
The reason is that the first request with Prefer: odata.track-changes always returns a deltaToken, even if there are more results. The docs give more detail here, but the general sequence is:
Do GET on the calendar view with Prefer: odata.track-changes.
Verify that Preference-Applied: odata.track-changes header is present in response. If so, get the deltaLink and do a GET on that.
Now enter your loop. If you get a nextLink in response, do a GET on that and repeat. If you get a deltaLink, the sync is done. Store the value until your next sync.

500 error when querying workfront api Hours + parameterValues

When calling WorkFront's API
https://preview.workfront.com/attask/api/v7.0/HOUR/search?fields=*,parameterValues
I get a 500 error. It works fine if I don't specify parameterValues. In comparison providing a bogus field returns:
https://preview.workfront.com/attask/api/v7.0/HOUR/search?&fields=*,garbageParam
{"error":{"class":"java.lang.IllegalArgumentException","message":"APIModel V7_0 does not support field garbageParam (Hour)"}}
I can't simply remove parameterValues because the url is generated by the code, and I didn't see a means of determining if a particular ObjCode will or won't crash if given parameterValues.
My code is supposed to dump the JSON into C# classes I have, so I need all the fields that are available. Unfortunately WorkFront crashing by being requested all the fields is throwing a wrench into the design.
Is there a way to get around the 500 error, or a way to detect if paramterValues should be provided or not?
I am not sure why you are getting a 500 Error rather then a more specific error but Hours do not contain custom data so parameterValues would not contain any data on the HOUR object. If you were to make the same Call on the TASK object it would work.

How to add limit parameter in the soap request url?

My aim is to get all records from a table in ServiceNow. By default, I am able to get 250 records. But I need to get all the records. I learnt from here that
we can set the limit in the soap request url.
Code:
var url = "https://*****.service-now.com/rm_story.do?SOAP";
Additional code in getting records for reference
I added the limit parameter to the above url as
https://*****.service-now.com/rm_story.do?&limit=300&SOAP.
Even though, I am getting same 250 records.
Is this the correct way to add limit ? If not, how to add limit in the SOAP request url in ServiceNow? Thanks.
The _limit parameter must be passed in the body of the http request not the url. See answer to
ServiceNow - Getting all records for example http request to ServiceNow SOAP API using _limit parameter.
No, you need to look at first_row (perhaps combined with limit):
first_row: Instruct the results to be offset by this number of records from the beginning of the set. When used with __last_row has
the effect of querying for a window of results. The results are
inclusive of the first row number.

Difference between Request.Form and Request.QueryString?

Can some tell me the exact difference between Request.Form and Request.QueryString?
I know one difference, like
If the HTTP request method is POST, the user submitted data is in the
Request.Form() collection
If the HTTP request method is GET, then user submitted data is in the
Request.QueryString() collection
any other difference? and Any example would be greatly appreciated.
In Request.Form the data is posted in the http request body whereas in QueryString data is sent through url.
I found some other difference
Request("id")
will first try to locate
Request.Form("id")
then
Request.Querystring("id")
then
Request.Cookies("id")
and finally
Request.ServerVariables("id")
it is reccommended to use the explicit naming convention if possible because it is more efficient and more readable.it also enables you to be sure where your information is coming from since the system will stop after the first hit is made.... It is also faster for the system if you specify the location of the information.
and we can refer this link for more some details :
http://www.hanselman.com/blog/ASPNETParamsCollectionVsQueryStringFormsVsRequestindexAndDoubleDecoding.aspx
But any one know any other difference, I really appreciate that .
As stated on MSDN,
(Request.Form): The value of Request.Form(element) is an array of all
the values of element that occur in the request body. You can
determine the number of values of a parameter by calling
Request.Form(element).Count. If a parameter does not have multiple
values associated with it, the count is 1. If the parameter is not
found, the count is 0.
and (Request.QueryString): The value of Request.QueryString(parameter)
is an array of all of the values of parameter that occur in
QUERY_STRING. You can determine the number of values of a parameter by
calling Request.QueryString(parameter).Count. If a variable does not
have multiple data sets associated with it, the count is 1. If the
variable is not found, the count is 0.
So, some things to note:
In a typical Form on a page, we may include some hidden elements:
<form method="post">
<input type="hidden" name="lol" value="cat" />
<input type="text" />
</form>
Hidden elements (if memory serves), are not displayed in the QueryString. So, I would assume that there are some things that are not shown in Request.QueryString. Unfortunately I am in the process of re-installing dev apps on a new machine and cannot test this at the moment but if I'm right, when you POST a form, more details about the form and its contents gets sent. And when you access QueryString, you are only seeing the things that make up the entirety of the URL, e.g.:
http://somesite.com/index.html?v=1&NonHiddenElement=lol&ManualValue=hello
Request.Form - means you are wanting to retrieve the values for the form that was posted.
Request.QueryString - means you are wanting to retrieve values that have been passed on the querystring.
Request.Form()
The Form collection retrieves the values of form elements posted to the HTTP request body, Only those elements and value which exist in your Form.
Request.QueryString()
The QueryString collection retrieves the values of the variables in the HTTP query string, Here you can append any of your custom variable and value which event dose not exist in your Form.
Request.Form Collection
The Form collection retrieves the values of form elements posted to the HTTP request body, with a form using the POST method.
Form input is contained in headers. It is wise to not trust the data that is contained in headers, as this information can be falsified by malicious users. For example, do not rely on data such as cookies to securely identify a user.
As a security precaution, always encode header data or user input before using it. A general method of encoding data is to use Server.HTMLEncode. Alternatively, you can validate header data and user input with a short function such as the one described in Validating User Input to Avoid Attacks. For more detailed information about developing secure Web applications, see chapter 12 of MS Press - Writing Secure Code.
Syntax
Request.Form(element)[(index)|.Count]
Parameters
element
The name of the form element from which the collection is to retrieve values.
index
An optional parameter that enables you to access one of multiple values for a parameter. It can be any integer in the range 1 to Request.Form(parameter).Count.
Applies To
Request Object
Remarks
The Form collection is indexed by the names of the parameters in the request body. The value of Request.Form(element) is an array of all the values of element that occur in the request body. You can determine the number of values of a parameter by calling Request.Form(element).Count. If a parameter does not have multiple values associated with it, the count is 1. If the parameter is not found, the count is 0.
To reference a single value of a form element that has multiple values, you must specify a value for the index parameter. The index parameter may be any number between 1 and Request.Form(element).Count. If you reference one of multiple form parameters without specifying a value for index, the data is returned as a comma-delimited string.
When you use parameters with Request.Form, the Web server parses the HTTP request body and returns the specified data. If your application requires unparsed data from the form, you can access it by calling Request.Form without any parameters.
Request.QueryString Collection
The QueryString collection retrieves the values of the variables in the HTTP query string. The HTTP query string is specified by the values following the question mark (?). Several different processes can generate a query string. For example, the following anchor tag generates a variable named string with the value "this is a sample."
string sample
Query strings are also generated by sending a form or by a user typing a query into the address box of the browser.
Query strings are contained in request headers. It is wise to not trust the data that is contained in headers, as this information can be falsified by malicious users. For example, do not rely on data such as cookies to securely identify a user.
As a security precaution, always encode header data or user input before using it. A general method of encoding data is to use Server.HTMLEncode. Alternatively, you can validate header data and user input with a short function such as the one described in Validating User Input to Avoid Attacks. For more detailed information about developing secure Web applications, see chapter 12 of MS Press - Writing Secure Code.
Syntax
Request.QueryString(variable)[(index)|.Count]
Parameters
variable
Specifies the name of the variable in the HTTP query string to retrieve.
index
An optional parameter that enables you to retrieve one of multiple values for variable. It can be any integer value in the range 1 to Request.QueryString(variable).Count.
Applies To
Request Object
Remarks
The QueryString collection is a parsed version of the QUERY_STRING variable in the ServerVariables collection. It enables you to retrieve the QUERY_STRING variable by name. The value of Request.QueryString(parameter) is an array of all of the values of parameter that occur in QUERY_STRING. You can determine the number of values of a parameter by calling Request.QueryString(parameter).Count. If a variable does not have multiple data sets associated with it, the count is 1. If the variable is not found, the count is 0.
To reference a QueryString variable in one of multiple data sets, you specify a value for index. The index parameter can be any value between 1 and Request.QueryString(variable).Count. If you reference one of multiple QueryString variables without specifying a value for index, the data is returned as a comma-delimited string.
When you use parameters with Request.QueryString, the server parses the parameters sent to the request and returns the specified data. If your application requires unparsed QueryString data, you can retrieve it by calling Request.QueryString without any parameters.
You can use an iterator to loop through all the data values in a query string.
For example, if the following request is sent:
for more details click this link

Categories