We have updated Flexmonster Software License Agreement, effective as of September 30, 2024. Learn more about what’s changed.

Using withCredentials with type: 'json'

Answered
Chris Malherbe asked on February 16, 2021

Hi,

I need to send a cookie with the get request that fetches the data.
 
It seems like the cookie is sent when I use `withCredentials: true` with the type set as `api`. However, when the type is set as type: 'json', the cookies are not sent. It looks like the withCredentials property is ignored with type: 'json'.
 
Here is the config:

dataSource: {
requestHeaders: {
'some-header': 'header-value'
},
withCredentials: true,
filename: 'https://domain.com/json-data-file',
type: 'json',
},

Is this a known issue, or is there a way I can include the cookies with the json type?
 
I have tried using the customizeAPIRequest method, but this also seems to only work for the 'api' type.
 

12 answers

Public
Vera Didenko Vera Didenko Flexmonster February 16, 2021

Hello, Chris,
 
Thank you for writing to us.
 
Our team recently added an update making the withCredentials property also supported for CSV, JSON, and Elasticsearch data sources.
 
We kindly suggest updating to the latest version of Flexmonster.
Here is our updating to the latest version guide for assistance.
 
Please let us know if updating to the latest version helps to resolve the issue.
Looking forward to your reply.
 
Kind regards,
Vera

Public
Vera Didenko Vera Didenko Flexmonster February 22, 2021

Hello, Chris,
 
We are reaching out to ask if you managed to resolve the issue with using withCredentials for JSON data source.
Did updating Flexmonster to the latest version help?
 
Please let us know if everything works.
Looking forward to your reply.
 
Kind regards,
Vera

Public
Vera Didenko Vera Didenko Flexmonster March 1, 2021

Hello, Chris,
 
Hope you are doing well.
 
Our team is wondering whether our response helped you.
Did updating Flexmonster to the latest version help to get withCredentials working for JSON data source?
 
We will be glad to hear if everything works.
Also, please let us know if there is anything we can assist you with. 
 
Kind regards,
Vera

Public
Alex Gilleran March 1, 2021

I work with Chris and have picked up this task - so upgrading Flexmonster allows withCredentials to be used for the initial load, but we also need to refresh the underlying data. Using the updateData method appears to be the correct way to go about this, but doing this causes withCredentials to be set to false on the subsequent XmlHttpRequest.
Trying to debug the minified code, the problem seems to be that the data object gets copied in two different ways depending on whether you're using setReport or updateData - the one updateData uses looks like this:

           i9(f) {
var c = {};
e.w(f.dataSourceType) || (c.dataSourceType = f.dataSourceType);
e.w(f.type) || (c.dataSourceType = f.type);
e.w(f.proxyUrl) || (c.proxyUrl = f.proxyUrl);
e.w(f.dataSourceInfo) || (c.dataSourceInfo = f.dataSourceInfo);
e.w(f.catalog) || (c.catalog = f.catalog);
e.w(f.cube) || (c.cube = f.cube);
e.w(f.subquery) || (c.subquery = f.subquery);
e.w(f.localeIdentifier) ||
(c.localeIdentifier = f.localeIdentifier);
e.w(f.effectiveUserName) ||
(c.effectiveUserName = f.effectiveUserName);
e.w(f.customData) || (c.customData = f.customData);
e.w(f.filename) || (c.filename = f.filename);
e.w(f.requestHeader) || (c.requestHeaders = f.requestHeader);
e.w(f.requestHeaders) || (c.requestHeaders = f.requestHeaders);
e.w(f.fieldSeparator) || (c.fieldSeparator = f.fieldSeparator);
e.w(f.thousandSeparator) ||
(c.thousandSeparator = f.thousandSeparator);
e.w(f.recordsetDelimiter) ||
(c.recordsetDelimiter = f.recordsetDelimiter);
e.w(f.browseForFile) || (c.browseForFile = f.browseForFile);
e.w(f.data) || (c.data = f.data);
e.w(f.binary) || (c.binary = f.binary);
e.w(f.ignoreQuotedLineBreaks) ||
(c.ignoreQuotedLineBreaks = f.ignoreQuotedLineBreaks);
e.w(f.roles) || (c.roles = f.roles);
e.w(f.hash) || (c.hash = f.hash);
e.w(f.username) || (c.username = f.username);
e.w(f.password) || (c.password = f.password);
e.w(f.host) || (c.host = f.host);
e.w(f.node) || (c.node = f.node);
e.w(f.index) || (c.index = f.index);
e.w(f.mapping) || (c.mapping = f.mapping);
e.w(f.useStreamLoader) || (c.useStreamLoader = f.useStreamLoader);
e.w(f.url) || (c.url = f.url);
return c;
}

