Fetch Admin/products.json via React-Native using expo

Shopify Partner
1 0 0

Hi,

So I'm trying to connect to my shopify products using a fetch command on react-native. I'm getting mixed results.

 

export default class App extends Component<> {
  constructor(props) {
    super(props);
	 this.state ={ isLoading: true}
  } 

componentDidMount(){  
    return fetch("https://[###]:[###]@dlars-fashion.myshopify.com/admin/products.json")
.then((response) => response.json())
.then((responseJson) => {
         this.setState({
          isLoading: false,
         dataSource: responseJson,
      
        }, function(){		
        });
      })
      .catch((error) =>{
        console.error(error)
      });
  }  
  render(){
    if(this.state.isLoading){
      return(
        <View style={{flex: 1, padding: 20}}>
          <ActivityIndicator/>
        </View>
      )
    }

    return(
      <View style={{flex: 1, paddingTop:20}}>
        <FlatList
          data={ this.state.dataSource.orders}

          renderItem={({item}) => <Text>{item.id}</Text>}

           keyExtractor={({id}, index) => id}
        />
      </View>
    );
  }
}

The above code gives me a blank screen with no errors.

If I change the products.json to orders.json I get results so that works fine.

I checked my private apps setting and everything is in order (read and write on products is active)

Onto postmaseter, everything works fine there and I even tried using PHP curl and that works too.

 

So my only issue is on react-native with products.json. Can anyone tell me why this isn't working for me?

Does it have anything to do with needing to use GraphQl, I read the shopify page that shopfiy storefornt only works with GraphQl.

At this moment all I want to do is connect to products.json using react-native.

 

Thanks,

 

Ahmed

0 Likes