sphereio / google-glass-demo

Sample application allowing to buy products managed in sphere.io using a google glass device.
http://dev.sphere.io/
MIT License
2 stars 3 forks source link

How to query a product by SKU? #3

Closed svenmueller closed 9 years ago

svenmueller commented 9 years ago

Answer

getting access token

find the proper project_id, client_id/client_secret values in the developer section of the merchant center:

https://admin.sphere.io/google-glass-demo/developers/clients

$ curl https://<client_id>:<client_secret>@auth.sphere.io/oauth/token -X POST -d "grant_type=client_credentials&scope=manage_project:<project_id>"
{"access_token":"XXXXXXXXXXXXX","token_type":"Bearer","expires_in":172800,"scope":"manage_project:google-glass-demo"}

querying product by SKU

Unencoded predicate used for querying

"masterData(current(masterVariant(sku=\"sku_MB_PREMIUM_TECH_T_variant1_1415189355070\")))"
$ curl "https://api.sphere.io/google-glass-demo/product-projections?where=masterVariant(sku%20%3D%20%22sku_MB_PREMIUM_TECH_T_variant1_1415189355070%22)%20or%20variants(sku%20%3D%20%22sku_MB_PREMIUM_TECH_T_variant1_1415189355070%22)" -H "Authorization: Bearer XXXXXXXXXXXXX"
{"offset":0,"count":1,"total":1,"results":[{"id":"f4d2cfe8-378a-4c55-b1a6-da02ac29fc7c","version":2,"productType":{"typeId":"product-type","id":"4c68efc5-e044-45d4-8408-eb127de8429b"},"name":{"en":"MB PREMIUM TECH T"},"description":{"en":"Sample description"},"categories":[{"typeId":"category","id":"03a6041a-7953-4dd0-9e03-2ac764520699"}],"slug":{"en":"mb-premium-tech-t1415189355070"},"masterVariant":{"id":1,"sku":"sku_MB_PREMIUM_TECH_T_variant1_1415189355070","prices":[{"value":{"currencyCode":"EUR","centAmount":10000}}],"images":[{"url":"https://www.commercetools.com/cli/data/253245821_1.jpg","dimensions":{"w":1400,"h":1400}}],"attributes":[]},"variants":[],"searchKeywords":{},"hasStagedChanges":false,"published":true,"taxCategory":{"typeId":"tax-category","id":"80aa5db7-c0a6-4590-a2ce-e8c8b7527d07"},"createdAt":"2014-11-05T12:09:15.090Z","lastModifiedAt":"2014-11-05T12:09:15.234Z"}]}
svenmueller commented 9 years ago

consider using our java sdk for easier API handling:

https://github.com/sphereio/sphere-jvm-sdk http://sphereio.github.io/sphere-jvm-sdk/javadoc/master/overview-summary.html

schleichardt commented 9 years ago

The JVM SDK works only for the Java Virtual Maschine (hence the name) - not Dalvik.

The legacy Java client works with Android, but has not sku finder yet: http://www.commercetools.com/sdk/io/sphere/client/shop/ProductService.html

butenkor commented 9 years ago

Maybe its worth to mention its not about JVM vs Dalvik but used Java version, right? There is a way of using java libs in Android if they are written with Java 6. With Android SDK based on KitKat (4.4) you can use Java 7 too but there is no support for Java 8 yet.

svenmueller commented 9 years ago

thx @schleichardt and @butenkor for the info

svenmueller commented 9 years ago

@sphereio/external-ingravity-media does this example (see above) help you?

fvillalbacar commented 9 years ago

Hope not to find any problem working with the library if its written in java 1.6 or 1.7. Tomorrow I'll check it. If I find any problem I'll tell you and we'll create a REST layer for the app. No worries about that.