Getting or Updating Single Discount Codes API Calls Not Working for Me

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);

 

 

 

 

0 Likes
Shopify Staff
Shopify Staff
472 35 90

Hi @Gravy_Referrals,

 

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

Developer Experience @ Shopify
0 Likes
Hi Ryan,
Thanks for reviewing... yes I keep testing with the 2 different IDs...
price rule id and discount id and still no luck... Maybe new 2019-07 api
has changed this function?
Chris
0 Likes
Shopify Staff
Shopify Staff
472 35 90

No, there shouldn't be any changes.  Can you share specifically which calls are failing and what the error is?  If you can provide the X-Request-ID from the header response that would be the most helpful.

 

Thanks.

Developer Experience @ Shopify
0 Likes

Great idea, Ryan - I will look into that X-Header test and advise.

0 Likes

Here is my X-Request-ID:1234.  I have been playing with various form PUT requests to no avail...

tx

Chris

0 Likes
Highlighted
Shopify Staff
Shopify Staff
472 35 90

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

Developer Experience @ Shopify
0 Likes

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..

0 Likes
Shopify Staff
Shopify Staff
472 35 90

We can see it from the Request-ID, but you provided "1234" which is not valid :)

Developer Experience @ Shopify
0 Likes

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.

0 Likes