Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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

0
votes
0answers
9 views

Element API / Search with special characters

I'm working on a project and have a search field that uses vue2-autocomplete with the ElementAPI plugin (following Andrew Welch's blog post). I'm having problems with search queries that have special ...
0
votes
0answers
23 views

Shopify API and slow response times

I'm using the Element API to load entries that have a Shopify field (using the Craft Shopify plugin) and it takes up to 20 seconds to load all the data. Am I doing something wrong? Here's the code: ...
1
vote
1answer
24 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 ...
5
votes
1answer
22 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
1answer
19 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.
0
votes
0answers
14 views

Include the asset's volume in the eager loading. [Element API]

On Element API, I'm eager loading the header image like: $criteria = [ 'section' => $section, 'with' => ['categories', 'header_image'] ]; But, in the output, I cannot get the volume ...
1
vote
0answers
14 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-...
1
vote
1answer
18 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 ...
1
vote
0answers
37 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 ...
2
votes
1answer
54 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 ...
2
votes
1answer
17 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?
2
votes
1answer
68 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' => [ '...
1
vote
1answer
24 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()->...
2
votes
1answer
62 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 "...
1
vote
1answer
34 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 ...
0
votes
0answers
19 views

Getting Solspace Calendar Events with ElementAPI

I have started to use ElementAPI and Solspace Calendar plugins on a project and I'm trying to get a JSON feed of all events so I can dynamically load certain events with ajax. Here's a question about ...
2
votes
2answers
98 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 ...
1
vote
1answer
28 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 ...
0
votes
1answer
47 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 ...
1
vote
1answer
75 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 ...
0
votes
1answer
35 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 ...
1
vote
1answer
57 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->...
0
votes
0answers
21 views

Craft Element API data output as a hash instead of an array

I'm building and API feed using Element API plugin from Craft, and I'd like the data output to be serialized as a hash, but currently it's returning an array, as example bellow: <?php namespace ...
1
vote
2answers
60 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()...
1
vote
1answer
110 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 ...
2
votes
1answer
75 views

Element API Fetch Entries URL Within Matrix

I have a matrix with a field to set a Entries URL. Unfortunately the entry is not being returned, only an empty object. Here are my field settings below and element api code. See below for the ...
1
vote
0answers
40 views

Craft 3 Element Api when system status is disabled

Using Craft 3 RC14 System status is set to off Wondering if anyone has approached the same problem as I did. If there is a way to use element api while the system status is disabled? I have tried ...
1
vote
0answers
155 views

What are my caching options when using CraftQL and React?

I’m experimenting with the CraftQL plugin and React with Craft 3, and I’m really liking the similar syntax to standard Twig element queries, and the fact I don't need to manually configure API ...
3
votes
1answer
341 views

Element API display entries by category

With v2 of the Element API plugin, I'm having issues with working out how to return entries that are in a particular category. I've got the slug in the API route but can't work out what the query ...
1
vote
1answer
80 views

Get PDF file from Assets Folder - Element API

I have a PDF folder within assets and having trouble accessing the file path once chosen by the user. To get something like an image from assets within a matrix I do something like this which works: ...
1
vote
2answers
241 views

Image transform with focal point - in Element API

I can call predefined image transforms no problem - $image->getUrl('small') but cropped mobile transforms need to use the image asset's set focal point (from the Image Editor). I can't find any ...
1
vote
1answer
44 views

Using elements-api, how do i create a geojson structure with Features within a FeatureCollections

I am trying to output, from a single request, a geojson structure like so: "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {}, ...
1
vote
1answer
132 views

element-api plugin / get entry total in section in Craft 3

What is the best way to get only the total entry number from a section with the least overhead, in the element-api.php? Thanks Mark
1
vote
1answer
235 views

How to render a Twig template in the element-api plugin (v2.5)

I want to render a Twig template in an API endpoint. Specifically I need HTML for the JSON Feed field "content_html". My attempts until now (inside the transformer function): $view = Craft::$app->...
3
votes
1answer
56 views

Break-up Element API Config into partials

I'm working on a Vue SPA (single page application) for a client and my ElementAPI config file has grown to be quite large. To make it easier to maintain I was looking for suggestions of how to have ...
1
vote
0answers
54 views

Using target element criteria to filter results

I'm using the Element API plugin to try and search for addresses using minimum and maximum lat & lng values and then using target element within the criteria parameters to filter the results ...
1
vote
1answer
191 views

Element API with multiple categories gives back error 500

This works fine on localhost but crashes on remote Server. I can return one category, but it will crash when I try to display multiple categories. I also tried to save the categories in a variable and ...
1
vote
0answers
195 views

How to get list of category groups?

Is it possible to get a list of category groups without having to loop through all categories to get their parent group name? UPDATE: Just making this question clearer, as it's related to using ...
1
vote
1answer
33 views

Authorization fail

I am trying to being authorized at Chanel Adviser but it's showing error, "invalid_client". I am invoking this URL : https://api.channeladvisor.com/oauth2/token?client_id=...
1
vote
0answers
151 views

Using element API to query a matrix field

I'm using the Element API to grab entries and their data (via this answer). What I want to do is accept a URL parameter (eg. ?location=foo) and filter the returned entries by a Matrix field called ...
1
vote
1answer
63 views

getting the current user entries from elementapi

How do I use the elementapi to get the list of entries for the logged in user? I've tried a couple of options to no avail, like 'api/v1/user/<userId:\d+>.json' => function($userId) { ...
1
vote
1answer
61 views

Element API endpoint without a resourceKey

The output of a Element API endpoint allows you to change the resourceKey which contains the json data. Is it possible to return just the data without a resourceKey at all? Values such as null, false ...
0
votes
0answers
65 views

Element API preview unpublished entry?

I'm building a single page app using React and consuming content using the element-api plugin. I'd like to be able to preview entries before they're published, is it possible to get unpublished ...
3
votes
1answer
92 views

With Element API, can I combine two entry types into a JSON object, keyed by type?

I need to return two types of entry to an external service, and am trying to do so in one endpoint. I am able to return all of the instances of each type, but it returns an array of mixed types. "...
1
vote
1answer
179 views

Element API access param in transformer

Each of my entries has multiple categories (e.g. series, disciplines, and stages). I can get a list of elements related to a single category but I'd also like to get the category information as well (...
1
vote
1answer
343 views

Element API: Remove additional set of square brackets from JSON-String

We're currently having an Android-App access some of the entries of our Craft-based website. We are currently still using a self built API, and for easier creation of new API-Calls we are trying to ...
1
vote
1answer
19 views

MySQL ColumnType::Time does does not populate model from setAttribute()

I have a record with a time field set like this: 'startTime' => array(AttributeType::DateTime, 'column'=>ColumnType::Time, 'required' => true), 'endTime' => array(...
2
votes
0answers
90 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
1answer
148 views

How do I retrieve tags and tag data for an entry in Element API?

In Element API v1, I am setting up an endpoint that is trying to expose a news entry including the tags (title, id, slug) associated with it. Thought it could be set up similarly to how you can ...
1
vote
0answers
99 views

Craft CMS Integration with Node

Question 1 I have a Node/Express application where the users are registered and are using some kind of service. I want to have a list of the registered users and their info inside Craft CMS admin ...