Response Data formatted differently

Hello,

I've been working on a svelte frontend that was utilizing the javascript Prismic client to get data from Prismic. It was working well, however we realized that we need to utilize a proxy to handle requests from sending data based on authentication. Long story short, I've got an express server getting requests from my svelte frontend and am formatting requests to the node Prismic client I added to the server.

The issue is the response that I am getting is formatted differently than when querying directly from the front-end.

For example, when using getByUid directly from the frontend (js client) the request would look like this:

data:
article_main_title: Array(1)
0: {type: 'heading1', text: 'Statement extracts', spans: Array(0)}
length: 1
author: {link_type: 'Document'}
body: (10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
comments: [{…}]

When using getByUid from the proxy (node client) the request looks like this

data:
document:
article_main_title:
type: "StructuredText"
value: [{…}]
body: {type: 'SliceZone', value: Array(10)}
comments: {type: 'Group', value: Array(1)}

This is making the exact same query just from two different places.

Notice that there is a difference in the formatting. In particular, each property in the node version has a 'type' and 'value' property, while in the javascript version, the property just has the value without an internal 'value' property.

Is this expected behavior? Did I perhaps not set up the node client properly or am missing something?

Thanks

Hi @jim.moreno, thanks for reaching out about this. Hopefully we can get this all cleared up quickly.

It seems to me that your Node proxy is using the API v1, and that is where the differences are being seen. Can you share a bit more about the proxy setup? Which development kit are you using there and how do you have it set up?

My guess is that you need to update the library you're using in Node and switch to use the Prismic API v2 (the same as you're using on the frontend).

Hi Levi,

Thanks for the reply. The library I'm using in node is 5.1.0, the endpoint I'm calling is also a /v2 endpoint. The only library I installed is the client library (npm install @prismicio/client), thinking that is all I would need for the proxy. Is there another library I need installed to have the shape of the response be correct?

Here is what I'm doing:

const Prismic = require('@prismicio/client')

const client = Prismic.client(API_URL)

result = client.getByUid('my.document.uid', 'validUid', { 'fetchLinks': ['Document.uid', 'definition.definition'] })

Please let me know if there is anything I'm missing.

Thanks,
Jim

This is very strange. You're using the correct library, so I'm not sure why this is happening. Can you share your node codebase with me so that I can dig a little deeper?

You can send me a direct message with either a zip file of your project or a link to Github (or similar).

Levi,

This is incredibly embarrassing but your initial idea of me not using the right v2 endpoint was correct.

When I was cleaning the code up to package it and send it to you I noticed that the API url I was using had removed the /v2. This happened when I was originally trying to keep the library in the client and make a call to the proxy.

I've re-added the /v2 and it is working exactly as intended. I'm very sorry for not having double checked something so obvious sooner. I had assumed it was correct and didn't notice until now. Thank you very much fo your help and sorry for taking up your time on user error.

Thanks,
Jim

@jim.moreno No problem at all, I'm glad that we were able to get it sorted out :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.