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
2answers
36 views

Element API - Order results by Category

Is there a way to order the Craft Element-API results by the category title? I'm just getting the error SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data The "...
0
votes
0answers
10 views

Element Api: Create list of sites

I'm trying to provide a list of sites in a multisite environment as a JSON Feed for a Vue component. My current solution is to loop through the sites in the template with twig and pass it back to ...
1
vote
1answer
23 views

Element API - Markdown in JSON

I'm a little bit stuck using the Element API. I managed to get my JSON file going pretty easily which was great but I've reached a point where I want to include some formatted copy as it would be ...
1
vote
1answer
20 views

Element API: How to get entries up to a certain page?

I have a query that is pulling entries from a structure with elementsPerPage' => 3 If my pagination looks like this: Page 1: Entries: A, B, C Page 2: Entries: D, E, F Page 3: Entries: G, H, I ...
1
vote
1answer
13 views

Array from matrix fields without quotations

I am trying to create an array bodyBlocks by looping through all of my matrix fields called blockTextContent: $bodyBlocks = []; foreach ($entry->getFieldValue('pageBuilder')->all() as $block){ ...
0
votes
0answers
15 views

How can i filter on site and locale in the element API

I have multiple sites and locales enabled. How can filter on entries only from a given site and locale? Here's what I have. As you can see I already have a the $site and $locale variables, but I don'...
1
vote
1answer
25 views

Logging in to Craft via Vue/Javascript apps

I'm just diving into the world of javascript frameworks (late to the party I know) and can't figure out the missing piece of the authentication puzzle. What is the preferred way to authenticate users ...
0
votes
1answer
25 views

How do I fetch all categories under a category group using the Element API?

I am not too familiar with PHP and am just learning the Element API. How do I turn this craft query into an element api query? craft.categories.group("brands").level(1).all(), In categories this is ...
0
votes
0answers
21 views

Send delete event timestamp element api

I have an endpoint that sets a response header when an entry is saved (code below). Is there a similar method I can use when an entry is deleted? 'api/entries.json' => function() { ...
1
vote
1answer
98 views

Return JSON array without extra square brackets

I'm having difficulties to remove an additional set of square brackets or avoid including them within array. My JavaScript code currently accesses array's object at 0 index and therefore I'd have to ...
1
vote
1answer
43 views

relatedTo - return only entries that have a related entry where a field in the related entry has a value

Trying to figure out if this is possible in 1 step. I want to return locations that have a related entry in the relatedMerchant field, but I'd also want to make sure that a field in the ...
1
vote
1answer
82 views

Element API — Endpoint has an invalid elementType

I'm trying the Element API for the first time and getting this error message {"error":{"code":404,"message":"Endpoint has an invalid elementType"}} I cannot for the life of me figure out what I'm ...
1
vote
1answer
116 views

How can I query entries based on a Matrix Block Type?

I'm using Element API and trying to create a query that returns a list of entries based on if the entry is using a specific Matrix Block Type. I've tried a few different things including a query that ...
0
votes
0answers
29 views

Element API - Get all category group titles without passing in a handle

I want to achieve something like the following: $categoriesData = []; if ($type === "helpIndex") { $index = -1; $catGroups = Category::find()->group()->all(); foreach ($catGroups as ...
0
votes
0answers
16 views

How do we eager load locales with criteria in eager loading?

I can eager load in element-api the site name in the criteria passed, but i cant find a way of getting the language locale id into the criteria. This works return [ 'resourceKey' => '...
0
votes
0answers
11 views

Is it possible to set default language or site id globally in element api?

Id like to load up all french content for all endpoints in the api plugin. I can do it per endpoint but can it be done for all endpoints?
1
vote
0answers
15 views

Locales with independent language and country

How might we use Craft to manage our locales, keeping our language and country logic independent? The desired scenario: No duplicate language entries: Spanish in Spain would be the same as Spanish in ...
1
vote
0answers
22 views

Query element api (output) via plugin

Is there a way to fetch the content generated by the Element API via a plugin. For example, if we have created an ingredients/<slug:{slug}>.json endpoint, can the data for a specific page (eg ...
0
votes
1answer
33 views

Element API unable to get all() of matrix field

I'm getting matrix block content from an entry type which works fine for the most part. It's probably clearer to just paste in the code: Current element api code: $relationsData = []; if($entry-&...
0
votes
0answers
43 views

Shopify - Connect existing Element API/Vue JS site to new Shopify store

I have a Craft 3 site, currently running using the Element API and Vue JS as follows: VueJS: Product grid component ... mounted(){ this.getGridProducts() }, data() { return { ...
1
vote
1answer
38 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 [ ...
1
vote
1answer
22 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 ...
1
vote
0answers
39 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 ...
1
vote
0answers
23 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 ...
0
votes
0answers
26 views

Using Element API with Digital Products

I'm trying to set up the Element API to get Digital Products. I've managed to get regular commerce products like this: use craft\commerce\elements\Product; return [ 'elementType' => Product::...
1
vote
1answer
52 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 ...
1
vote
1answer
51 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 ...
1
vote
1answer
29 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 ...
1
vote
1answer
86 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, ...
2
votes
1answer
150 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-...
1
vote
1answer
40 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 ...
0
votes
1answer
67 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 "...
2
votes
0answers
127 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 ...
1
vote
1answer
42 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 ...
2
votes
0answers
196 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 ...
1
vote
1answer
148 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 ...
1
vote
0answers
82 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 ...
2
votes
1answer
49 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 ...
2
votes
1answer
172 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 ...
1
vote
1answer
22 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: ...
1
vote
1answer
221 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 ...
1
vote
1answer
226 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->...
0
votes
0answers
89 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' => ...
2
votes
1answer
216 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 ...
2
votes
1answer
453 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 ...
1
vote
1answer
252 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?
1
vote
2answers
272 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 ...
1
vote
1answer
213 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; ...
0
votes
2answers
211 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, ...
0
votes
0answers
34 views

ElementAPI fetching categories' children not returning localized elements

I followed Brandon's explanation in this thread to fetch all categories' children with the ElementAPI. But when I add the locale to the criteria, I don't get the localized children elements. Do I ...