You can connect your blocks to an external API and then use dynamic data to build a custom design. This will work similarly to Repeater Builder, but instead of using the site’s internal data, you can connect to an external site.

Also, the request can be static (will be processed on each page reload) or Dynamic (you can connect it to Form Submit, ajax loading, any element on page or Interaction Layers)

We added two API Connector options: server side and client side.

Server-side API Connector

To use this type, you need to enable Dynamic/Repeater Output in Element block

Screenshot

Then, you can connect any API. To do this, add API data and click on the fetch button. Data will be fetched and stored in a block.

Screenshot

You must be familiar with how API is working, but don’t worry, even if you don’t understand what is HEADER, BODY, method in API Connection, you still can use many API URLs that don’t require any authorization or extra options. For example, all WordPress sites have enabled REST API but default, and you can put next link

https://site.com/wp-json/wp/v2/product?per_page=25

Add next part to your site link to get the latest 25 products

/wp-json/wp/v2/product?per_page=25

you can also get specific post with ID

/wp-json/wp/v2/posts/25

Greenshift automatically converts JSON format into more structured output and retrieves all attached featured images for posts. In this way, you can get items from external WordPress sites and show them on your site.

This block is working as a constructor. You can put anything inside your block, which will be used as repeated items. For example, you want to get the latest posts with images and titles, so your structure will be next. As you see, we wrapped the item in DIV and added an image and text element. This will group each returned item into a separate block.

Screenshot