As you can see it's copying everything except withCredentials.
Are you able to fix this, and is there any way to work around it in the meantime? I've tried using setReport instead but that has its own set of quirks - namely it causes the field list to appear and reappear even though configuratorActive is always set to true.

Public
Vera Didenko Vera Didenko Flexmonster March 2, 2021

Hello, Alex,
 
Nice to meet you!
 
Thank you for reporting this behavior to us.
Our team will look into this in more detail, and we will provide the fix in the minor release version of Flexmonster with the ETA 22nd of March.
 
In the meantime, we kindly suggest using the getReport() and setReport() API calls as a workaround. 
As for the Field List appearing and disappearing, the Field List could be hidden by specifying the configuratorActive: false report option.
We have prepared a JSFiddle for illustration: https://jsfiddle.net/flexmonster/ky1pcam3/.
 
Please let us know if this would work for you.
Looking forward to your response.
 
Kind regards,
Vera

Public
Alex Gilleran March 2, 2021

Hi Vera  - thanks so much for that, I'll look forward to the release!
For the field list, you can actually see the behaviour I'm describing in your fiddle if you just turn configuratorActive to true - https://jsfiddle.net/z13peLhd/1/. We want the field list to always be shown unless the user specifically hides it (we put it at the right, as per the fiddle link), but every setReport call toggles from hidden to shown or from shown to hidden.

Public
Vera Didenko Vera Didenko Flexmonster March 3, 2021

Hello, Alex,
 
Thank you for your reply. 
 
Regarding the Field List not being restored, thank you for providing additional details.
We would like to confirm that this is not the expected behavior. Our team will provide the fix to this in the minor release version of Flexmonster with the ETA 22nd of March.
 
In the meantime, a possible solution to restore the Field List settings is to listen to the reportcomplete event and use the openFieldsList() API call.
We have modified the provided JSFiddle so that the Field List is restored after setReport() takes place: https://jsfiddle.net/flexmonster/5egmqtaz/.
 
Please let us know if this helps.
 
Kind regards,
Vera

Public
Vera Didenko Vera Didenko Flexmonster March 24, 2021

Hello, Alex,
 
We are happy to inform you that the issue with the Field List position settings not getting restored was fixed. Also, the issue with withCredentials not applied using updateData() was fixed.
 
This is available in the latest version of Flexmonster.
You are welcome to update the component. Here is our updating to the latest version guide for assistance.
 
Please let us know if the fix works fine for you.
Looking forward to your response.
 
Kind regards,
Vera

Public
Alex Gilleran March 24, 2021

Thanks Vera, we'll give it a go!

Public
Vera Didenko Vera Didenko Flexmonster April 6, 2021

Hello, Alex,
 
Our team is wondering if the provided fix works fine for you.
 
Please let us know if the update helped to resolve the issue.
We would be grateful for your feedback.
 
Kind regards,
Vera

Public
Vera Didenko Vera Didenko Flexmonster April 13, 2021

Hello, Alex,
 
Just checking in to ask if you've had a chance to try out the update.
Did it resolve the issue with the Field List position settings not getting restored and withCredentials not getting applied when using updateData()?
 
Please let us know if everything works fine for you.
Looking forward to your response.
 
Kind regards,
Vera

Public
Alex Gilleran April 25, 2021

Hi Vera,
 
Sorry about the delay, just circled back to this - it works great in the new version, thanks so much for the fix!
 
Thanks,
Alex

Please login or Register to Submit Answer