Java
Chilkat2 Java
Shopify Receive Count of All Products in a Collection
See more Shopify Examples
Get a count of all products of a given collectionChilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.Rest;
import com.chilkatsoft.chilkat2.StringBuilder;
public class ChilkatExample {
public static void main(String[] args) {
Rest rest = new Rest();
rest.setAuthBasic("SHOPIFY_PRIVATE_API_KEY", "SHOPIFY_PRIVATE_API_KEY");
try {
rest.connect("chilkat.myshopify.com", 443, true, true);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
StringBuilder sbJson = new StringBuilder();
try {
rest.fullRequestNoBodySb("GET", "/admin/products/count.json?collection_id=841564295 ", sbJson);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
if (rest.getResponseStatusCode() != 200) {
System.out.println("Received error response code: " + rest.getResponseStatusCode());
System.out.println("Response body:");
System.out.println(sbJson.getAsString());
return;
}
JsonObject json = new JsonObject();
json.loadSb(sbJson);
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
int count = json.intOf("count");
// A sample JSON response body that is parsed by the above code:
// {
// "count": 1
// }
System.out.println("Example Completed.");
}
}