Your API can also return only a single item (without an array), so you must enable the Single Item option in API Connector if this is the case. Also, if your API returns a complex array, you can get only a specific field for a response; for this, use the Response field (you can also use array values like field[subfield][0][subsub]

Screenshot

To understand which data is returned from your API, you can also use the Test API function; there is a special panel for this.

Screenshot

Note that Tester Data doesn’t support Dynamic placeholders, so test your API without them first.

I recommend designing a single item without dynamic data, then putting it inside the Dynamic block and connecting the API. Anyway, you can always click on the edit Icon in the block to access the constructor of a single item

Screenshot

Now, click on items in a single item area and connect static data to dynamic. For this, enable the dynamic option in each field mapped with API data and select Repeater data as source, then select which field you want to map. All available fields from API will be visible as Repeater Field.

Screenshot

You can have also nested arrays in your data, you also can get them, for this, add another Dynamic or Repeater block inside, also connect it to Repeater source and field where you nested array is saved. You can also use array-like values for repeater field, like field[subfield]

Dynamic placeholders for Server Side API

API Connector supports Dynamic Placeholders in all fields (link, body, header). This means you can have dynamic requests based on your dynamic site options. For example, you can retrieve User meta field {{USER_META:field}} and put this placeholder in body area, this will send request with dynamic data of current user of your site.

Screenshot

Placeholders have self-explanatory names. But there are a few specific ones; please continue to read.

Dynamic Ajax Loading

By default, API Connector requests endpoints on page loading, but you can enable the Ajax option. In this case, it will be loaded on specific interactions.

For example, you can use it on Form Submit. There are special placeholders to use dynamic requests.

Form Submit trigger

You can add a form with the Form Element block, but any other form plugin will work also.

So, enable the Form trigger. I used the selector “.submitform” which means I will use the form with the class “submitform”

Now, add Form Element on the page and add class submitform to it. Add Input with name “name” and id “name”. Now, in your API fields, you can use placeholder {{FORM:name|test}}

Screenshot

This will dynamically add the value from Input “name” to your API request. If this field is not available, it will use fallback “text.” In this way, you can create filters or dynamic API requests on your site based on user input in the form.

Dynamic AJAX loading and Interaction Layers

You can also enable the Custom Interaction trigger for more control over triggers.

Copy provided ID. Now, use the Interaction layer and select any trigger. Add “Dynamic API Call” as an action and put the copied ID. Now, the API call will be controlled by your custom trigger.

For example, you can call an external API request when the user clicks a button or reaches the scroll position.

Another prevalent scenario is to create intervals with API calls. For this, we added a Loop trigger in interaction layers. Use it and add an interval and the number of calls. I recommend adding an interval bigger than 4-5 seconds so the API can return data before the subsequent call runs.

API connector also stores the index of calls on the page. You can use it with a combination with placeholder {{INCREMENT:1}}

For example, you can use the offset parameter in the WordPress REST API link. Like

https://woocommerce.greenshiftwp.com/wp-json/wp/v2/product?per_page=1&offset=1

Now, we can modify it to next.

https://woocommerce.greenshiftwp.com/wp-json/wp/v2/product?per_page=1&offset={{INCREMENT:1}}

Now, on each new sequential call on the page, the offset parameter will increase by 1. So, on the first loading, it will be offset=0, on the second offset=1, etc.

This can be used to get dynamic data individually instead of all together.

Another functional placeholder can be {{RANDOM:0-100}}, which means that a random value between 0 and 100 will be used for each call. Or {{RANDOM:blue|grey|yellow}}, which means one of the provided values will be used on each call.

Custom Preloader and animation for dynamically added items

You can use also custom preloader. For this, create any block and add class to it. Then, use this class in custom selector option

Screenshot

On loading state, this selector will have .active class. You can use it to add animation to preloader. For this, put any block inside custom loader block. Enable Animation in it and use option to activate animation on .active class

Screenshot

A similar approach can be used for newly added items for result output. You can use class .result-loaded with animation presets

Screenshot

Also, the container where results are added has class .loading – while loading and .loaded and .active – after adding results. You can use them to add extra conditions.

Pagination in ajax responses

You can also have pagination when you use dynamic ajax. For this, create a block and add a unique class to it. Then, add this class in option of Connector

Screenshot

Then put any button inside this container and add Animation preset with .active class trigger the same as we did for custom preloader. Please, note that this feature will work if your API pagination is using “page” parameter to get page number

WordPress Authentification

For specific operations, you may need to have WP authentication, this is where usually many fails, because there is no good documentation how it works. One day, it took me also few hours to understand how it works, so I want to save your time.

When you do WP API connections that require authentications, like Submiting Post to database, you must use WordPress App Password. It’s not the same as your real password. You must create Application Password in admin panel in Profile page

Screenshot

Once you added and copied this password, you must encode the pair to use it in the Authentification header. For this, put your details in this way

UserName:Password

and encode this on site. After encoding, you will get a long piece of text. This text you must use in the Head part of API in this format

Screenshot

This field has Autocomplete, so select key as “Authorization” and the Value as “Basic yourEncodedCode”

Where you must put the code that you got from the previous step. Don’t forget to put space between code and Basic

Client Side API Connector

The server side uses WordPress’s Rest API and does all the jobs on your server. It can also use dynamic data stored on your site.

The client-side API uses only the Javascript fetch function and performs tasks only in the browser. It has no connection to the WordPress database. At the same time, as it’s a 100% front-end solution, it has more options to interact with elements on the page.

Attention. Client-side APIs are always public, so users can see your API keys. Use them only for public APIs or on restricted parts of your site. If you need to hide all processing and keys, the Server-Side type is better.

Similar to Server Side API, you can also create a custom design for retrieved results, but Selector Maping does this. For this, you add a special, unique class to each item that you want to connect to the results and provide a key to the results that will be mapped. Let’s dive into the details.

The Client Side works from Interaction Layers, so you must add any block with interaction layers. For example, I added a Form element with two inputs and a Button. When the button is clicked, I want to take the value from my inputs and send it to the request.

Screenshot

I added a special class “search-input-api” to the first input and “color-select-api” to select. Now, I added an interaction layer to the button and enabled click as a trigger and API Connector as an action.

Screenshot

See that I used {{VALUE:.search-input-api}} as part of URL. It’s a dynamic placeholder that makes a dynamic replacement. In this case, it’s replaced by a value from the .search-input-API field on the frontend. Click on “Dynamic Placeholders” link in Body field to see list of available placeholders, you can use them in any of field. Let’s review them

Screenshot

Dynamic Placeholders for Client Side API

{{TEXT:.selector}} – will use text from selector. Difference from VALUE is that VALUE will get value from input field, while TEXT can be used to get any text value from any element on page

{{VALUE:.selector}} – works only for form element inputs

{{COOKIE:cookie_name}} – takes cookie by key

{{STORAGE:storage_name}} takes storage value by key

{{ATTR:attribute_name|selector}} – can take special attribute value instead of value. For example, you have <div data-src=”https://link.com” class=”mylink”>My link</a>. And you want to get data-src value. Use {{ATTR:data-src|.mylink}}

{{SESSION_ID}} – on each page loading, API connector can have special ID that you can use for API. This is required, for example, for chat-like API requests when you need ongoing requests that is stored as one chat

{{FORMDATA:.selector}} – this will use FormData API so practically, you can send all fields of specific form to your API if it’s supporting FormData

Result template for Client Side API

With Interaction Layers, you can send requests and design their returned values. For this, create two blocks, it is better to use DIV and add classes. One will be a block where we store our output results design, and one will be used as a container where we will send results to show them after retrieval.

So, on block where we store results design, it should be on page but must be hidden. Script will use this block as source to build constructor for results. Add special class in block so it will be hidden on frontend

Screenshot

Now, put any kind of static blocks inside it and style them as you want. Values that you use will also be used as Fallback values in case the API request doesn’t have value for a specific key. Put unique classes to all elements that you plan to have dynamic value replacement from API

For Result Container, you can use any block, there is no special requirement for this. It will be used to show results, so put it somewhere near your button.

Put both selectors to proper fields in Connector API.

Screenshot

Next part is to map all our fields to API results. For this, you must add selector of field that you want to map and key from API. Value from API will replace value of element. If it’s link, then it will be added to href attribute. If it’s image or video, then it will be added to src attribute. For other scenarios, text value will be replaced

Screenshot

There is also Test API panel, so test what is returned in your API (do this without placeholders first). When API is tested, you can also see them in Auto Complete when you select key. You can also use array like values. For example, data is

{urls: 
   {
      "small": ...,
      "big": ...
   }
}

as you see, it’s not saved directly in “URLs” key. But you can use urls[small] to retrieve such values.

Custom Loader

Client Side doesn’t have default loader icon, so you need to add it if you want to show some animation when API is loading. For this create any block, add unique class. Use this class in custom loader option. Put anything you want inside. For example, rotating icon. When API is loaded, this block will have class “.active”. You can use Animation preset to show block on .active class as explained before.

Animation for result appearance

As well as in Server Side API, when result container is loading, it has class loading, when it’s ready, it has class .active and .loaded. So, you can use Animation presets and on .active class condition

Interactions in results

You can add also interaction layers inside Result blocks. They will be executed after results are ready on page

Hook for developers

You can use also special JS hook for Client Side API

document.addEventListener("GSPB_API_RESPONSE", (event) => {
    const { resultElem, responseData } = event.detail;
    console.log("Received API response:", responseData);
    console.log("Result Element:", resultElem);
});

Chat Type and Streaming responses

When you use the Client Side, you can also enable Chat mode and streaming. Chat mode allows you to send ongoing requests related to previous requests. It’s usually used in Chats when you need to send previous discussions to the AI model so the agent can understand the context.

I will explain an example of building chat with OPEN AI API.

If you check their documentation you will see that you need to send an object with roles, something like this.

   "messages": [
      {
        "role": "developer",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "Hello!"
      },
      {
        "role": "assistant",
        "content": "How are you?"
      }
    ]

So, on each user input, you need to attach new.

      {
        "role": "user",
        "content": "Hello!"
      },

Then, get a response from the model, and next time, attach this response to chat with the role “assistant”.

Quite a complex task, but Greenshift will do it for you

So, at first, you need to add initial data for the body, it will be

{
  "model": "gpt-4o",
  "messages": [
    {
      "role": "system",
      "content": [
        {
          "type": "text",
          "text": "You are a helpful assistant that can answer questions and help with tasks."
        }
      ]
    }
  ]
}

Here, we define the messages object and add the initial system role.

We need to provide a key from the body where ongoing inputs will be stored. It’s our Append Field because each new user request will add a new item in this key. In our case, it’s “messages”

Screenshot

Now, I need to provide a User Message JSON format

{
  "role": "user",
  "content": [
    {
      "type": "text",
      "text": "{{VALUE:.search-input-api}}"
    }
  ]
}

See that I used {{VALUE:search-input-api}} It’s a special placeholder that shows the plugin to get value from .search-input-api element from the page and use its value to add the object to messages

I will need to get a response from the system and save it for assistant messages. So I used

{
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "{{RESPONSE}}"
    }
  ]
}

