Has anyone used the contentful sdk with NativeScript?

Hi all

I’m new to Contentful and hoping to use it in an app I am building using NativeScript. I’ve downloaded the boiler plate code from the Contentful API’s section and that runs fine; returns the content types from my portal, etc however if I try and do this from within my NativeScript app nothing happens - createClient stops the execution of my native script view model but there are no errors or warnings. Wondered if anyone had tried this before and managed to get it working.

Thanks
Tim

I played ones with NativeScript and ended up with implementing the HTTP calls myself…

const fetchModule = require('fetch');
...
function loadItems() {
  return fetchModule.fetch(
      `https://cdn.contentful.com/spaces/${config.space}/entries?access_token=${config.cda.token}&content_type=event&order=fields.start`,
      {
        method: "GET",
        headers: {
          'Content-Type': 'application/json'
        }
      }
    )
    .then( response => response.json() )
}

I don’t remember though what the exact problem was (it’s a year ago) but I assume that axios (that’s what the SDK uses) doesn’t work in native script either because HTTP is work their in another way?

Could you check if that’s the case?

Hope that helps.

Thanks for the reply!

I did some more digging after submitting the post and yes it does seem to be incompatible. After installing the nativescript-nodeify module the Contenful SDK throws an error: window is not defined. It seems it tries to detect a browser but of course this doesn’t exist. I see support for React Native in the contentful module but it triggers the else statement and assumes it is running in a browser.

I think Axiom itself might work ok if this was fixed.

The reason I wanted to use the SDK is because I need to support sync for offline content. Is it possible to implement that easily without the SDK ?

Thanks
Tim

Ja I don’t know enough about the NativeScript environment to help here to be a real help. :frowning:

The reason I wanted to use the SDK is because I need to support sync for offline content. Is it possible to implement that easily without the SDK ?

Looking at the underlying SDK code I might be “doable” relatively quickly.
(I might also underestimating that, too :wink: )

https://github.com/contentful/contentful.js/blob/master/lib/create-contentful-api.js#L267-L270
https://github.com/contentful/contentful.js/blob/master/lib/paged-sync.js#L44-L68

Thanks :slight_smile:

Hmmm I might try React Native instead. It would be cool if Contentful supported NativeScript but I understand it might not be as popular.

I will see how I get on