Proper REST formatted URL with date ranges - rest

I have a REST URL to get all users formatted like this:
http://example.com/users
To get an individual user by id:
http://example.com/users/12345
To get all user's bids:
http://example.com/users/12345/bids
To get all user's bids between two dates:
http://example.com/users/12345/bids/?start=01/01/2012&end=01/31/2012
or should it be like this:
http://example.com/users/12345/bids/start/01012012/end/01312012
I'm leaning towards the 1st date range URL as start and end are not entities in the domain. What is the proper way to format a REST URL with a date range?
Thanks,
Tom

http://example.com/users/12345/bids?start=01-01-2012&end=01-31-2012
Have the query parameters on the same "level" as the bids (remove the slash before the question mark). But you would probably want to have support for if they only provide one query parameter. So if they only provided "start" then it would get all bids after that date, or if they only provided "end" it would get all bids before that date.
The reasoning being that query parameters are good for GETting a subset of results from a GET request. They don't go on another level because the next level is usually one specific item with a unique identifier.

I would go with http://example.com/users/12345/bids?start=2012-01-01&end=2012-01-31.
There shouldn't be a slash before the query string.
Avoid using slashes in the query string. It'll be easier that way.

If you use the path separator / to delimit the values you're likely to encounter numerous issues. If you decide you want the start and end dates to allow ISO formats e.g. 2021-10-12T01:00:00.000Z, 2021-10-01T18:00:00.000+05:00, those formats contain characters that will break the URL. Much better to use querystring parameters.
I'd recommend using the querystring and ISO format for dates so your URL will look something like this:
https://example.com/users/12345/bids?start=2022-08-08T00:00:00.000Z&end=2022-08-09T00:00:00.000Z
Your API method that retrieves by date range can then be differentiated from the GET request that retrieves all bids for the user, simply by using a different method signature that expects additional start and end date parameters in the request.

if example.com/users/12345 gets the user with id 12345, then to get all users by id it should be example.com/users with the id included in the response as a relationship. (usually a hyperlink to that resource).
Now to get them by date ranges it should be example.com/users/start=01-01-2012&end=01-31-2012
The 12345 part is the id of an individual user, it's a resource, therefore it should not be included to get the rest of the users.
As the name of the parameter it should be meaningful. start could mean anything, but start_date is more meaninful.

Related

Difference between Created and Created. in SharePoint REST API Call

I call SPO Rest API and in response I found two type of dates. I am not able to find any documentation on their difference especially the one with Dot (.)
Both Dates are shown here
We want to use one with Dot as its in standard format, but not sure about its authenticity. We are using RenderListDataAsStream as end point to get data.
Any documentation of properties coming with Dot(.) will be helpful to understand it. In attached image count is also another same example having dot.
P.S: here are the differnt ways to access them
I think the value of the normal named key (like technical field name) represents the value shown in UI to a user. So it is affected by the regional settings of the web.
The value of the additional "."-key (technical field name plus ".") represents the UTC-0 value in ISO format (like the data is stored in DB internaly).
For example:
"Created": "0;#2022-09-07 06:17:37", // timestamp by Regional Settings
"Created.": "2022-09-07T13:17:37Z", // UTC-0 in ISO format

Proper multi-id syntax when using the custom_file_ids[] query parameter for the CLIO API "contacts" endpoint

What is the correct API syntax for using the custom_file_ids[] query parameter to specify multiple fields (but not all) in the CLIO API contacts result set? I need to specify multiple custom fields. I can get it to work for a single field, but not multiple fields at the same time.
Specifically, how do I specify and delimit the multiple fields? I have tried the following:
custom_file_ids[]=1234567,2345678
custom_file_ids[]=[1234567,2345678]
custom_file_ids[]=(1234567,2345678)
custom_file_ids[]={1234567,2345678}
custom_file_ids[]=1234567:2345678
The API documentation at https://app.clio.com/api/v4/documentation is silent on the list syntax that it expects.
Below is one specific API call I tried (both the actual URL-encoded call, and a decoded one for clarity) using a simple comma-delimited list, but which only returns custom field data for the first ID in the list--not the second. If I enclose the ID list in any kind of brackets (per above), the endpoint returns a 404 error.
https://app.clio.com/api/v4/contacts?custom_field_ids[]=1234567%2C2345678&custom_field_values[4529224]=true&fields=id%2Cname%2Cprimary_address%2Cprimary_work_address%2Cis_client%2Ctype%2C%20primary_email_address%2Cprimary_phone_number%2Ccustom_field_values%7Bid%2Cfield_type%2Cfield_name%2Cvalue%2Ccustom_field%7D
https://app.clio.com/api/v4/contacts?custom_field_ids[]=1234567,2345678&custom_field_values[4529224]=true&fields=id,name,primary_address,primary_work_address,is_client,type,primary_email_address,primary_phone_number,custom_field_values{id,field_type,field_name,value,custom_field}
Try:
custom_file_ids[]=1234567&custom_file_ids[]=2345678
I was able to do this with Contacts Custom Fields by putting custom_field_id[] on the URL as many times as you have IDs.
I hope this helps.

GET a resource filtering by a composite key as query parameter?