{{RESPONSE}} is a placeholder that will be dynamically replaced by the response data of Assistant from a previous API call. You also need to add a specific field where the Assistant response text is saved because usually, the Response has many keys. In open AI, the response is added in the next format

Screenshot

See, it’s too much extra data here, but we need to get value only from the first item in “choices”, so our field is choices[0][message]

Screenshot

That’s all. But we need to use also Interaction layers to improve Chat style. For example, we need on each click of Sending button, we add user input value to our chat container. Hopefully, Interaction Layer has everything for this kind of functions. You can download everything from our library and use as base for your custom chats.

Streaming

Your responses can also be streamed. Streaming allows you to get results from the server immediately, chunk by chunk, and show them on the page. In this way, the user does not need to wait for the full answer to show up on the page because the results will be added faster and typed on the page. Usually, chats use streaming.

You don’t need to worry how it’s made, Greenshift will take care of everything for you.

When you use custom response template, each element that you add for mapping will have “loading” class before getting data and “loaded”, “active” class if value will be retrieved while streaming. You can use it to show or hide specific items depending on fact if there is data in the streaming response.

API Presets

There are few integrated API presets, that you can use for practical tasks.

Screenshot

Click on API Presets link for this.

Currently we added two ready presets:

WordPress Site Latest Items

This is for easier generation of WordPress REST link. Put there any WordPress site and select post type to show. Now, you can get items from external site

Google Sheet/CSV

You can use Google Sheet link or csv link as source. Plugin will automatically convert data to be API source.

It’s possible to convert each row as item and each column as item

Examples

Please check our library for three examples of API Connector

Client Side API

Server Side API

Custom Chat for Open AI

