Unicode C
Unicode C
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 Unicode C Downloads
#include <C_CkRestW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkOAuth1W.h>
void ChilkatSample(void)
{
BOOL success;
HCkRestW rest;
HCkJsonObjectW json;
HCkOAuth1W oauth1;
BOOL autoReconnect;
BOOL tls;
const wchar_t *jsonText;
const wchar_t *jsonResponseText;
HCkJsonObjectW jsonResponse;
success = FALSE;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
rest = CkRestW_Create();
// See this example for getting an OAuth1 token for Etsy
json = CkJsonObjectW_Create();
success = CkJsonObjectW_LoadFile(json,L"qa_data/tokens/etsy.json");
if (success == FALSE) {
wprintf(L"Failed to load previously fetched Etsy OAuth1 access token.\n");
CkRestW_Dispose(rest);
CkJsonObjectW_Dispose(json);
return;
}
oauth1 = CkOAuth1W_Create();
CkOAuth1W_putConsumerKey(oauth1,L"app_keystring");
CkOAuth1W_putConsumerSecret(oauth1,L"app_shared_secret");
CkOAuth1W_putToken(oauth1,CkJsonObjectW_stringOf(json,L"oauth_token"));
CkOAuth1W_putTokenSecret(oauth1,CkJsonObjectW_stringOf(json,L"oauth_token_secret"));
CkOAuth1W_putSignatureMethod(oauth1,L"HMAC-SHA1");
CkOAuth1W_GenNonce(oauth1,16);
autoReconnect = TRUE;
tls = TRUE;
success = CkRestW_Connect(rest,L"openapi.etsy.com",443,tls,autoReconnect);
if (success == FALSE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
CkJsonObjectW_Dispose(json);
CkOAuth1W_Dispose(oauth1);
return;
}
// Tell the REST object to use the OAuth1 object.
success = CkRestW_SetAuthOAuth1(rest,oauth1,TRUE);
jsonText = L"[{\"product_id\":1999949999,\"property_values\":[],\"offerings\":[{\"offering_id\":9999905883,\"price\":\"36.23\",\"quantity\":1}]}]";
CkRestW_AddQueryParam(rest,L"products",jsonText);
CkRestW_AddHeader(rest,L"Content-Type",L"application/x-www-form-urlencoded");
jsonResponseText = CkRestW_fullRequestFormUrlEncoded(rest,L"PUT",L"/v2/listings/228827035/inventory");
if (CkRestW_getLastMethodSuccess(rest) == FALSE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
CkJsonObjectW_Dispose(json);
CkOAuth1W_Dispose(oauth1);
return;
}
jsonResponse = CkJsonObjectW_Create();
CkJsonObjectW_Load(jsonResponse,jsonResponseText);
CkJsonObjectW_putEmitCompact(jsonResponse,FALSE);
wprintf(L"%s\n",CkJsonObjectW_emit(jsonResponse));
wprintf(L"Response status code: %d\n",CkRestW_getResponseStatusCode(rest));
CkRestW_Dispose(rest);
CkJsonObjectW_Dispose(json);
CkOAuth1W_Dispose(oauth1);
CkJsonObjectW_Dispose(jsonResponse);
}