Skip to main content

Questions tagged [plugin-elementapi]

Plugin that makes it easy to create a JSON API for your elements, from Pixel & Tonic.

Filter by
Sorted by
Tagged with
0 votes
0 answers
43 views

Element API: Group Categories by Groups

I want to use the Element API to output a hierarchical JSON list of categories grouped by category group. For example: { "groups": [ { "id": 2, &...
2 votes
1 answer
102 views

How to Escape a Query Parameter

Extremely not a PHP developer here but trying to set up a simple API with Element API. I've got the basics working to filter my entry results based off of a query URL parameter: use craft\elements\...
2 votes
3 answers
697 views

Element-API: Access the first url of an asset array

I have an asset field in my current project with the handle postImage, containing multiple image files. In my element-api endpoint, I wish to access the url of the first file only. I tried the ...
1 vote
1 answer
55 views

How to migrate a selection of users passwords from a Craft 3 to a separate Craft 4?

I'm trying to move a large batch of users from a Craft 3 to a separate Craft 4 websites (only some selected data should be migrated). Element API + FeedMe looks like the right solution for that, as ...
1 vote
1 answer
328 views

Dynamic Element API

How can we write Element API configuration files to dynamically output JSON payloads in Craft 3.3? The goal is to create a generic function which only needs endpoint definitions to recursively loop ...
7 votes
2 answers
2k views

Element API plugin - Return message when no results are found

Per this code example, it's clear that the API is expecting to return results based on an existing element... 'transformer' => function(EntryModel $entry) { ... } And when the criteria finds ...
1 vote
2 answers
250 views

Element API and Shopify plugin

Is there any way to translate this: {% set shopify = craft.shopify.getProductById({ id: entry.shopifyProduct, fields: 'variants, id' }) %} to the Element API? I've tried this, but obviously it ...
0 votes
1 answer
47 views

Element-api get other entries by id inside a entry.json

I have few entry ids from a plugin(donkeytail), and are arranged in an array, I need to loop through that array and get title, slug, etc of each entry. $entry->pins = ["106","122&...
0 votes
0 answers
38 views

Outputting geojson collection with element-api

I am trying to get the element-api to output a valid geojson collection. The way the keys are set in the returned data make me think it isnt possible. To produce a valid string of json i am having ...
2 votes
2 answers
818 views

Craft 3: get enabled sites of an entry

I'm looking for a way to list all the enabled sites for a given entry. I couldn't find some sort of getEnabledSites method that's similar to the available getSupportedSites. The latter only returns ...
2 votes
1 answer
76 views

Get last change timestamp in header response

I'll be polling an endpoint created with the element-api plugin which will trigger a concourse build. I need to include a timestamp the last time any entry was changed. So I need something to go in ...
0 votes
0 answers
83 views

Element-api search with space in query returns zero data

I have an endpoint for searching entries via the element api. 'api/searchtherest.json' => function () { $section_handle = 'openFunding'; $criteria = [ '...
1 vote
0 answers
97 views

Join multiple tables in element-api

My problem is the following: I have a website with products which contains ratings. I have an element-api endpoint to get the products. I want to sort the products based on the average rating or the ...
1 vote
1 answer
50 views

Jsondecode in element API causing memory issue

I have the element api pulling back 1300 entries. One of the fields is storing geojson data and I had to change the type from text to mediumtext to accommodate some of the data stored. When I moved ...
1 vote
0 answers
118 views

Element API relatedTo not working

I'm creating a lazy load/infinite scroll based on the tutorial but I want it to grab entries that are in categories. It doesn't seem to be doing anything with it at all though. It's returning the list ...
2 votes
1 answer
170 views

Element API using the entries field to display related content from a separate section

I've seen similar questions but none seem to help. I have two sections named jobs and jobDescriptions. I'm using the entries field to pull in a description field from the jobDescriptions section to ...
1 vote
1 answer
882 views

Element API: Get Entries Related to Category with Query Parameter

I'm using the Element API Plugin to create an API, with which I want to get entries related to one category, but dynamically with the category set in the Url. What I have so far in the config/element-...
1 vote
1 answer
63 views

Having issues looping through variants for Commerce 2 Products using Element API

I'm currently able to return the first variant using the following: <?php use craft\commerce\elements\Product; use craft\helpers\UrlHelper; return [ 'endpoints' => [ 'products.json' =>...
2 votes
1 answer
726 views

Getting Commerce Products using Element API in Craft 3

I am trying to get Products using the Element API plugin. I set the 'elementType' to Commerce_Products, CommerceProducts, etc.., but the endpoint keeps returning: Endpoint has an invalid ...
3 votes
3 answers
1k views

How can I get image locations in a list of entries using the Element API plugin?

'api/looks/list' => [ 'criteria' => ['section' => 'looks'], 'transformer' => function(EntryModel $entry) { //print_r($entry->getAncestors()); ...
5 votes
2 answers
4k views

How do you use the Element API plugin to output Matrix blocks for an entry?

I am having a hard time trying to figure out how to pull matrix blocks within an entry into the single entry's endpoint with the Element API plugin. Is this possible? Or do I need to output the ...
1 vote
2 answers
142 views

Accessing SEOmatic meta via controller action in Element API triggers HTTPForbiddenException

I'm attempting to fetch SEO meta for entries inside of an element API, roughly following the advice in Element API integration Below is the exact code in my element-api.php: <?php use craft\...
3 votes
2 answers
335 views

Smart Map - Sorting for closest location in PHP

I want to sort entries with a Smart Map address field for closest location. I know how it should be done in a template: {% set entries = craft.entries.myAddress(params).order('distance').find() %} ...
4 votes
1 answer
413 views

Using multiple elementTypes in Element API

I am currently trying to create an autocomplete search with the element-api. I need results from two different elementTypes: Product::class Entry::class How do I get results out of both elementTypes ...
1 vote
1 answer
385 views

Element API, query entries where relationship field ':empty:' AND the same relationship field with specified entry ID

Element API, query entries where relationship field ':empty:' AND the same relationship field with specified entry ID. Can't seem to figure out how to do this without performing two separate queries ...
2 votes
2 answers
473 views

How to search on multiple (custom) fields using Element API

I am using the Element API to search for entries that match a search query: either the title OR the excerpt should contain the query term. The entry is very simple and has these fields: -title -...
3 votes
2 answers
342 views

How do I sort and paginate a JSON feed by a key from a transformer?

I need to sort the entries for an Element API endpoint by a value calculated in a custom transformer. Is this possible? The use case is this: We're dealing with Events/Courses that have multiple ...
1 vote
1 answer
37 views

Setting relative path to ElementAPI in PHP

I need a few small bits of data from Craft in a PHP file. It’s a really small task, so I don’t want to delve into writing plugins or anything hardcore. It seemed to me the simplest way to approach it ...
2 votes
1 answer
302 views

Get currentSite.handle in Element API

I need to get the currentSite in Element API. How can this be achieved? Is it as a slug in the endpoint URL? or as a Query param? Here is the current code: <?php use craft\elements\Entry; use ...
0 votes
0 answers
197 views

How to load more entries of a category on that category's page with Element API?

Following up on previous questions of mine: How to use multiple different instances Element API "Load More" button? I have a website that utilizes the "load More" (button) method ...
1 vote
1 answer
136 views

How to use multiple different instances Element API "Load More" button?

Following up on a previous question of mine: How to skip the first few entries in a "load more" scenario with Element API? I have a website that utilizes the "load More" (button) ...
1 vote
1 answer
153 views

How to skip the first few entries in a "load more" scenario with Element API?

I have a website that uses a "load more" button. The process for this button can be found here: http://craftsnippets.com/articles/infinite-scrolling-and-lazy-loading-with-craft-cms I made it ...
1 vote
1 answer
208 views

Retrieve Matrix Field from Related Category in Element API

I have an API endpoint set up for a category group. This currently provides some details of all entries that have been assigned that category (i.e. related entries). That works well for some high ...
1 vote
1 answer
490 views

Changing the output of ElementAPI

Wondering if it's possible to change the output that I'm getting from ElementAPI. I'm using the API to preload assets, and this is the output I'm getting. { "data": [ { "title"...
0 votes
1 answer
159 views

How get entries between mutiple dates, ordered by date?

I'll import (event) entries with feedme in craftcms 2 from an API who I'll can't change. The api gives the startdate off the events in a dateTime object. The allDay events have a date without time. ...
1 vote
1 answer
98 views

Element-api - filter Draft entries by the draft author (not original author)

I have a remote app that enables preview based on your editor craft account. I want to retrieve draft entries that they are working on, but i cant find a way to do this. 'authorId' seems to always be ...
0 votes
0 answers
236 views

Search for category and title in Element API for Jquery Autocomplete

I'm working on the search Autocomplete based on this article, http://craftsnippets.com/articles/search-autocomplete-component-for-craft-cms Besides the title, I want to search within the category too....
1 vote
1 answer
316 views

Headless mode/ElementAPI: how to set the frontend's baseUrl in the backend endpoint?

I am having an ongoing confusion in headless mode. Imagine a site with 2 servers: Backend (Craft with element API) on https://backend.site Frontend (vue.js) on https://frontend.site Editors pick ...
1 vote
1 answer
194 views

How to reset a multi-value checkbox using EVENT_AFTER_SAVE_ELEMENT in Craft 3?

I'm porting the functionality of an existing plugin from another CMS into Craft 3 through a custom Craft module. The functionality is: When an option from a multi-value checkbox is checked on the "...
1 vote
1 answer
805 views

Use GET parameters to query for array of entry IDs

On my client side, I have an array of entry IDs that match with entries in Craft const myIds = ['230', '249', '256'] I am trying to send that array over to an Element API endpoint and use it in the ...
2 votes
1 answer
217 views

How can I get field's value of entry in other site locale in my element-api endpoint?

I'd like to get a field value in 3 differents locales in the same element-api endpoint but I can't make a request similar to this one : craft.entries.siteId($siteId).id($entryId).one() in twig. <?...
0 votes
0 answers
319 views

Deprecation Warning: Use the all() function to fetch the query... in PHP

I am getting this warning message: "Looping through element queries directly has been deprecated. Use the all() function to fetch the query results before looping over them. " It is pointing out ...
1 vote
0 answers
126 views

Migrating to Matrix using Feed Me and Element API

How can I use Element API to move my entry fields into a matrix-based content builder? I'm going off the docs found at https://docs.craftcms.com/feed-me/v4/guides/importing-into-matrix.html#setup-your-...
1 vote
1 answer
130 views

Elements API - How to order / limit the output with an asset field of an entry

I recently started using the Elements API and I made up a recipe site as an example project. It's pretty easy to output the recipes as json data. But I now want some more control about the output of ...
1 vote
0 answers
368 views

How to get an Entry in structure and all of its children and it's children's children with Element APi?

How do I get all of an entry's children using the Element API? I want to return something like: data: [ title: 'Root Entry' uri: 'root-entry' children: [ { title: '...
0 votes
0 answers
79 views

ElementAPI: How to trigger the Custom service php file when a endpoint is loaded

I am Using Craft 3.3.11 version I have a php file in plugin/elementapi/src/services/EapiServices.php and the same file within vendor/craftcms/element-api/src/services/EapiServices.php When ...
1 vote
2 answers
2k views

ElementAPI: How to order and/or limit results?

Currently collaborating on a site with another developer, which is using ElementAPI pretty heavily for content delivery. Is there a way to limit the number of returns on any given json feed? Say; ...
6 votes
1 answer
542 views

Is there a way to split the element-api.php file?

Is there some way I can split the element-api.php file into separate files and import them all? It's getting quite long and unwieldy.
2 votes
1 answer
258 views

Pass params to transform function of Transformer class in split Transformer class

I have transformer like down below in the element API. 'transformer' => 'MyTransformerClassName', Or 'transformer' => new MyTransformerClassName(), I am going to pass a param like $user ...
1 vote
1 answer
416 views

How to pull an entry's SEOmatic meta tags with Element API?

How do I get the meta tags used in SEOmatic for a specific entry and returning it through the Element API? Not sure how the PHP code looks like when using SEOmatic's PHP API.

1
2 3 4 5