Copy this post’s content
<!-- wp:paragraph -->
<p>You can connect <span style="box-sizing: border-box; margin: 0px; padding: 0px;">your blocks to an external API and then use dynamic data to build a custom design. This will work similarly to <a href="https://greenshiftwp.com/repeater-builder/" target="_blank">Repeater Builder</a>, but instead of using the site's internal data, you can connect to a</span>n external site.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Also, the request can be static (will be processed on each page reload) or Dynamic (you can connect it to Form Submit, ajax loading, any element on page or <a href="https://greenshiftwp.com/documentation/greenshift-extra/interaction-panels/" data-type="documentation" data-id="3662">Interaction Layers</a>)</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>We added two API Connector options: server side and client side.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 class="wp-block-heading" id="server-side-api-connector">Server-side API Connector</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>To use this type, you need to enable Dynamic/Repeater Output in <a href="https://greenshiftwp.com/element-tag-block/" data-type="post" data-id="4576">Element block</a></p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5579,"width":"300px","sizeSlug":"full","linkDestination":"none","style":{"border":{"radius":"10px"}}} -->
<figure class="wp-block-image size-full is-resized has-custom-border"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5579" style="border-radius:10px;width:300px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Then, you can connect any API. To do this, add API data and click on the fetch button. Data will be fetched and stored in a block.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5616,"width":"300px","sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full is-resized"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5616" style="width:300px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>You must be familiar with how API is working, but don't worry, even if you don't understand what is HEADER, BODY, method in API Connection, you still can use many API URLs that don't require any authorization or extra options. For example, all Wordpress sites have enabled REST API but default, and you can put next link</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>https://site.com/wp-json/wp/v2/product?per_page=25</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Add next part to your site link to get the latest 25 products</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>/wp-json/wp/v2/product?per_page=25</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>you can also get specific post with ID</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>/wp-json/wp/v2/posts/25</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Greenshift automatically converts JSON format into more structured output and retrieves all attached featured images for posts. In this way, you can get items from external WordPress sites and show them on your site.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This block is working as a constructor. You can put anything inside your block, which will be used as repeated items. For example, you want to get the latest posts with images and titles, so your structure will be next. As you see, we wrapped the item in DIV and added an image and text element. This will group each returned item into a separate block.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5589,"width":"400px","sizeSlug":"full","linkDestination":"none","style":{"border":{"radius":"10px"}}} -->
<figure class="wp-block-image size-full is-resized has-custom-border"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5589" style="border-radius:10px;width:400px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Your API can also return only a single item (without an array), so you must enable the Single Item option in API Connector if this is the case. Also, if your API returns a complex array, you can get only a specific field for a response; for this, use the Response field (you can also use array values like field[subfield][0][subsub]</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5590,"width":"300px","sizeSlug":"full","linkDestination":"none","style":{"border":{"radius":"10px"}}} -->
<figure class="wp-block-image size-full is-resized has-custom-border"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5590" style="border-radius:10px;width:300px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>To understand which data is returned from your API, you can also use the Test API function; there is a special panel for this.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5615,"width":"300px","sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full is-resized"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5615" style="width:300px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:greenshift-blocks/infobox {"id":"gsbp-4569498","type":"noticelight"} -->
<div class="wp-block-greenshift-blocks-infobox gspb_infoBox gspb_infoBox-id-gsbp-4569498" id="gspb_infoBox-id-gsbp-4569498"><div class="gs-box noticelight_type icon_type"><div class="gs-box-icon"><svg x="0px" y="0px" viewBox="0 0 486.463 486.463"> <g> <g> <path d="M243.225,333.382c-13.6,0-25,11.4-25,25s11.4,25,25,25c13.1,0,25-11.4,24.4-24.4 C268.225,344.682,256.925,333.382,243.225,333.382z"></path> <path d="M474.625,421.982c15.7-27.1,15.8-59.4,0.2-86.4l-156.6-271.2c-15.5-27.3-43.5-43.5-74.9-43.5s-59.4,16.3-74.9,43.4 l-156.8,271.5c-15.6,27.3-15.5,59.8,0.3,86.9c15.6,26.8,43.5,42.9,74.7,42.9h312.8 C430.725,465.582,458.825,449.282,474.625,421.982z M440.625,402.382c-8.7,15-24.1,23.9-41.3,23.9h-312.8 c-17,0-32.3-8.7-40.8-23.4c-8.6-14.9-8.7-32.7-0.1-47.7l156.8-271.4c8.5-14.9,23.7-23.7,40.9-23.7c17.1,0,32.4,8.9,40.9,23.8 l156.7,271.4C449.325,369.882,449.225,387.482,440.625,402.382z"></path> <path d="M237.025,157.882c-11.9,3.4-19.3,14.2-19.3,27.3c0.6,7.9,1.1,15.9,1.7,23.8c1.7,30.1,3.4,59.6,5.1,89.7 c0.6,10.2,8.5,17.6,18.7,17.6c10.2,0,18.2-7.9,18.7-18.2c0-6.2,0-11.9,0.6-18.2c1.1-19.3,2.3-38.6,3.4-57.9 c0.6-12.5,1.7-25,2.3-37.5c0-4.5-0.6-8.5-2.3-12.5C260.825,160.782,248.925,155.082,237.025,157.882z"></path> </g> </g> </svg></div><div class="gs-box-text"><!-- wp:paragraph -->
<p>Note that Tester Data doesn't support Dynamic placeholders, so test your API without them first.</p>
<!-- /wp:paragraph --></div></div></div>
<!-- /wp:greenshift-blocks/infobox -->

