How add styled paragraphs in Google Document by API - google-docs

i have a functional PHP script to add plain text into Google Document, but I'm struggling to insert paragraphs with styles. What I want to achieve is
append heading paragraph with text
append paragraph with hyperlink
There is insertText request but it's not possible to style this text directly in request. And there is not insertParagraph, so everytime when i insert text i cant even make a new line. https://developers.google.com/docs/api/reference/rest/v1/documents/request
It's frustrating how difficult is to work with Google Docs API, it should be much easier to do such basic tasks, please help.

I believe your goal is as follows.
You want to put the texts with the paragraph style and the text style.
You want to achieve this using Google Docs API.
In this case, how about the following sample request body?
Flow:
In order to achieve your goal, when the batchUpdate method is used, as a sample flow, the following flow is used.
Insert Texts.
In this sample, the texts of Sample1\n and Sample2\n are inserted.
Set paragraph style.
In this case, "HEADING_1" and "NORMAL_TEXT" are reflected in the text of Sample1\n and Sample2\n, respectively.
Set text style.
In this case, a hyperlink of https://www.google.com is set to the text of Sample2\n.
When this flow is reflected in a request body, it becomes as follows. Of course, for example, you can change this flow like "1. Insert Sample1\n. 2. Set paragraph style. 3. Insert Sample2\n. 4. Set paragraph style. 5. Set text style.".
Sample request body:
{
"requests": [
{
"insertText": {
"text": "Sample1\n",
"location": {
"index": 1
}
}
},
{
"insertText": {
"text": "sample2\n",
"location": {
"index": 9
}
}
},
{
"updateParagraphStyle": {
"range": {
"startIndex": 1,
"endIndex": 8
},
"paragraphStyle": {
"namedStyleType": "HEADING_1"
},
"fields": "namedStyleType"
}
},
{
"updateParagraphStyle": {
"range": {
"startIndex": 9,
"endIndex": 17
},
"paragraphStyle": {
"namedStyleType": "NORMAL_TEXT"
},
"fields": "namedStyleType"
}
},
{
"updateTextStyle": {
"range": {
"startIndex": 9,
"endIndex": 16
},
"textStyle": {
"link": {
"url": "https://www.google.com"
}
},
"fields": "link"
}
}
]
}
Testing:
When you test this request body with "Try this API" of batchUpdate method of Docs API, you can do it at this link. In this link, the request body has already been set. Please prepare a sample Google Document and set your Google Document ID.
Result:
When this request body is used for a Google Document, the following result is obtained.
References:
InsertTextRequest
UpdateParagraphStyleRequest
UpdateTextStyleRequest

Related

Custom Payload with dialogflow on google plateform

I am trying to sent custom payload in an dialogflot intent. When i am selecting the custom payload option available under google assistant it gives the following predefined json format : -
{
"google": {
}
}
now i am not aware about what i need to put in there in order to get a response from here. Any guide will be helpful
There are some compulsory Keys to be added in Rich Response JSON.
You must have Suggestion Chips and a Simple Response to maintain the follow-up of your Action. AoG rejects any action with missing Suggestion Chips or Follow-Up Response.
Refer to this JSON for Basic Card Response:
{
"payload": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Here's an example of a basic card."
}
},
{
"basicCard": {
"title": "Title: this is a title",
"subtitle": "This is a subtitle",
"formattedText": "This is a basic card. Text in a basic card can include \"quotes\" and\n most other unicode characters including emojis. Basic cards also support\n some markdown formatting like *emphasis* or _italics_, **strong** or\n __bold__, and ***bold itallic*** or ___strong emphasis___ as well as other\n things like line \nbreaks",
"image": {
"url": "https://storage.googleapis.com/actionsresources/logo_assistant_2x_64dp.png",
"accessibilityText": "Image alternate text"
},
"buttons": [
{
"title": "This is a button",
"openUrlAction": {
"url": "https://assistant.google.com/"
}
}
],
"imageDisplayOptions": "CROPPED"
}
},
{
"simpleResponse": {
"textToSpeech": "Which response would you like to see next?"
}
}
]
}
}
}
}
You can refer to the specific Rich Response JSON for your Action in the following Documentation:
https://developers.google.com/assistant/conversational/rich-responses#df-json-basic-card

How to custom page margin in google docs api?

I try to custom my page size and margin but it doesn't working.
I had try to used the auto API in the site but the result still not change the margin.
Is there any change in the google docs api?
Unfortunately, in the current stage, it seems that documentStyle and content cannot be set with the method of documents.create. Ref I confirmed that this has still not been modified. So as the current workaround, how about the following flow?
Flow:
Create new Document using the method of documents.create. In this case, the title can be set.
Set updateDocumentStyle using the method of documents.batchUpdate.
From your question, the request body for documents.batchUpdate is as follows.
{
"requests": [
{
"updateDocumentStyle": {
"documentStyle": {
"marginTop": {
"magnitude": 100,
"unit": "PT"
},
"marginLeft": {
"magnitude": 500,
"unit": "PT"
}
},
"fields": "marginTop,marginLeft"
}
}
]
}
References:
Method: documents.create
Method: documents.batchUpdate
If this was not the direction you want, I apologize.

Is it possible to change verbiage of listAuditEvents?

