GET 'ing discount codes for me works just fine:
e.g. /admin/api/2019-07/price_rules/507328175/discount_codes.json
But not able to retrieve (GET) or update (PUT) single discount codes using below (seems to be an error in both IDs in url being the same ... mmmm:
/admin/api/2019-07/price_rules/507328175/discount_codes/507328175.json
For PUT'ing, I pass the parameters just like the example:
{ "discount_code": { "id": 507328175, "code": "WINTERSALE20OFF", "usage_count": 0, "created_at": "2019-08-08T14:48:57-04:00", "updated_at": "2019-08-08T14:48:57-04:00" } }
This looks funky in the DOCs: price rule ID and discount code ID should be different, no?
PUT/admin/api/2019-07/price_rules/507328175/discount_codes/507328175.json
Anyone see what I am missing? Is this me or the API?
My long code below using live/real ids for discount code and price rule;
$url = "https://$shopify_api_key:$shopify_api_password@".$shop."/admin/api/2019-07/price_rules/384286621759/discount_codes/1646809677887.json";
$params = '{"discount_code": {"id": 1646809677887, "code": "COUPONTEST", "usage_count": 1, "created_at": "2019-09-18T14:48:57-04:00", "updated_at": "2019-09-18T14:48:57-04:00"}}';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json;charset=utf-8'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-Shopify-Access-Token:'.$shop_token));
$json_response = curl_exec($curl);
curl_close($curl);
$result = json_decode($json_response, TRUE);
Hi @Gravy_Sales,
The discount code ID and price rule ID would not be the same you are correct, the documentation just has fake values in it. The $url you have provided in your code below looks like the URL is correct. Is this still an issue if you use different IDs?
Cheers,
Ryan
Great idea, Ryan - I will look into that X-Header test and advise.
Here is my X-Request-ID:1234. I have been playing with various form PUT requests to no avail...
tx
Chris
The Request ID header is a response header provided by Shopify after you make the call, you don't provide it to us.
On my end there doesn't seem to be any issues, so it's likely something wrong with your request, if you could provide more details even in lieu of the request ID I would be able to help more (request ID is still the best).
Ryan
Ah, OK, I thought you could see the API requests for that ID on your end... I'll keep playing with this on my end then and look for that ID, not sure where but will start Googling... It could be my PUT form, but I see the data posted in Chrome Inspector..
OK, can you try seeing what you get on your end using X-Request-ID:30f14c6c1fc85cba12bfd093aa8f90e3
This is now valid given over 20 characters etc. and I've PUT'ed a few times with my form to test updating a price rule title.
User | Count |
---|---|
25 | |
8 | |
7 | |
5 | |
4 |