<!-- wp:paragraph -->
<p>I recommend designing a single item without dynamic data, then putting it inside the Dynamic block and connecting the API. Anyway, you can always click on the edit Icon in the block to access the constructor of a single item</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5591,"sizeSlug":"full","linkDestination":"none","style":{"border":{"radius":"10px"}}} -->
<figure class="wp-block-image size-full has-custom-border"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5591" style="border-radius:10px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Now, click on items in a single item area and connect static data to dynamic. For this, enable the dynamic option in each field mapped with API data and select Repeater data as source, then select which field you want to map. All available fields from API will be visible as Repeater Field.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5592,"width":"300px","sizeSlug":"full","linkDestination":"none","style":{"border":{"radius":"10px"}}} -->
<figure class="wp-block-image size-full is-resized has-custom-border"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5592" style="border-radius:10px;width:300px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:greenshift-blocks/infobox {"id":"gsbp-e3177d2"} -->
<div class="wp-block-greenshift-blocks-infobox gspb_infoBox gspb_infoBox-id-gsbp-e3177d2" id="gspb_infoBox-id-gsbp-e3177d2"><div class="gs-box info_type icon_type"><div class="gs-box-icon"><svg x="0px" y="0px" viewBox="0 0 512 512"> <g><g> <path d="M256,0C114.497,0,0,114.507,0,256c0,141.503,114.507,256,256,256c141.503,0,256-114.507,256-256 C512,114.497,397.492,0,256,0z M256,472c-119.393,0-216-96.615-216-216c0-119.393,96.615-216,216-216 c119.393,0,216,96.615,216,216C472,375.393,375.384,472,256,472z"></path> </g> </g> <g> <g> <path d="M256,214.33c-11.046,0-20,8.954-20,20v128.793c0,11.046,8.954,20,20,20s20-8.955,20-20.001V234.33 C276,223.284,267.046,214.33,256,214.33z"></path> </g> </g> <g> <g> <circle cx="256" cy="162.84" r="27"></circle> </g> </g> </svg></div><div class="gs-box-text"><!-- wp:paragraph -->
<p>You can have also nested arrays in your data, you also can get them, for this, add another Dynamic or Repeater block inside, also connect it to Repeater source and field where you nested array is saved. You can also use array-like values for repeater field, like field[subfield]</p>
<!-- /wp:paragraph --></div></div></div>
<!-- /wp:greenshift-blocks/infobox -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="dynamic-placeholders-for-server-side-api">Dynamic placeholders for Server Side API</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>API Connector supports <a href="https://greenshiftwp.com/dynamic-placeholders/" data-type="post" data-id="5575">Dynamic Placeholders</a> in all fields (link, body, header). This means you can have dynamic requests based on your dynamic site options. For example, you can retrieve User meta field {{USER_META:field}} and put this placeholder in body area, this will send request with dynamic data of current user of your site. </p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5617,"width":"300px","sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full is-resized"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5617" style="width:300px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Placeholders have self-explanatory names. But there are a few specific ones; please continue to read.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="dynamic-ajax-loading">Dynamic Ajax Loading</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>By default, API Connector requests endpoints on page loading, but you can enable the Ajax option. In this case, it will be loaded on specific interactions. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>For example, you can use it on Form Submit. There are special placeholders to use dynamic requests.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="form-submit-trigger">Form Submit trigger</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>You can add a form with the Form Element block, but any other form plugin will work also.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>So, enable the Form trigger. I used the selector ".submitform" which means I will use the form with the class "submitform"</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5598,"width":"350px","sizeSlug":"full","linkDestination":"none","style":{"border":{"radius":"10px"}}} -->
<figure class="wp-block-image size-full is-resized has-custom-border"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/image-4.png" alt="" class="wp-image-5598" style="border-radius:10px;width:350px"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Now, add Form Element on the page and add class submitform to it. Add Input with name "name" and id "name". Now, in your API fields, you can use placeholder {{FORM:name|test}} </p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5618,"width":"300px","sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full is-resized"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5618" style="width:300px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>This will dynamically add the value from Input "name" to your API request. If this field is not available, it will use fallback "text." In this way, you can create filters or dynamic API requests on your site based on user input in the form.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="dynamic-ajax-loading-and-interaction-layers">Dynamic AJAX loading and Interaction Layers</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>You can also enable the Custom Interaction trigger for more control over triggers. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Copy provided ID. Now, use the Interaction layer and select any trigger. Add "Dynamic API Call" as an action and put the copied ID. Now, the API call will be controlled by your custom trigger.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>For example, you can call an external API request when the user clicks a button or reaches the scroll position.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Another prevalent scenario is to create intervals with API calls. For this, we added a Loop trigger in interaction layers. Use it and add an interval and the number of calls. I recommend adding an interval bigger than 4-5 seconds so the API can return data before the subsequent call runs.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>API connector also stores the index of calls on the page. You can use it with a combination with placeholder {{INCREMENT:1}}</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>For example, you can use the offset parameter in the WordPress REST API link. Like</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>https://woocommerce.greenshiftwp.com/wp-json/wp/v2/product?per_page=1&offset=1</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Now, we can modify it to next.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>https://woocommerce.greenshiftwp.com/wp-json/wp/v2/product?per_page=1&offset={{INCREMENT:1}}</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Now, on each new sequential call on the page, the offset parameter will increase by 1. So, on the first loading, it will be offset=0, on the second offset=1, etc.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This can be used to get dynamic data individually instead of all together. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Another functional placeholder can be {{RANDOM:0-100}}, which means that a random value between 0 and 100 will be used for each call. Or {{RANDOM:blue|grey|yellow}}, which means one of the provided values will be used on each call.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="custom-preloader-and-animation-for-dynamically-added-items">Custom Preloader and animation for dynamically added items</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>You can use also custom preloader. For this, create any block and add class to it. Then, use this class in custom selector option</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5645,"width":"300px","sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full is-resized"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5645" style="width:300px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>On loading state, this selector will have .active class. You can use it to add animation to preloader. For this, put any block inside custom loader block. Enable Animation in it and use option to activate animation on .active class</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5646,"width":"300px","sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large is-resized"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5646" style="width:300px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>A similar approach can be used for newly added items for result output. You can use class .result-loaded with animation presets</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5647,"width":"300px","sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large is-resized"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5647" style="width:300px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Also, the container where results are added has class .loading - while loading and .loaded and .active - after adding results. You can use them to add extra conditions.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="pagination-in-ajax-responses">Pagination in ajax responses</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>You can also have pagination when you use dynamic ajax. For this, create a block and add a unique class to it. Then, add this class in option of Connector</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5656,"width":"300px","sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full is-resized"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5656" style="width:300px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Then put any button inside this container and add Animation preset with .active class trigger the same as we did for custom preloader. Please, note that this feature will work if your API pagination is using "page" parameter to get page number</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="wordpress-authentification">WordPress Authentification</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>For specific operations, you may need to have WP authentication, this is where usually many fails, because there is no good documentation how it works. One day, it took me also few hours to understand how it works, so I want to save your time.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>When you do WP API connections that require authentications, like Submiting Post to database, you must use Wordpress App Password. It's not the same as your real password. You must create Application Password in admin panel in Profile page</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5661,"width":"500px","sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large is-resized"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5661" style="width:500px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Once you added and copied this password, you must encode the pair to use it in the Authentification header. For this, put your details in this way</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>UserName:Password</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><span style="box-sizing: border-box; margin: 0px; padding: 0px;">and encode this on <a href="https://www.base64encode.org/" target="_blank">site.</a> After encoding, you will get a long piece of text.</span> This text you must use in the Head part of API in this format</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5662,"width":"300px","sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full is-resized"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5662" style="width:300px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>This field has Autocomplete, so select key as "Authorization" and the Value as "Basic yourEncodedCode"</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Where you must put the code that you got from the previous step. Don't forget to put space between code and Basic</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 class="wp-block-heading" id="client-side-api-connector">Client Side API Connector</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The server side uses WordPress's Rest API and does all the jobs on your server. It can also use dynamic data stored on your site.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The client-side API uses only the Javascript fetch function and performs tasks only in the browser. It has no connection to the WordPress database. At the same time, as it's a 100% front-end solution, it has more options to interact with elements on the page.</p>
<!-- /wp:paragraph -->