The current [Envelopes: listAuditEvents] creates the following verbiage for correction:
"eventFields": [
{
"name": "logTime",
"value": "2018-09-18T19:09:01.3603686Z"
},
{
"name": "Source",
"value": "api"
},
{
"name": "UserName",
"value": "Staging"
},
{
"name": "UserId",
"value": "8c57af14-e46a-4965-ae8b-42bb0c29b706"
},
{
"name": "Action",
"value": "Correction Initiated"
},
{
"name": "Message",
"value": "Staging initiated correction"
},
{
"name": "EnvelopeStatus",
"value": "correct"
},
I would like to modify the Message values. I have gone through Docusigns API but I have not found any indication that this is possible.
Has anyone had the same need? and if so were you able to add custom message verbiage for certain events/actions?
Thanks.
It's not possible for you to configure the contents of the API response for the listAuditEvents operation. However, you could (in your code) include logic to parse the API response and based on certain values in the response, substitute values (for purposes in your app) with the verbiage you prefer.
For example, let's say that you have a page in your app that displays the various events that have occurred for an Envelope, but you don't want to display the verbiage "[UserName] initiated correction" as the text in your UI when a user initiates an envelope correction -- instead you want to display the text "[UserName] changed envelope settings." The logic in your code could do something like this psuedo code shows (where auditEvent represents an object within the API response body for the listAuditEvents operation):
if (auditEvent.ActionInitiated == "Correction Initiated") {
displayMessageInUI(auditEvent.UserName + " changed envelope settings.");
}

How to query by array of objects in Contentful

I have an content type entry in Contentful that has fields like this:
"fields": {
"title": "How It Works",
"slug": "how-it-works",
"countries": [
{
"sys": {
"type": "Link",
"linkType": "Entry",
"id": "3S5dbLRGjS2k8QSWqsKK86"
}
},
{
"sys": {
"type": "Link",
"linkType": "Entry",
"id": "wHfipcJS6WUSaKae0uOw8"
}
}
],
"content": [
{
"sys": {
"type": "Link",
"linkType": "Entry",
"id": "72R0oUMi3uUGMEa80kkSSA"
}
}
]
}
I'd like to run a query that would only return entries if they contain a particular country.
I played around with this query:
https://cdn.contentful.com/spaces/aoeuaoeuao/entries?content_type=contentPage&fields.countries=3S5dbLRGjS2k8QSWqsKK86
However get this error:
The equals operator cannot be used on fields.countries.en-AU because it has type Object.
I'm playing around with postman, but will be using the .NET API.
Is it possible to search for entities, and filter on arrays that contain Objects?
Still learning the API, so I'm guessing it should be pretty straight forward.
Update:
I looked at the request the Contentful Web CMS makes, as this functionality is possible there. They use query params like this:
filters.0.key=fields.countries.sys.id&filters.0.val=3S5dbLRGjS2k8QSWqsKK86
However, this did not work in the delivery API, and might only be an internal query format.
Figured this out. I used the following URL:
https://cdn.contentful.com/spaces/aoeuaoeua/entries?content_type=contentPage&fields.countries.sys.id=wHfipcJS6WUSaKae0uOw8
Note the query parameter fields.countries.sys.id

Drupal 7 Search Autocomplete module never loads "suggestions"

I am attempting to use the module Search Autocomplete 7.x-4.0-alpha2.
I have added a form in the "search_autocomplete" configuration section.
It is enabled.
I created a view that returns taxonomy in json format.
Here is an example of the json output from the json view
[{
"value": "aquaculture",
"fields": {
"name_i18n": "aquaculture"
},
"group": {
"group_id": "aquaculture",
"group_name": "aquaculture"
}
}, {
"value": "climate change",
"fields": {
"name_i18n": "climate change"
},
"group": {
"group_id": "climatechange",
"group_name": "climate change"
}
}, {
"value": "coastal development",
"fields": {
"name_i18n": "coastal development"
},
"group": {
"group_id": "coastaldevelopment",
"group_name": "coastal development"
}
}, {
"value": "deforestation",
"fields": {
"name_i18n": "deforestation"
},
"group": {
"group_id": "deforestation",
"group_name": "deforestation"
}
}, {
"value": "extinction",
"fields": {
"name_i18n": "extinction"
},
"group": {
"group_id": "extinction",
"group_name": "extinction"
}
}]
I set the Suggestion Source to be the view. I used the autocomplete feature of it so I know that my "search autocomplete" suggestion source is configured right. The id selector of a form in a different view (not the json taxonomy one) is used. The permissions for the module are correct.
Now, when I load my view that has the search api form I see a little blue circle icon that is circling to the right of the search api form field. It is circling the whole time and no suggestions are ever populated in the search text box.
I know I have the right form configured because if I set a different form id for the "searchautocomplete" configuration and reload the view page, the circling blue circle is missing.
Does anyone have any idea what might be wrong?
UPDATE: I was going to my modules page and saw this error (i wasn't changing anything on the modules page, just going there) and saw the error on the top of the modules page regarding the Search Autocomplete module
Update: I changed the Search Autocomplete configuration section to not point to my json view but point to an outside url, http://google.com. Of course this is not a valid json endpoint, but I wanted to see if I could see it at least attempt to get it's json data from google.com. Watching through firebug has shown that it doesn't even attempt to go to google.com for it's json data. I think something similar is happening with my json views (it's just not even going there for the data).
That was probably due to a bug in the alpha-version? When you configure the JSON Endpoint by using the Views UI, you should see a list of items in the "preview"-section underneath. The items that are listed there should be the ones that appear as suggestions in the search.

Resources