React Native Requires Chilkat v11.0.0+
React Native
Shopify Private Authentication for Private Apps
See more Shopify Examples
Shopify private authentication is for interacting with your own store through private applications. It uses HTTP "Basic" authentication with your Shopify private application key and secret key.This example demonstrates how to send a private authenticated request using Chilkat Http, and then the same using Chilkat Rest.
Chilkat React Native Downloads
import { Http, HttpResponse, JsonObject, Rest, StringBuilder } from '@chilkat/react-native'
async function chilkatExample() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// First demonstrate sending a simple request using Shopify private authentication w/ the Chilkat Http API.
const http = new Http();
// To use HTTP Basic Authentication with any HTTP request, we simply set the Login, Password, and BasicAuth properties.
// Important: All HTTP requests using Basic authentication must be over SSL/TLS.
http.login = 'SHOPIFY_PRIVATE_API_KEY';
http.password = 'SHOPIFY_PRIVATE_API_SECRET_KEY';
http.basicAuth = true;
// Make sure to replace "chilkat" with your store name.
const resp = new HttpResponse();
try {
await http.httpNoBodyAsync('GET', 'https://chilkat.myshopify.com/admin/products.json', resp);
} catch {
console.log(http.lastErrorText);
return;
}
// Examine the response code.
if (resp.statusCode !== 200) {
console.log(`Received error response code: ${resp.statusCode}`);
console.log('Response body:');
console.log(resp.bodyStr);
return;
}
// Success.
console.log('Success.');
// Examine the JSON response
const sbJson = new StringBuilder();
resp.getBodySb(sbJson);
const json = new JsonObject();
json.loadSb(sbJson);
json.emitCompact = false;
console.log(json.emit());
// -------------------------------------------------
// Now let's do the same using the Chilkat Rest API.
const rest = new Rest();
// Provide the private app credentials:
rest.setAuthBasic('SHOPIFY_PRIVATE_API_KEY', 'SHOPIFY_PRIVATE_API_SECRET_KEY');
// Connect to the shopify server.
const bTls = true;
const port = 443;
const bAutoReconnect = true;
// Make sure to replace "chilkat" with your store name.
try {
await rest.connectAsync('chilkat.myshopify.com', port, bTls, bAutoReconnect);
} catch {
console.log(rest.lastErrorText);
return;
}
sbJson.clear();
try {
await rest.fullRequestNoBodySbAsync('GET', '/admin/products.json', sbJson);
} catch {
console.log(rest.lastErrorText);
return;
}
if (rest.responseStatusCode !== 200) {
console.log(`Received error response code: ${rest.responseStatusCode}`);
console.log('Response body:');
console.log(sbJson.getAsString());
return;
}
// Success...
json.loadSb(sbJson);
console.log(json.emit());
}