apostrophe-headless icon indicating copy to clipboard operation
apostrophe-headless copied to clipboard

Unable to retrieve apostrophe-global

Open RyamBaCo opened this issue 5 years ago • 6 comments

Hey there,

we're having some fields stored in apostrophe-global we want to retrieve and manipulate using apostrophe-headless. Our index.js in apostrophe-global looks like that:

module.exports = {
  restApi: true,
  apiKeys: [... api key...],
  addFields: [ ... some fields ... ]
}

In my understanding I should get global data by setting up a get request against /api/v1/apostrophe-global (also tried only global) but i receive a 404. Am I missing something or is this functionality missing? I think that this feature should work as apostrophe-globals inherits from pieces.

RyamBaCo avatar Feb 07 '20 13:02 RyamBaCo

Do you have this working for other pieces modules in this project?

On Fri, Feb 7, 2020 at 8:10 AM Ryam BaCo [email protected] wrote:

Hey there,

we're having some fields stored in apostrophe-globals we want to retrieve and manipulate using apostrophe-headless. Our index.js in apostrophe-global looks like that:

module.exports = { restApi: true, apiKeys: [... api key...], addFields: [ ... some fields ... ] }

In my understanding I should get global data by setting up a get request against /api/v1/apostrophe-global (also tried only global) but i receive a 404. Am I missing something or is this functionality missing? I think that this feature should work as apostrophe-globals inherits from pieces.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/apostrophecms/apostrophe-headless/issues/43?email_source=notifications&email_token=AEJYL2HC2F5FZY2XMUYKIMLRBVMV5A5CNFSM4KROJHKKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4ILZYVGQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEJYL2DMNFXXJF6MSVCIB3TRBVMV5ANCNFSM4KROJHKA .

--

THOMAS BOUTELL | CHIEF TECHNOLOGY OFFICER APOSTROPHECMS | apostrophecms.com | he/him/his

punkhub avatar Feb 07 '20 13:02 punkhub

Yes, we got this working for pieces and pages in the same project.

RyamBaCo avatar Feb 07 '20 13:02 RyamBaCo

Hello, I was wondering if there has been any solution for this. I have different pieces working for headless. I have pages working. However, as RyamBaCo said the typical ways of retrieving do not work. I added

'apostrophe-global': { restApi: true },

It returns a 404. Thanks

jpitassi1 avatar Jul 14 '20 02:07 jpitassi1

Hey there, after a few months with more Apostrophe-knowledge one possible workaround is to write your own getter in api/index.js, like for instance:

module.exports = {
  construct: function (self, options) {
  self.apos.app.get("/api/v1/custom/global", async (req, res) => {
      const global = (await self.apos.global.find(req).toArray())[0];
      res.json(global);
   });
   }
}

This code is untested, I just altered some functionality, where I had to deal with global values.

RyamBaCo avatar Jul 14 '20 15:07 RyamBaCo

That would work. It would send everything though; I recommend paring it down to stuff you know you need.

Of course we should fix the underlying issue.

On Tue, Jul 14, 2020 at 11:26 AM Ryam BaCo [email protected] wrote:

Hey there, after a few months with more Apostrophe-knowledge one possible workaround is to write your own getter in api/index.js, like for instance:

module.exports = { construct: function (self, options) { self.apos.app.get("/api/v1/custom/global", async (req, res) => { const global = (await self.apos.global.find(req).toArray())[0]; res.json(global); }); } }

This code is untested, I just altered some functionality, where I had to deal with global values.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/apostrophecms/apostrophe-headless/issues/43#issuecomment-658245572, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAH27MQSK3JIPEKGOU6IW3R3R2J5ANCNFSM4KROJHKA .

--

THOMAS BOUTELL | CHIEF TECHNOLOGY OFFICER APOSTROPHECMS | apostrophecms.com | he/him/his

boutell avatar Jul 14 '20 19:07 boutell

Yea I started tracing through the code and although global is marked as a piece when it comes to apostrophe-pieces-headless it does not show up as a piece to try to make an endpoint for. I could not pinpoint where it falls out of the list of viable pieces.

jpitassi1 avatar Jul 16 '20 18:07 jpitassi1