Sample code for 30+ languages & platforms
Dart

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 Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

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

  final rest = CkRest();

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

  final json = CkJsonObject();
  try {
    json.loadFile('qa_data/tokens/etsy.json');
  } on ChilkatException {
    print('Failed to load previously fetched Etsy OAuth1 access token.');
    return;
  }

  final oauth1 = CkOAuth1();

  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);

  final autoReconnect = true;
  final tls = true;
  try {
    rest.connect('openapi.etsy.com', 443, tls, autoReconnect);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

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

  final 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');

  final String jsonResponseText;
  try {
    jsonResponseText = rest.fullRequestFormUrlEncoded('PUT', '/v2/listings/228827035/inventory');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final jsonResponse = CkJsonObject();
  jsonResponse.load(jsonResponseText);
  jsonResponse.emitCompact = false;

  print(jsonResponse.emit());

  print('Response status code: ${rest.responseStatusCode}');
}