ShopifySharp icon indicating copy to clipboard operation
ShopifySharp copied to clipboard

null ref when creating discountcode from price rule

Open RealCosmik opened this issue 4 years ago • 1 comments

Hi, so I am trying to make a discount code using shopify. I already have the price rule set up on the shopify dash i just would like to make codes from it but it seems that i get a null ref when trying to create the discount code.

        var rulingservice= new PriceRuleService(ShopLink, password);
        var codeservice = new DiscountCodeService(ShopLink, password);
        var allrules = await rulingservice.ListAsync() as List<PriceRule>;
        var jbsrule=allrules.Single(rule => rule.Title == "JBSTEST");
        var testcode = await codeservice.CreateAsync(jbsrule.Id.Value, new PriceRuleDiscountCode()
        {
            Code=jbsrule.Title,//setting discount code to be the same as rule title
            PriceRuleId=jbsrule.Id.Value// settings this or leaving default made no diff
            
        });

a null ref exception is thrown by the DiscountCodeService when trying to make a pricerulediscount code instance via the createAsync method. then i went on to think perhaps it was the DiscountService class that i should be using but that just throws a error not found exception. i am a shopify plus member and im certain these are the correct links and passwords for my private app. any idea whats going on?

RealCosmik avatar Jan 18 '20 08:01 RealCosmik

Thanks for filing this report! Can you paste the full exception message and stack trace for this? That will help me figure out where the problem lies.

nozzlegear avatar Jan 18 '20 16:01 nozzlegear