#khorgnil
1 messages · Page 1 of 1 (latest)
Hello! You can retrieve Promotion Codes from the API by their code: https://stripe.com/docs/api/promotion_codes/list#list_promotion_code-code
And then the Promotion Code object you get back has the Coupon object in the coupon property: https://stripe.com/docs/api/promotion_codes/object#promotion_code_object-coupon
For your second question I'm not sure what you mean. I'm not a Go developer, so I might not be understanding what you mean by "filter". Can you provide more details?
Thanks @ripe olive , that's perfect.
For my second question, I'm not sure if this problem is Go-specific or what, but all the list-based API calls have a Filter parameter. Look at this sample code in the same API you linked:
stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"
params := &stripe.PromotionCodeListParams{}
params.Filters.AddFilter("limit", "", "3")
i := promotioncode.List(params)
for i.Next() {
pc := i.PromotionCode()
}
Note the line params.Filters.AddFilter(...) All other list-based APIs have something similar. Where is that documented?
Seems like that's how you specify the limit property: https://stripe.com/docs/api/promotion_codes/list#list_promotion_code-limit
That's likely also how you specify the code parameter.
I get that's what that particular exasmple is doing, but if you look at the code, it seems far more general than that. Besides, that's a opretty complicated mechanism to only lim,it the number of returns?
For example, there are three parameters, not two. The middle parameter is named 'op', anmd in the example it's blank. What are the other 'op's?
I'm not sure why it's implemented that way in our Go library. The library is open source, though, so you can take a look to see how it works and what it's doing with the parameters. For example: https://github.com/stripe/stripe-go/blob/d038ebbf7b3100fb94bfb4ac21874a5dbfaba25e/promotioncode/client.go#L67-L87
I was really looking for documentation about how to use filters. The example makes sense, but leaves more questions than answers. It doesnt sound like there is any documentation for how filters work in List-based APIs in the go API.
Sorry, I'm not following. Can you tell me why you're looking for that documentation? What would it enable you to do that you can't do now?
Don'
Don't sweat it, man. I don't think my question has an answer, and it's just a quirk of the documentation.
Okay. Sorry, don't have anyone around who's familiar with Go right now. 😅
That said, I will say that the documentation does appear to br wrong at least in this particular case.
Specifically, the documentation lists 'limit' as a direct member of the 'PromotionCodeListParams' type, but it is not. Also, the example code doesn't show 'limit' being set as a member of 'PromotionCodeListParams' -- it shows it being set using a completely different facility: some undocumented 'Filter' thingy
I can flag that internally, or you can post an issue on the GitHub Go library repo if you want a response from the team that maintains that library.