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
1 vote
1 answer
156 views

Get a specific product with Element API, Commerce and Craft 2

How do I get a specific product via Element API? Here's what i have so far 'api/product' => function() { $productId = craft()->request->getRequiredQuery( 'productId' ); return [ ...
Lumiere's user avatar
  • 11
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 ...
Matt Simon's user avatar
1 vote
0 answers
203 views

element-api: include a collection with mixed entry types, and nested includes

Does anyone know how to include a collection of entries, containing multiple entry-type, in such way that: 1. Each entry type gets transformed by its own custom transformer class (tailord to the ...
yoannisj's user avatar
  • 111
1 vote
0 answers
60 views

Retrieving Entries by Category & Exclude by Tag

I have an endpoint that I want to retrieve entries by a category, but then exclude entry ids if they have a certain tag. It seems to me that the relatedTo param overrides the id param that says not in ...
Michael's user avatar
  • 33
1 vote
1 answer
214 views

Element api JSON output formatting

I want to output all globals with one endpoint. This is trivial for the most part but I need to have some objects in a specific shape. I'm using a matrix block to handle the content. The main issue ...
user924248's user avatar
1 vote
1 answer
255 views

Element API: Is it possible to ignore/skip an Entry?

I would like to exclude some of my entries, via my own validation inside the Transformer, from the api output. Is there a possibility to move on to the next Entry without outputing anything? Right ...
Leonardo's user avatar
  • 471
1 vote
1 answer
203 views

How I’ll get an entryId based on a given URL?

I want to configure deeplinks for an app and want to set up 'universal links'. Right now I'll send an entry id to the element api to get the right content. But with universal links I didn't have a ...
Maarten Heideman's user avatar
2 votes
1 answer
488 views

Element API throws 404 when not logged into CP

My element API endpoint throws a 404 when I'm logged out of the CP, but works fine when I'm logged in. When logged out it throws a regular 404 with stack trace exactly as any other non-existing url, ...
Udo's user avatar
  • 607
2 votes
1 answer
446 views

Element API calling Module that integrates with third-party plugin

This is probably a bit niche but anyone especially au fait with the element api here? On project X I have a custom module within which I am referencing a service from another plugin (bolden/google-...
Cole Henley's user avatar
  • 1,741
1 vote
1 answer
148 views

Craft update process affecting Element API cache

I have a site A using the Element API plugin to feed content to site B via JSON and handlebars templates. The process is both sites are up to date with content 'x' and it works fine. When I run the ...
joomkit's user avatar
  • 2,034
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 "...
Warmbeat's user avatar
2 votes
0 answers
450 views

Group by Date Field in Element API Query

I have a custom field called releaseDate in one of my entry types. I would like to use Element API to get all the distinct years assigned to those entries. I dump all the years for all entries just ...
Tony DeStefano's user avatar
1 vote
1 answer
172 views

Matrix block Element API call on null error

I get this JSON error when trying to output content of a matrix block called proLinks using the Element API. Call to a member function all() on null The code is as follows (I've shortened it and ...
H.W. Sanden's user avatar
1 vote
0 answers
588 views

Element API SearchQuery to search for value inside child-entries

I currently try to use the Element API to build a search. Unfortunately I'm kind of stuck. I have a baseEntry, that has a field that references entries (let's call them subEntries) of the section ...
Eternal Black's user avatar
1 vote
1 answer
444 views

Use conditional for Element API results?

Using the Element API is there a way to get entries by dateUpdated OR dateCreated within the last whatever time, say day? Or a way to get the entry IDs for both of those criteria then do a query ...
Erik's user avatar
  • 306
2 votes
0 answers
257 views

Get field type of product or variant with element api

Trying to get type of a field (dropdown, checkbox, etc) to render those fields in app, there is all sorts of info available in $variant->fieldLayout->fields like handles, values, ids except type ...
Alex's user avatar
  • 31
2 votes
1 answer
127 views

Disable dateUpdated

I am using Craft 3 to populate content over a REST api. Now I have a use case, where I want to update an internal field of an entry without changing the dateUpdated. Otherwise the clients would get ...
Volker Andres's user avatar
2 votes
1 answer
493 views

Exposing current Commerce2 Cart via the Element API

I want to be able to retrieve the current users Cart via a JSON API endpoint, so I can loop through the products in the cart in JS on the front end. I've got the Element API plugin installed, but I ...
Matt Wilcox's user avatar
  • 3,209
1 vote
1 answer
39 views

Check if title field has a string in ElementAPI

I am trying to retrieve search suggestions for a search form. I sent the parameter entered by the user, but how do I do it in the criteria? I tried this: 'criteria' => [ 'search' => 'title: ...
Flying Car 0013's user avatar
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 ...
Flying Car 0013's user avatar
2 votes
1 answer
589 views

Element-API migration - entries by category

I am having trouble getting the related category passed thru to the entry api endpoint. I cant use : $criteria = craft()->elements->getCriteria(ElementType::Category); $criteria->...
joomkit's user avatar
  • 2,034
0 votes
0 answers
169 views

Using Embedded Assets Plugin With Element API

When using the Element API, how do you go about using the Embedded Assets plugin? With a regular asset, in the API transformer you can pull out assets and include them like this: 'transformer' => ...
JamesNZ's user avatar
  • 947
2 votes
1 answer
405 views

Element API, VueJs and Imager!

I'm trying to do something akin to Andrew's excellent article whereby I have a 'more' button that spits out 6 more entries at a time. I'm nearly there, but running into some issues. I don't get past ...
Ian Ebden's user avatar
  • 894
2 votes
1 answer
2k views

Craft 3 Element API Authentication/Login

First things first: This is quite similar to this, yet different. I'm trying to get authentication/login for Element-API for Craft 3 to work. Meaning I would like to restrict access to certain ...
Eternal Black's user avatar
1 vote
1 answer
760 views

Element API - Entries Related to a Category

In Craft 3, I want to list all the categories in a group and all the entries related to them. How can I do this?
Billy Sengsey's user avatar
2 votes
2 answers
1k views

Calling Craft API from node.js

I really love working with Craft, especially around how easy and user friendly it is. However, I do work with React/Vue and usually I setup a node server/app that will do some routing, render views ...
nickelman's user avatar
  • 133
1 vote
1 answer
647 views

How do you use the Element API plugin to output Assets from Matrix block for an entry?

I have Single Section(entry) with Matrix field which contains Assets in blocks. I'm trying to fetch assets from a single Matrix block. My element-api.php code is: <?php use craft\elements\Entry; ...
Nikolay Bronskiy's user avatar
0 votes
2 answers
501 views

Use Imager plugin with Element API?

I'm trying to use the Imager-Craft plugin to make specific image transformations, but cannot figure out how to access Imager within the element-api.php file. Imager shows plenty of template examples, ...
Scott Thiessen's user avatar
2 votes
3 answers
698 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 ...
Anthronaut's user avatar
1 vote
1 answer
176 views

Loop over table field in Element API plugin

How can I output the rows and values of a table field using the element api plugin? Where I have entries I do ... $industries = []; foreach ($entry->industries->all() as $industry) { $...
Steven Grant's user avatar
  • 1,855
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 ...
Billy Sengsey's user avatar
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.
George Feast-Parker's user avatar
2 votes
1 answer
729 views

Getting all the values out of a field as array of values

I have a multi-select field in my work section I want to get the values either with the Element api as json or an array of simple values in my template.
LeBlaireau's user avatar
1 vote
0 answers
106 views

Check the field type of all the attributes of an entry

Here's the whole picture: I'm trying to make an API endpoint which should output everything from an entry: First I did this: public function transform(Entry $entry) { return $entry-...
Jorge Anzola's user avatar
1 vote
1 answer
338 views

Matrix block fields returning NULL when using MatrixBlock query

$blocks = MatrixBlock::find()->relatedTo($entry)->all(); The above returns the correct blocks but all fields are returned as NULL. I've read over at GitHub that we need to specify a fieldId ...
biko's user avatar
  • 670
1 vote
0 answers
516 views

Element API plugin: searching and working with nested objects

I’m experimenting with the Element API plugin and working with querying the tags of the assets that appear in matrix blocks in a set of entries. Essentially I’m hoping to be able to use a tag in a ...
Evan's user avatar
  • 11
2 votes
1 answer
930 views

Write to Craft via Element API

I’d like to use Craft as a headless CMS for my mobile app (via the Element API plugin). However, in addition to reading data, I’d also like to write data back to Craft. It looks like this is ...
JWK's user avatar
  • 123
2 votes
1 answer
266 views

Restrict access to Element API endpoint

I'd like to Restrict access to Element API endpoint by the current user's group. Is this possible Using Craft 2?
Adam Menczykowski's user avatar
2 votes
1 answer
1k views

Element API: Get Matrix Content

So I'm trying to get my Matrix as JSON with the Craft CMS Element API plugin. <?php use Craft\elements\Entry; return [ 'endpoints' => [ 'api/sites' => [ '...
Leonardo's user avatar
  • 471
1 vote
1 answer
91 views

Can I output custom or specific data (Not related to an elementType) on Element API?

For example, an endpoint to retrieve all the languages available on the website 'endpoints' => [ 'languages' => function () { $sites = Craft::$app->getSites()->...
Jorge Anzola's user avatar
3 votes
1 answer
972 views

Craft 3 Element API: Query the "parent" entry of a "child" entry with Matrix blocks connected by an 'Entries' field

In a Matrix block field of a "page" entry, I'm using an Entries field to manually select a list of "article" entries to the "page" entry. When I query an "article" entry, is it possible to query its "...
biko's user avatar
  • 670
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 ...
biko's user avatar
  • 670
2 votes
2 answers
1k views

Element API - Filter on a value from a multi value field

I am looking for some assistance with the Element API plugin. I need to filter on the bannerPageCategories field which is a multi select checkbox field. The value will be passed via a querystring ...
Ray's user avatar
  • 23
1 vote
1 answer
131 views

Does Craft do joined calls or multiple ones when fetching the related items? [Element API]

I'm checking Element API's performance to decide if it's a good idea to replace my own custom API with Element API. Right now, when fetching the related items (Via fields or matrix elements), my API ...
Jorge Anzola's user avatar
0 votes
1 answer
294 views

ElementAPI : Excluding terms from search criteria

I am trying to exclude terms in my search when using the element api. I have successfully managed to include terms and search them by fields in my entries. I would now like to be able to exclude ...
Rhys Halsey's user avatar
2 votes
1 answer
1k views

Using Element API to output Super Table fields

I am building a feed using Element API. I am currently looping through Matrix blocks to get various data (based on the help from this post). One of the matrix blocks contains a Super Table field, with ...
andrewmenich's user avatar
0 votes
1 answer
1k views

Get all entries with linked entry in entries field

I have a channel called 'projects'. This channel has two entries fields: relatedThemes relatedAreas What I want to do is perform a search query which filters all projects where the relatedThemes ...
svrbst's user avatar
  • 3
1 vote
1 answer
468 views

Get all Categories with getGroupById in Element API plugin - Craft 3

I have an endpoint created and I am getting the groupID but I am unable to get all the categories associated with the group. This is what I have right now: $categoriesGroup = Craft::$app->...
Kenyon Kowal's user avatar
3 votes
2 answers
2k views

Saving asset programatically, eg via API

I'm working on a plugin in Craft 3 that is fetching a file reference (URL) via an API. I want to fetch the file and save it locally as an Asset. I've tried to do this via Craft::$app->getElements()...
Cole Henley's user avatar
  • 1,741
1 vote
1 answer
931 views

Element API -- getting table data from a matrix

I'm using element API to pull JSON, and I have it working pretty well with a matrix field, but I need to pull a single column out of a table field inside of the matrix, and I don't even know where to ...
Dustin C's user avatar
  • 379