<!-- wp:greenshift-blocks/infobox {"id":"gsbp-0c14264","type":"noticelight"} -->
<div class="wp-block-greenshift-blocks-infobox gspb_infoBox gspb_infoBox-id-gsbp-0c14264" id="gspb_infoBox-id-gsbp-0c14264"><div class="gs-box noticelight_type icon_type"><div class="gs-box-icon"><svg x="0px" y="0px" viewBox="0 0 486.463 486.463"> <g> <g> <path d="M243.225,333.382c-13.6,0-25,11.4-25,25s11.4,25,25,25c13.1,0,25-11.4,24.4-24.4 C268.225,344.682,256.925,333.382,243.225,333.382z"></path> <path d="M474.625,421.982c15.7-27.1,15.8-59.4,0.2-86.4l-156.6-271.2c-15.5-27.3-43.5-43.5-74.9-43.5s-59.4,16.3-74.9,43.4 l-156.8,271.5c-15.6,27.3-15.5,59.8,0.3,86.9c15.6,26.8,43.5,42.9,74.7,42.9h312.8 C430.725,465.582,458.825,449.282,474.625,421.982z M440.625,402.382c-8.7,15-24.1,23.9-41.3,23.9h-312.8 c-17,0-32.3-8.7-40.8-23.4c-8.6-14.9-8.7-32.7-0.1-47.7l156.8-271.4c8.5-14.9,23.7-23.7,40.9-23.7c17.1,0,32.4,8.9,40.9,23.8 l156.7,271.4C449.325,369.882,449.225,387.482,440.625,402.382z"></path> <path d="M237.025,157.882c-11.9,3.4-19.3,14.2-19.3,27.3c0.6,7.9,1.1,15.9,1.7,23.8c1.7,30.1,3.4,59.6,5.1,89.7 c0.6,10.2,8.5,17.6,18.7,17.6c10.2,0,18.2-7.9,18.7-18.2c0-6.2,0-11.9,0.6-18.2c1.1-19.3,2.3-38.6,3.4-57.9 c0.6-12.5,1.7-25,2.3-37.5c0-4.5-0.6-8.5-2.3-12.5C260.825,160.782,248.925,155.082,237.025,157.882z"></path> </g> </g> </svg></div><div class="gs-box-text"><!-- wp:paragraph -->
<p>Attention. Client-side APIs are always public, so users can see your API keys. Use them only for public APIs or on restricted parts of your site. If you need to hide all processing and keys, the Server-Side type is better.</p>
<!-- /wp:paragraph --></div></div></div>
<!-- /wp:greenshift-blocks/infobox -->

