Using the Warranty API with cURL

We received a message from a frustrated forum participant who wanted to know why our API returned unusable characters instead of usable data.

Gzipped

The Product Warranty API uses compression (gzip) to return the status of existing jobs and the results of completed jobs. This data must be uncompressed when it reaches the client - otherwise, what you see will look something like this:

??Qk?0E?J?sթ??eilm?o?m?Pld??XE??%*??

>


?w?mJr???????_q8??E????K

                        Fh?F?????f    ???kY~{?0z?,<9{??J??l?a?ԶY??.M????a/??W`??WM?s?}x???M?v93??Q}Z?4??׻?3???OG?E%E?r?! ??T%(?R??A?b?b?xB??lB?I?F$U?H?2?}????TA?ëU?K

핞?]Y?4???Z???4k79 U?b*?b??38??f?

                                 ?g[]y?4??????G????N?E)0EA??<?k?d??]Z%i???G??l?????:???G???    ?8?????F\Gz

The affected participant was using cURL to manage warranty lookups, but had not included the --compressed flag (which will automatically treat retrieved content as compressed and uncompress it for you) when checking the status of batch jobs.

cURL code

If you would like to use cURL to manage your warranty lookups, a typical set of commands might look like this:

1. Create an access token using your API key and API secret. The access token is necessary for the remaining steps.

# Create an access token (No --compress flag needed):

curl  -d "apiKey=API_KEY&apiSecret=API_SECRET&grantType=client_credential&scope=warranty" -X POST "https://css.api.hp.com/oauth/v1/token" -H "Accept: application/json"

# Returns: {"access_token":"ACCESS_TOKEN","expires_in":"3599","scope":"warranty"}
# Replace "API_KEY" and "API_SECRET" with your key and secret. "ACCESS_TOKEN" will be a string you use as a bearer token for authentication.

2. Create a batch job comprised of serial numbers and (optionally) product numbers.

# Create new batch job (No --compress flag needed):

curl -d '[{"sn":"SERIAL_NUMBER_1", "pn":"PRODUCT_NUMBER_1"},{"sn":"SERIAL_NUMBER_2", "pn":"PRODUCT_NUMBER_2"},...]' -X POST "https://css.api.hp.com/productWarranty/v1/jobs" -H "Content-Type: application/json" -H "Authorization: Bearer ACCESS_TOKEN" -H "Accept: application/json"

# Returns: {"jobId":"JOB_ID","estimatedTime":ESTIMATED_TIME}
# Replace "SERIAL_NUMBER_#" and "PRODUCT_NUMBER_#" with serial numbers and product numbers.
# Note: Product numbers are optional.

3. Check the status of the batch job. The amount of time it takes is a function of how many serial numbers you need to look up. Batch jobs theoretically can accept up to 5000 serial numbers.

# Check the status of the batch job (--compressed flag required):

curl --compressed "https://css.api.hp.com/productWarranty/v1/jobs/JOB_ID" -H "Authorization: Bearer ACCESS_TOKEN" -H "Accept: application/json"

# Returns: {"jobId":"JOB_ID","status":"STATUS","productsProcessed":PRODUCT_COUNT,"expirationDate":"DATE"}
# Replace "JOB_ID" with the jobId returned in step 2.
# Note: A status of "completed" will be returned when the entire batch job is finished.

4. Retrieve the results of the job.

# Retrieve the results (--compressed flag required):

curl --compressed "https://css.api.hp.com/productWarranty/v1/jobs/JOB_ID/results" -H "Authorization: Bearer ACCESS_TOKEN" -H "Accept: application/json"

# Returns: <Array of results for each entry submitted>
# Note: Each member of the array will have a "status" field indicating whether its warranty is expired.

IMPORTANT NOTE: Steps 3 and 4 require the --compressed flag.

Author : damon.kaswell