AWS Kendra get _document_body attribute - amazon-web-services

I'm trying to query aws kendra but I need to have the document_body in the ResultItem response.
I tried with the RequestedDocumentAttributes param in the QueryCommand but the result still not contains the document body.
const command = new QueryCommand({
IndexId: 'xxxxxxx',
QueryText: "How to connect to ec2?",
RequestedDocumentAttributes: [
"_document_body",
"_data_source_id",
"_last_updated_at"
]
});
Any suggestion?

_document_body is a special field and Kendra currently does not support returning its entire value in the Query response. Kendra does returns a DocumentExcept for each document ResultItem, which contains the most relevant extract of text in the _document_body.

Related

How to create a collection variable from response in postman

Selecting a value and right-clicking enables me to save it as a Global variable.
But there is no option to save it as a collection variable.
In the environments section as well. I can see Globals but my collection is not available.
But as I go through blogs/ articles online I can see some variables that are scoped to a collection.
Can I know a way to achieve this?
Tests tab is all you need
Considering the Stackoverflow GetUser API for Reference.
NOTE: The below-shown response is a part of the original response.
Response:
{
"items": [
{
"user_type": "registered",
"user_id": 12345678,
}
]
}
In the above response let's say we need user_type, and user_id in another API's URL / body / headers.
Before accessing we need to store these variables after receiving the response. This can be done in the Tests tab in postman request.
const jsonData = JSON.parse(responseBody);
const userType = jsonData?.items?.[0]?.user_type;
const userId = jsonData?.items?.[0]?.user_id;
if(userType){
pm.collectionVariables.set("userType",userType)
}
if(userId){
pm.collectionVariables.set("userId", userId)
}
Points to Note:
Postman tests are written in Javascript.
Optional chaining in line 2,3 is to avoid console errors. Possible Scenario: When API fails and returns an error response.
The IF Statements are to avoid null values in case of an Error Response. If statements are not mandatory. In fact without using if statements you will get to know clearly that something went wrong.
How to use collection variables
Once you make a request with the above tests. Postman IntelliSense suggests available collection variables. ( Refer to the image attached )
We are sending the body as a raw JSON in this Test Endpoint. Note that userType is surrounded by double quotes "" whereas userId is not. ( JSON syntax )

Passing multiple Key Values using Postman Tool for API

It is a basic question from a newbie. I am testing an API using Postman Tool. I am new to using Postman tool. Here are the details:
"custretryatmpt": 1,
"isrefno":true,
"msisdnlist":[{"phoneno":"9XXXXXXXXXX","agentno":"8XXXXXXXXX"}]
I know how to enter the Keys & value for custretryatmpt and isrefno. How to enter Key & Value for
"msisdnlist":[{"phoneno":"9XXXXXXXXXX","agentno":"8XXXXXXXXX"}]
Requesting help...
click body tab and select round row button
select Json right cornar.
paste json below
send
{
"custretryatmpt": 1,
"isrefno": true,
"msisdnlist": [
{
"phoneno": "9XXXXXXXXXX",
"agentno": "8XXXXXXXXX"
}
]
}
Select your request method type (POST)
It's a lot easier to explain it with an image. Also the link https://community.postman.com/t/sending-an-array-as-form-data/4606 from the post can be helpful.

Querying Couchbase Bucket from Postman - Unrecognized parameter in request

Using the Postman tool, I'm trying to query a Couchbase bucket. I'm getting an error response 1065 that there is an "unrecognized parameter in request". The query will work fine within the Couchbase workbench, but I need to be able to do this from Postman.
I'm making a POST request with this body:
{
"statement" : "SELECT * from `myBucketName` where id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee""
}
There error message is:
"msg": "Unrecognized parameter in request: {\n\"statement\" : \"SELECT from `myBuckeyName` where _id "
I think this is just an issue with how my request body is formatted, I'm just new to this and not sure how it should be formatted based off the error I'm getting.
Here's how I did it:
Open Postman
Select POST
Use a URL of http://localhost:8093/query/service
Under "Authorization", use Basic Auth (with the username/password you've created for Couchbase)
Under "Body", select "x-www-form-urlencoded"
Add a KEY of statement and a value of your query
Click SEND
I got a 200 OK response with the results of the query. Screenshot:
You should definitely check out the Couchbase REST API documentation. It uses curl instead of Postman, but that's a translation you'll eventually get used to.

Couch DB - Passing input parameters to view

I am moving from SQL to Couch DB from my web application, my very first application.
While i can not say why I do not like SQL queries, not sure that i don not, the idea of making CURL requests to access my database sound must better than using PHPs PDO .
I have spent a little over a day and a half trying to acquaint myself with the couch DB HTTP API. I can not claim I have throughly read the API , but who thoroughly reads an API before beginning to code. So my, possibly silly, question is - how do I pass an variable other than doc to a map function while making a http request to the view. The API clearly says that a map function only takes a single parameter which is "doc", in which case the function below itself is wrong but I can't find any section in the API that lets me query a database using end-user provided input.
my map function is
function(doc, pid2){
if (doc.pid === pid2)
{
emit(doc._id, doc) ;
}
}
pid2 is a number that will be provided by a front end user.
<?php
$pid2 = file_get_contents(facebook graphi api call_returns a Profile ID) ;
$user_exists = HTTP request to couch DB view to return
in JSON format the list of JSON documents with pid = $pid2
?>
Let your view emit the documents with doc.pid as the key
function(doc) {
emit(doc.pid, doc);
}
and use the key parameter to retrieve the right document:
http://localhost:5984/<database>/_design/<designdoc>/_view/<viewname>?key=<pid2>
This should return all documents with doc.pid === pid2.

CF8 and Salesforce REST API - updating records

I'm trying to do integration with Salesforce using their REST API and CF8.
I got the OAuth bit working, getting data etc but now I'm trying to update some records in Contact table.
First I tought about doing it the "proper" way as their docs say -
Update a record using HTTP PATCH.
But CFHTTP doesn't support PATCH method.
So then I tried running a SOQL query:
UPDATE Contact SET MailingStreet = 'Blah Blah' WHERE Id = '003A000000Zp4ObIAJ'
but here I'm getting
{"message":"unexpected token: UPDATE","errorCode":"MALFORMED_QUERY"}
Does anyone have an idea how to do it?
You can create your own PATCH method if your client supports it, but there is an easier way. From the Force.com REST API Developer's Guide:
If you use an HTTP library that doesn't allow overriding or setting an
arbitrary HTTP method name, you can send a POST request and provide an
override to the HTTP method via the query string parameter
_HttpMethod. In the PATCH example, you can replace the PostMethod line
with one that doesn't use override:
PostMethod m = new PostMethod(url + "?_HttpMethod=PATCH");
In CF9 CFScript, using the method that Paddyslacker already suggested for adding _HttpMethod=PATCH to the URL:
private boolean function patchObject(required string sfid, required string type, required struct obj) {
local.url = variables.salesforceInstance & '/services/data/v' & variables.apiVersion &'/sobjects/' & arguments.type & '/' & arguments.sfid &'?_HttpMethod=PATCH';
local.http = new Http(url=local.url,method='post');
//... convert obj to a json string, add to local.http ...
local.httpSendResult = local.http.send().getPrefix();
}
We have a CF9 CFC that we wrote that wraps most of the REST API that we will be open sourcing soon. I'll come back and link to it when we do.