<!-- wp:paragraph -->
<p>Similar to Server Side API, you can also create a custom design for retrieved results, but Selector Maping does this. For this, you add a special, unique class to each item that you want to connect to the results and provide a key to the results that will be mapped. Let's dive into the details.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><span style="box-sizing: border-box; margin: 0px; padding: 0px;">The Client Side works from <a href="https://greenshiftwp.com/documentation/greenshift-extra/interaction-panels/" target="_blank">Interaction Layers</a>, so you must add any block with interaction layers. For example, I added a Form element with two inputs and a Button. When the button is clicked, I want to take the value from my inputs and send it to the </span>request.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5648,"width":"400px","sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full is-resized"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5648" style="width:400px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>I added a special class "search-input-api" to the first input and "color-select-api" to select. Now, I added an interaction layer to the button and enabled click as a trigger and API Connector as an action.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5649,"width":"300px","sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large is-resized"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5649" style="width:300px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>See that I used {{VALUE:.search-input-api}} as part of URL. It's a dynamic placeholder that makes a dynamic replacement. In this case, it's replaced by a value from the .search-input-API field on the frontend. Click on "Dynamic Placeholders" link in Body field to see list of available placeholders, you can use them in any of field. Let's review them</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5650,"width":"300px","sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full is-resized"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5650" style="width:300px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="dynamic-placeholders-for-client-side-api">Dynamic Placeholders for Client Side API</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>{{TEXT:.selector}} - will use text from selector. Difference from VALUE is that VALUE will get value from input field, while TEXT can be used to get any text value from any element on page</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>{{VALUE:.selector}} - works only for form element inputs</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>{{COOKIE:cookie_name}} - takes cookie by key</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>{{STORAGE:storage_name}} takes storage value by key</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>{{ATTR:attribute_name|selector}} - can take special attribute value instead of value. For example, you have <div data-src="https://link.com" class="mylink">My link</a>. And you want to get data-src value. Use {{ATTR:data-src|.mylink}}</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>{{SESSION_ID}} - on each page loading, API connector can have special ID that you can use for API. This is required, for example, for chat-like API requests when you need ongoing requests that is stored as one chat</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>{{FORMDATA:.selector}} - this will use <a href="https://developer.mozilla.org/en-US/docs/Web/API/FormData">FormData API</a> so practically, you can send all fields of specific form to your API if it's supporting FormData</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="result-template-for-client-side-api">Result template for Client Side API</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>With Interaction Layers, you can send requests and design their returned values. For this, create two blocks, it is better to use DIV and add classes. One will be a block where we store our output results design, and one will be used as a container where we will send results to show them after retrieval. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>So, on block where we store results design, it should be on page but must be hidden. Script will use this block as source to build constructor for results. Add special class in block so it will be hidden on frontend</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5651,"width":"300px","sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full is-resized"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5651" style="width:300px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Now, put any kind of static blocks inside it and style them as you want. Values that you use will also be used as Fallback values in case the API request doesn't have value for a specific key. Put unique classes to all elements that you plan to have dynamic value replacement from API</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>For Result Container, you can use any block, there is no special requirement for this. It will be used to show results, so put it somewhere near your button. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Put both selectors to proper fields in Connector API. </p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5652,"width":"300px","sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full is-resized"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5652" style="width:300px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Next part is to map all our fields to API results. For this, you must add selector of field that you want to map and key from API. Value from API will replace value of element. If it's link, then it will be added to href attribute. If it's image or video, then it will be added to src attribute. For other scenarios, text value will be replaced</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5653,"width":"300px","sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full is-resized"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5653" style="width:300px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>There is also Test API panel, so test what is returned in your API (do this without placeholders first). When API is tested, you can also see them in Auto Complete when you select key. You can also use array like values. For example, data is </p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>{urls: 
   {
      "small": ...,
      "big": ...
   }
}</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>as you see, it's not saved directly in "URLs" key. But you can use urls[small] to retrieve such values.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="custom-loader">Custom Loader</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Client Side doesn't have default loader icon, so you need to add it if you want to show some animation when API is loading. For this create any block, add unique class. Use this class in custom loader option. Put anything you want inside. For example, rotating icon. When API is loaded, this block will have class ".active". You can use Animation preset to show block on .active class as explained before. </p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="animation-for-result-appearance">Animation for result appearance</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>As well as in Server Side API, when result container is loading, it has class loading, when it's ready, it has class .active and .loaded. So, you can use Animation presets and on .active class condition</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="interactions-in-results">Interactions in results</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>You can add also interaction layers inside Result blocks. They will be executed after results are ready on page</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="hook-for-developers">Hook for developers</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>You can use also special JS hook  for Client Side API</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>document.addEventListener("GSPB_API_RESPONSE", (event) => {
    const { resultElem, responseData } = event.detail;
    console.log("Received API response:", responseData);
    console.log("Result Element:", resultElem);
});</code></pre>
<!-- /wp:code -->

