How to Create Elasticsearch Point in Time (PIT)? - elasticsearch

I'm trying to use the search_after parameter with a point in time (PIT) to paginate search results. This is the documentation section I'm consulting.
I'm making a POST to /my-index/_pit?keep_alive=1m.
The /_pit endpoint only accepts the POST method (if I try GET, it says only POST is accepted), and per the doc, does not take a request body. However, the response I receive is a 400 with this message:
"type": "parse_exception",
"reason": "request body is required"
I can't find any other examples of a /_pit request and I'm just confused by these responses.
Has anyone successfully gotten back a PIT?
In case it's relevant, we have a managed elastic cloud deployment on a standard subscription.

I ended up finding an Elastic forum post indicating that the PIT API is only available as of version 7.10. Sure enough, I tried against a 7.10 deployment and it succeeded as a POST without a body.

So, I feel as though there isn't much guidance on this outside of this particular example and I felt the need to post this for other users that struggled as I did.
If you're using an API tool like postman, you have to update your headers to include Content_Type: application/json, and set your authorization method as what you need (I used basic for password and username).
The index that you should use (my-index-000001 from their example) should be one that you've set up for your search query (right before the _search portion). Leave the body empty and send over the post request and you'll get your id.

Related

How to do a REST POST with Grafana AJAX panel?

I have a SpringBoot API with a POST end-point.
Trying to make a call to end-point from Grafana AJAX panel
It seems to be hitting the end-point but error occurs complaining about missing body.
error: "Bad Request" message: "Required request body is missing: public org.springframework.http.ResponseEntity status: 400
But the request has indeed a body.
Have been looking for possible POST examples for hrs now but no joy, e.g.
https://community.grafana.com/t/using-ajax-plugin-to-make-rest-call/6674
Any tips or solutions would be much appreciated.
Asked this same question on Grafana support forum.
Turns out the plugin/panel in question does not support POST with body.
Indeed, it looks like POST JSON data to backend is not currently supported. There seem to be two related issues here:
https://github.com/ryantxu/ajax-panel/issues/48
https://github.com/ryantxu/ajax-panel/issues/13
You're welcome to share your thoughts there, it looks like this feature request has been added as a future enhancement but I am not sure when that work will be completed. In the meantime, you may need to forego using the AJAX Plugin.
So it's basically useless as my backend API end-point requires a body.
try the new JSON API plugin
https://grafana.com/grafana/plugins/marcusolsson-json-datasource/?tab=changelog
or AjaxPanel plugin for more control

Why are GraphQL queries POST requests even when we are trying to fetch data and not update/submit new data?

I am using Postman to fetch data from my server and when I use a REST call it is a GET request but when I use a GraphQL API call, it needs to be a POST request. Why is it so?
The GraphQL spec is itself transport-agnostic, however the convention adopted by the community has been to utilize POST requests. As pointed out in the comments, some libraries support GET requests. However, when doing so, the query has to be sent as a URL query parameter since GET requests can't have bodies. This can be problematic with bigger queries since you can easily hit a 414 URI Too Long status on certain servers.
The best practice is to always utilize POST requests with a application/json Content-Type.

How can I make a POST request to my Dynamics CRM from Postman?

I am having trouble making a successful HTTPS Post Request to my Dynamics Health 365 CRM.
My goal is to update the "description" field for one specific contact through a Post request.
I am able to make a successful Get request for this specific contact by passing in their contactid to the /contacts path.
get req
However, I am unable to make a Post request on this URI for my CRM site. I am consistently met with a "405 - Method Not Allowed" response.
post req body
Here are the headers I have set. Is there something I am not doing correctly to add content to a certain field for a certain contact?
post req headers
I have also tried to use a Put request but am met with the same 405 error.
I do not know of any guidance on the Dynamics CRM Web API documentation. If there is any content specifically on making Post requests to the Dynamics CRM, I would be more than happy to look to that. I am just looking for any guidance on this because I feel like I have totally hit a wall on this for the last few days. Anything helps, thank you!!
This is for a dynamics CRM portal
I am able to make Get requests on this same URL
I think I need to set the key-value pair of the data I want to update in the body of the request, but that seems not to be correct. Either that, or I am not doing some preliminary step in order to allow for that Post body content to be applied to the contact I am passing.
I want the "description" field in the contact's data to update to the value I set it to. See second image of my post request body.
I recommend you to check the documentation, it has a Postman specific section and some helpful examples.
About your question, updates use the HTTP PATCH verb (POST is used for create operations):
PATCH [Organization URI]/api/data/v9.0/accounts(00000000-0000-0000-0000-000000000001) HTTP/1.1
Content-Type: application/json
OData-MaxVersion: 4.0
OData-Version: 4.0
{
"name": "Updated Sample Account ",
"description": "This is the updated description of the sample account"
}
If you're trying to update a single attribute, you can use PUT as you did but the URL must include the attribute name (/name after the record id in this case):
PUT [Organization URI]/api/data/v9.0/accounts(00000000-0000-0000-0000-000000000001)/name HTTP/1.1
Content-Type: application/json
OData-MaxVersion: 4.0
OData-Version: 4.0
{"value": "Updated Sample Account Name"}
More about update operations on the documentation.
You can also check out the Postman collection template I created some time ago in GitHub.

ServiceNow Scripted REST API GET with Body

I setup a GET scripted rest API. However, when I try to send a GET request with a body, ServiceNow (before it hits my code) complains that GET is not allowed to have a body.
Is there a way to disable this restriction? For now as a temporary workaround, I converted the request into a POST. However, this request does not change any state, so I believe it should be a GET. The request only searches for existing items.
GET is used without body, any configuration of a GET is in the URL and header. A query URL looks like this:
https://instance.service-now.com/api/now/table/problem?sysparm_query=active=true^ORDERBYnumber^ORDERBYDESCcategory&sysparm_limit=1
See the documentation here:
https://developer.servicenow.com/app.do#!/rest_api_doc?v=madrid&id=r_TableAPI-GET
Generally it's OK to use a POST to get data, graphQL does this for example, but i think SNOW is configured for GETs only.

How to specify Content-Type of all responses once in API Blueprint?

In order to satisfy Dredd, I have to write this for every response in my API Blueprint document:
+ Response 201 (application/json; charset=utf-8)
Is there a way to specify the media type ((application/json; charset=utf-8)) once, globally, for every response? This would have cleaned the document a bit.
As far as I know, this is not a supported scenario. I suggest you to file an issue on API Blueprint repository on GitHub to eventually get this feature request evaluated!

Resources