C
C
Shopify Receive Count of All Products in a Collection
See more Shopify Examples
Get a count of all products of a given collectionChilkat C Downloads
#include <C_CkRest.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>
void ChilkatSample(void)
{
BOOL success;
HCkRest rest;
HCkStringBuilder sbJson;
HCkJsonObject json;
int count;
success = FALSE;
rest = CkRest_Create();
CkRest_SetAuthBasic(rest,"SHOPIFY_PRIVATE_API_KEY","SHOPIFY_PRIVATE_API_KEY");
success = CkRest_Connect(rest,"chilkat.myshopify.com",443,TRUE,TRUE);
if (success != TRUE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
return;
}
sbJson = CkStringBuilder_Create();
success = CkRest_FullRequestNoBodySb(rest,"GET","/admin/products/count.json?collection_id=841564295 ",sbJson);
if (success != TRUE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
CkStringBuilder_Dispose(sbJson);
return;
}
if (CkRest_getResponseStatusCode(rest) != 200) {
printf("Received error response code: %d\n",CkRest_getResponseStatusCode(rest));
printf("Response body:\n");
printf("%s\n",CkStringBuilder_getAsString(sbJson));
CkRest_Dispose(rest);
CkStringBuilder_Dispose(sbJson);
return;
}
json = CkJsonObject_Create();
CkJsonObject_LoadSb(json,sbJson);
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
count = CkJsonObject_IntOf(json,"count");
// A sample JSON response body that is parsed by the above code:
// {
// "count": 1
// }
printf("Example Completed.\n");
CkRest_Dispose(rest);
CkStringBuilder_Dispose(sbJson);
CkJsonObject_Dispose(json);
}