<!-- wp:heading -->
<h2 class="wp-block-heading" id="chat-type-and-streaming-responses">Chat Type and Streaming responses</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>When you use the Client Side, you can also enable Chat mode and streaming. Chat mode allows you to send ongoing requests related to previous requests. It's usually used in Chats when you need to send previous discussions to the AI model so the agent can understand the context.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>I will explain an example of building chat with OPEN AI API. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you check their <a href="https://platform.openai.com/docs/api-reference/chat/create">documentation</a> you will see that you need to send an object with roles, something like this.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>   "messages": [
      {
        "role": "developer",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "Hello!"
      },
      {
        "role": "assistant",
        "content": "How are you?"
      }
    ]</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>So, on each user input, you need to attach new. </p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>      {
        "role": "user",
        "content": "Hello!"
      },</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Then, get a response from the model, and next time, attach this response to chat with the role "assistant". </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Quite a complex task, but Greenshift will do it for you</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>So, at first, you need to add initial data for the body, it will be </p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>{
  "model": "gpt-4o",
  "messages": [
    {
      "role": "system",
      "content": [
        {
          "type": "text",
          "text": "You are a helpful assistant that can answer questions and help with tasks."
        }
      ]
    }
  ]
}</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Here, we define the messages object and add the initial system role.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>We need to provide a key from the body where ongoing inputs will be stored. It's our Append Field because each new user request will add a new item in this key. In our case, it's "messages"</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5708,"width":"300px","sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large is-resized"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5708" style="width:300px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Now, I need to provide a User Message JSON format</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>{
  "role": "user",
  "content": [
    {
      "type": "text",
      "text": "{{VALUE:.search-input-api}}"
    }
  ]
}</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>See that I used {{VALUE:search-input-api}} It's a special placeholder that shows the plugin to get value from .search-input-api element from the page and use its value to add the object to messages</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>I will need to get a response from the system and save it for assistant messages. So I used</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>{
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "{{RESPONSE}}"
    }
  ]
}</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>{{RESPONSE}} is a placeholder that will be dynamically replaced by the response data of Assistant from a previous API call. You also need to add a specific field where the Assistant response text is saved because usually, the Response has many keys. In open AI, the response is added in the next format</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5709,"width":"400px","sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image size-large is-resized"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5709" style="width:400px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>See, it's too much extra data here, but we need to get value only from the first item in "choices", so our field is choices[0][message]</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5710,"width":"300px","sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full is-resized"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5710" style="width:300px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>That's all. But we need to use also Interaction layers to improve Chat style. For example, we need on each click of Sending button, we add user input value to our chat container. Hopefully, Interaction Layer has everything for this kind of functions. You can download everything from our library and use as base for your custom chats.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="streaming">Streaming</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Your responses can also be streamed. Streaming allows you to get results from the server immediately, chunk by chunk, and show them on the page. In this way, the user does not need to wait for the full answer to show up on the page because the results will be added faster and typed on the page. Usually, chats use streaming.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>You don't need to worry how it's made, Greenshift will take care of everything for you. </p>
<!-- /wp:paragraph -->

<!-- wp:greenshift-blocks/infobox {"id":"gsbp-1be8656"} -->
<div class="wp-block-greenshift-blocks-infobox gspb_infoBox gspb_infoBox-id-gsbp-1be8656" id="gspb_infoBox-id-gsbp-1be8656"><div class="gs-box info_type icon_type"><div class="gs-box-icon"><svg x="0px" y="0px" viewBox="0 0 512 512"> <g><g> <path d="M256,0C114.497,0,0,114.507,0,256c0,141.503,114.507,256,256,256c141.503,0,256-114.507,256-256 C512,114.497,397.492,0,256,0z M256,472c-119.393,0-216-96.615-216-216c0-119.393,96.615-216,216-216 c119.393,0,216,96.615,216,216C472,375.393,375.384,472,256,472z"></path> </g> </g> <g> <g> <path d="M256,214.33c-11.046,0-20,8.954-20,20v128.793c0,11.046,8.954,20,20,20s20-8.955,20-20.001V234.33 C276,223.284,267.046,214.33,256,214.33z"></path> </g> </g> <g> <g> <circle cx="256" cy="162.84" r="27"></circle> </g> </g> </svg></div><div class="gs-box-text"><!-- wp:paragraph -->
<p>When you use custom response template, each element that you add for mapping will have "loading" class before getting data and "loaded", "active" class if value will be retrieved while streaming. You can use it to show or hide specific items depending on fact if there is data in the streaming response.</p>
<!-- /wp:paragraph --></div></div></div>
<!-- /wp:greenshift-blocks/infobox -->

<!-- wp:heading -->
<h2 class="wp-block-heading" id="api-presets">API Presets</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>There are few integrated API presets, that you can use for practical tasks.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":5720,"width":"300px","sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full is-resized"><img src="https://greenshiftwp.com/wp-content/uploads/2025/02/[email protected]" alt="" class="wp-image-5720" style="width:300px"/><figcaption class="wp-element-caption">Screenshot</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Click on API Presets link for this.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Currently we added two ready presets:</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="wordpress-site-latest-items">Wordpress Site Latest Items</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>This is for easier generation of Wordpress REST link. Put there any Wordpress site and select post type to show. Now, you can get items from external site</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading" id="google-sheet-csv">Google Sheet/CSV</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>You can use Google Sheet link or csv link as source. Plugin will automatically convert data to be API source. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>It's possible to convert each row as item and each column as item</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2 class="wp-block-heading" id="examples">Examples</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Please check our library for three examples of API Connector</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://greenshift.wpsoul.net/external-client-side-api-example/">Client Side API</a></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://greenshift.wpsoul.net/external-server-side-api-connector/">Server Side API</a></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://greenshift.wpsoul.net/custom-open-ai-chat-ui/">Custom Chat for Open AI</a></p>
<!-- /wp:paragraph -->
«
»