I can successfully create a name range using batchUpdate api, however, replaceNameRangeContent gives the following error:
{ "error": { "code": 400, "message": "Invalid requests[0].replaceNamedRangeContent: Named range with ID kix.ydbik9q4xmna contains content that cannot be replaced.", "status": "INVALID_ARGUMENT" } }
The request for this was:
{ "requests": [ { "replaceNamedRangeContent": { "namedRangeId": "kix.ydbik9q4xmna", "text": "" } } ] }
Am I using the API properly? I created the name range giving start/endindex and naming it. It creates the NameRangeId that I used in the replace content post.
There was content in the index range above. However, below is a sample doc structure for an empty doc (with doc styles, etc. omitted). I tried a
{
"requests": [
{
"createNamedRange": {
"range": {
"startIndex": 1,
"endIndex": 2
},
"name": "ApplicantName"
}
}
]
}
followed by
{
"requests": [
{
"replaceNamedRangeContent": {
"namedRangeId": "kix.f7g9w0sr3kyp",
"text": "Applicant Name"
}
}
]
}
and get the same error. But when doing the create named range it would not accept any start/end index besides 1 and 2.
I must not understand the actual intent of named ranges!
Sample:
{
"title": "Test mule",
"body": {
"content": [
{
"endIndex": 1,
"sectionBreak": {
"sectionStyle": {
"columnSeparatorStyle": "NONE",
"contentDirection": "LEFT_TO_RIGHT",
"sectionType": "CONTINUOUS"
}
}
},
{
"startIndex": 1,
"endIndex": 2,
"paragraph": {
"elements": [
{
"startIndex": 1,
"endIndex": 2,
"textRun": {
"content": "\n",
"textStyle": {}
}
}
],
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT",
"direction": "LEFT_TO_RIGHT"
}
}
}
]
}
I can reproduce your error when creating a named range with "startIndex": 0
Mind that indices for paragraphs (and thus text) in Google Docs refer to the position of a character in the text and start with 1.
So if you create a name range specifying the indices correctly, you will not get the error mesage
{ "error": { "code": 400, "message": "Invalid requests[0].replaceNamedRangeContent: Named range with ID kix.ydbik9q4xmna contains content that cannot be replaced.", "status": "INVALID_ARGUMENT" } }
Sample request for creating named ranges:
{
"requests": [
{
"createNamedRange": {
"range": {
"startIndex": 5,
"endIndex": 7
},
"name": "test3"
}
}
]
}
Related
I'm new to API Connect, and I haven't been able to find the correct mapping to pass from an array of objects to an object, evaluating its content.
I explain:
I have as input a json like this:
{
"methodCall": {
"methodName": {
"$": "ThisIsTheMethodName"
},
"params": {
"param": {
"value": {
"array": {
"data": {
"value": {
"struct": {
"member": [
{
"name": {
"$": "message"
},
"value": {
"string": {
"$": "Some text to send to client"
}
}
},
{
"name": {
"$": "phone"
},
"value": {
"string": {
"$": "9876543120124"
}
}
},
{
"name": {
"$": "date"
},
"value": {
"string": {}
}
},
{
"name": {
"$": "appid"
},
"value": {
"string": {
"$": "Application Identificator"
}
}
},
{
"name": {
"$": "costCenter"
},
"value": {
"string": {
"$": "102030"
}
}
},
{
"name": {
"$": "filled"
},
"value": {
"string": {
"$": "filledString"
}
}
}
]
}
}
}
}
}
}
}
}
}
and I need to generate this json output from the mapping:
{
"phoneNumberSMS":"983849780",
"message":"Some text to send to client",
"date": "2022-10-04T15:30:00",
"appId":"Application Identificator",
"costCenter":"102030",
"filled":"filledString" }
I have tried with the following configuration, but without success:
On the YAML
actions:
- set: output.phoneNumberSMS
foreach: input.methodCall.params.param.value.array.data.value.struct.member.value.string
from:
- input.methodCall.params.param.value.array.data.value.struct.member.name.$
- input.methodCall.params.param.value.array.data.value.struct.member.value.string.$
values: |-
var retValue1 = '';
if($(input.methodCall.params.param.value.array.data.value.struct.member.name.$) == 'phone'){
retValue1=input.methodCall.params.param.value.array.data.value.struct.member.value.string.$;
}
retValue1;
I appreciate your help !!
I solve this in two phases of mapping:
Create an array called members, where each node is of type member, which has name and value properties.
This 'members' array is the receiver of the data coming from the request.
In the second phase of the mapping, I took the output variable from the previous mapping (of type members) and assigned it to message.body.
This with the aim of getting rid of the field names with a dollar symbol ($), so the mapping will not give any error for not recognizing it.
Is it possible to use image in the google drive? If yes, how? I have tried using https://drive.google.com/uc?id= + id, but failed.
error": {
"code": 400,
"message": "Failed to fetch image from source_uri: https://drive.google.com/uc?id=xxxxxxxxxxxxxxxxxxxx",
"status": "INVALID_ARGUMENT"
}
Image
{
"contentUri": string,
"altText": string,
"properties": {
object (MediaProperties)
},
"sourceUri": string
}
I use this form
update = {
"requests": [{
{
"createItem": {
"item": {
"imageItem": {
"image": {
"sourceUri": https://drive.google.com/uc...
}
}
},
"location": {
"index": 0
}
},
},
]
}
service_form.forms().batchUpdate(
formId=form_id, body=update).execute()
Doc https://developers.google.com/forms/api/reference/rest/v1/forms/batchUpdate
Problem
If you edit a Google Doc and add TITLE's, HEADING_1's, HEADING_2's etc. and then perform a documents.get request, the JSON response contains headingId's.
Whereas if you use a batchUpdate request with a insertTextRequest and updateParagraphStyleRequest (including, namedStyleType = HEADING_1) and then perform a documents.get request, the JSON response does not contain, headingId's.
I've tried sending the insertTextRequest in a separate batchUpdate request from the updateParagraphStyleRequest. I've also tried sending both together with the insertTextRequest first and last in the requests array as part of the batchUpdate request.
documents.batchUpdate - Request Body:
{
"requests": [
{
"updateParagraphStyle": {
"paragraphStyle": {
"namedStyleType": "HEADING_1"
},
"range": {
"segmentId": "",
"startIndex": 1,
"endIndex": 1
},
"fields": "namedStyleType"
}
},
{
"insertText": {
"location": {
"index": 1,
"segmentId": ""
},
"text": "\nMyText\n"
}
}
]
}
documents.get - Sample Output after the above batchUpdate request:
{
"startIndex": 2,
"endIndex": 9,
"paragraph": {
"elements": [
{
"startIndex": 2,
"endIndex": 9,
"textRun": {
"content": "MyText\n",
"textStyle": {}
}
}
],
"paragraphStyle": {
"namedStyleType": "HEADING_1",
"direction": "LEFT_TO_RIGHT"
}
}
},
documents.get - Sample Output after manually editing the document:
{
"startIndex": 2,
"endIndex": 10,
"paragraph": {
"elements": [
{
"startIndex": 2,
"endIndex": 10,
"textRun": {
"content": "My Text\n",
"textStyle": {}
}
}
],
"paragraphStyle": {
"headingId": "h.3e6t9mhosaga",
"namedStyleType": "HEADING_1",
"direction": "LEFT_TO_RIGHT"
}
}
},
In the documents.get request sample output after manually editing the document there is "headingId": "h.3e6t9mhosaga",.
Why isn't this headingId present after the batchUpdate request?
I have a query where I am using search_type as
GET /test_videos/_search?search_type=dfs_query_then_fetch&explain=true
{
"query": {
"bool": {
"must": {
"multi_match": {
"query": "funny",
"fields": ["title"]
}
}
}
}
}
which works fine and gives the result I want.
I can also specify the explain in the body like this:
GET /test_claim_videos/_search?search_type=dfs_query_then_fetch
{ "explain" : true,
"query": {
"bool": {
"must": {
"multi_match": {
"query": "funny",
"fields": ["title", "asset_name", "description", "tags.name", "asset_group_name.humanized", "credit"]
}
}
}
}
}
But I want to specify the search_type as dfs_then_fetch inside the body.
If I do
GET /test_claim_videos/_search
{ "search_type" : "dfs_query_then_fetch",
"explain" : true,
"query": {
"bool": {
"must": {
"multi_match": {
"query": "funny",
"fields": ["title", "asset_name", "description", "tags.name", "asset_group_name.humanized", "credit"]
}
}
}
}
}
It raises error:
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "Unknown key for a VALUE_STRING in [search_type].",
"line": 1,
"col": 19
}
],
"type": "parsing_exception",
"reason": "Unknown key for a VALUE_STRING in [search_type].",
"line": 1,
"col": 19
},
"status": 400
}
Why can't I specify search type in body here and how to fix that? I need it to be in body as I am using a third party gem chewy which doesn't allow to pass URL.
Unfortunately you have no ability to do it. You can read more in documentation:
Out of the above, the search_type and the request_cache must be passed as query-string parameters.
I'm new to elastic Search. I have a field name clearance in my users table and I'm trying to filter my results based on this.
match: {
clearance: {
query: 'None',
type: 'phrase'
}
}
When I give the above match query i get 3 results. What I'm trying to get is to pass one more string along with None. For eg I want to find the users with clearance None and First Level
I tried this.
multi_match: {
clearance: {
query: 'None OR First Level',
type: 'phrase'
}
}
But ended up in some error. Please Help. Correct me if my question is wrong.
One way would be making clearance as not_analyzed field in the mapping and using terms filter.
Example:
PUT test
{
"mappings": {
"e1":{
"properties": {
"clearance":{
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
Some test data:
PUT test/e1/1
{
"clearance":"None"
}
PUT test/e1/2
{
"clearance":"First Level"
}
PUT test/e1/3
{
"clearance":"Second Level"
}
Now query part:
GET test/e1/_search
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"terms": {
"clearance": [
"None",
"First Level"
],
"execution": "or"
}
}
}
}
}
Result verfication:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "test",
"_type": "e1",
"_id": "1",
"_score": 1,
"_source": {
"clearance": "None"
}
},
{
"_index": "test",
"_type": "e1",
"_id": "2",
"_score": 1,
"_source": {
"clearance": "First Level"
}
}
]
}
}