I'm thinking the best way to create an endpoint that one of the filters be a composite key.
Per example, we have a rest service to search for orders:
/orders/
We can filter the orders by start and final date:
/orders?dt-start=2017-05-11T17:12Z&dt-final=2017-05-11T17:12Z
Until here, so far so good. But I would like to filter the orders by customer. The customer is identified by his type of document and number of this document.
So, something like this could be possible:
/orders?type=ID&number=123456789
But the type and number are query parameters that only work together, it's a composite key. But using query parameter - like the last example - seems that the API user can do too:
/orders?number=123456789
/orders?type=ID
But not makes sense. Yes, I could return an error in response (bad request) if only one of these parameters were passed, but this is not natural for who are reading the API endpoint.
Another strategy is combine type and number in the same parameter, but I never see this in any API.
/orders?document=ID-12345678
It's odd to me too. I prefer to use separated parameters instead of this.
So, there are a way to use query parameter and solve this problem in a more "elegant" way?
Thanks!
Don't make up a composite key, instead conditionally require the two params. This ins't bad and IMO is much cleaner than creating a composite key which isn't represented by the data (or resource).
I've done this before, so to help illustrate I'll point you to it. This resource is to query for CyberFacts. The query is bound by a date range. To get data, you can do one of two things.
You can say ?today=true, and get the data for today (equivalent to saying ?startDate=2017-05-13&endDate=2017-05-13)
You can use the startDate and endDate query parameters, however if you use one and not the other (eg ?startDate=2017-05-13) you will receive a 400 Bad Request status response on the query and a error message in the response body.
So in this case I've done a few things to make this work
Make a higher priority parameter (today overrides startDate and endDate)
Document the valid behaviors
Provide appropriate error responses
For you only #2 and #3 would be needed, I think. Not knowing all of your use cases, I would suggest using /orders?type=ID&number=123456789 and document that number is a require query param when type=ID, and also include the appropriate error (eg: "You queried for an Order by Type 'ID', however you did not provide a 'number' query parameter")
How about providing a default value for type, (such as 'ID') as a fallback if the type parameter is absent (I'd probably go for the most common/used document type depending on your situation).
While for the number parameter I would enforce it, i.e. by specifying that it is a required parameter (somewhere in the docs?). If absent, return a bad request.

woocommerce customer Fetch with time filter

I am requesting customer data using Rest Api of woocommerce. Woocommerce api documentation says
"All endpoints (except for customer orders) support date filtering via created_at_min and created_at_max as ?filter[] parameters. e.g. ?filter[created_at_min]=2013-12-01".
However, when I am giving date filter in request URL it results in blank response!!
My question is,can the customer data be fetched via date filter in woocommerce.
Thanks.
You can pass Filter with time in REST API of WooCommerce.
Just pass the filter in H:i:s format.
Note : while trying to generate the signature, I found, the URL encoding needs to be done twice because of extra space between DateTime filter criteria. Just encode the clean text once to get RFC3986 encoding, and do it again to generate the signature. Pass the first encoded string and append the generated signature. I saw the filter to be working.

Rational ClearQuest Http request to find defects that have been updated since a specific time?

I am trying to use ClearQuest OSLC CM REST API to write an http request to accomplish the following. I want to get a list (in the XML format) of ClearQuest defects that have been updated since a specified time.
So far I have been able to get a list of all defects from a particular defect family that I'm interested in with the following request (I'm using a sample base URL here):
http://localhost:8080/oslc/cqrest/repo/7.0.0/db/SAMPL/record/?oslc_cm.query=Found_in_Product_Family="MyDefectFamily"&rcm.type=Defect
I also was able to put together an http request that returned a complete timestamp history for a single defect like so:
http://localhost:8080/oslc/cqrest/repo/7.0.0/db/SAMPL/record/16777241-38577895?oslc_cm.properties=id,dbid,history{action_timestamp}
I can show sample xml response for both of those requests if anyone thinks it can be helpful here.
I can't seem to figure out how to write a request that will return a list of defects (id, dbid, timestamp) that contain a timestamp later than say 01/01/2014 00:00:00. Or at least a request that would return all defects where each defect entry would contain the last timestamp in it's history. I think I can get a list of all defects with all timestamps for each defect but I would like just the last timestamp. Taking the last node in the timestamp history doesn't work. Timestamp history doesn't seem to be ordered. Some sort of max function seems to be necessary for such a request.
Can anyone point me in the right direction or tell if what I want is impossible with ClearQuest OSLC CM REST API?
This is what I use in VB.NET:
Dim asOfValue = asOf.ToString("'""'yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z""^^xsd:dateTime'")
Dim upToValue = upTo.ToString("'""'yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z""^^xsd:dateTime'")
Dim where = "cq:history{cq:action_timestamp>=" & asOfValue & " and cq:action_timestamp<=" & upToValue & "}"
Const prefix = "cq=<http://www.ibm.com/xmlns/prod/rational/clearquest/1.0/>"
uri.Query = String.Format("oslc.orderBy=dcterms:identifier&oslc.where={0}&oslc.select={1}&oslc.prefix={2}", where, select, prefix)