Sample code for 30+ languages & platforms
React Native

Update an Inventory Listing using OAuth1 Authentication

See more Etsy Examples

Updates an inventory listing. This example uses OAuth1 authentication instead of providing an api_key=MY_ETSY_KEYSTRING query parameter.

Chilkat React Native Downloads

React Native
import { JsonObject, OAuth1, Rest } from '@chilkat/react-native'

async function chilkatExample() {
  // This example assumes the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  const rest = new Rest();

  // See this example for getting an OAuth1 token for Etsy

  const json = new JsonObject();
  try {
    json.loadFile('qa_data/tokens/etsy.json');
  } catch {
    console.log('Failed to load previously fetched Etsy OAuth1 access token.');
    return;
  }

  const oauth1 = new OAuth1();

  oauth1.consumerKey = 'app_keystring';
  oauth1.consumerSecret = 'app_shared_secret';
  oauth1.token = json.stringOf('oauth_token');
  oauth1.tokenSecret = json.stringOf('oauth_token_secret');
  oauth1.signatureMethod = 'HMAC-SHA1';
  oauth1.genNonce(16);

  const autoReconnect = true;
  const tls = true;
  try {
    await rest.connectAsync('openapi.etsy.com', 443, tls, autoReconnect);
  } catch {
    console.log(rest.lastErrorText);
    return;
  }

  // Tell the REST object to use the OAuth1 object.
  rest.setAuthOAuth1(oauth1, true);

  const jsonText = '[{"product_id":1999949999,"property_values":[],"offerings":[{"offering_id":9999905883,"price":"36.23","quantity":1}]}]';

  rest.addQueryParam('products', jsonText);
  rest.addHeader('Content-Type', 'application/x-www-form-urlencoded');

  let jsonResponseText: string;
  try {
    jsonResponseText = await rest.fullRequestFormUrlEncodedAsync('PUT', '/v2/listings/228827035/inventory');
  } catch {
    console.log(rest.lastErrorText);
    return;
  }

  const jsonResponse = new JsonObject();
  jsonResponse.load(jsonResponseText);
  jsonResponse.emitCompact = false;

  console.log(jsonResponse.emit());

  console.log(`Response status code: ${rest.responseStatusCode}`);
}