#FireCoder-dotnet-subscription
1 messages ยท Page 1 of 1 (latest)
You should be able to do that as long as the product names are within four levels of expansion. The expand parameter is an array of strings and you can pass as many parameters to expand as you want as long as none of them are further than four levels
Or are you already trying that and product names are deeper than that?
So customer would be 1 level deep. Then we have items.data.price.data.product
so, beyond 4 levels
Unless I'm not understanding
The product field is directly on the price object, so you should be able to do items.data.price.product https://stripe.com/docs/api/prices/object#price_object-product
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Have you already tried expanding with that?
But I also need to get the full customer object
Or can we do .AddExpand[] more than once?
So you can pass expand=["customer", items.data.price.product"]
Yes I think so
That is the java library right?
C#
Hmm, doesn't seem to be correct syntax
I am able to use .AddExpand more than once though. At least at the moment. I won't know for sure until I run the app.
Uff that didn't work.
Did you get an error?
Cannot convert from Stripe.SubscriptionListOptions to string
Can you paste your C# code for this call so I can take a look?
Would you like a snip or code?
Code, the text of the code will be best to look at
public async Task<List<SubscriptionModel>> GetSubscriptions()
{
var subscriptionOptions = new SubscriptionGetOptions()
{
Expand = { "customer", "items.data.price.product" }
};
var service = new SubscriptionService();
await service.GetAsync(subscriptionOptions);
}
Yeah I know I should use SubscriptionListOptions, I changed and forgot to change back. Still same message though.
Ahh 1 sec. Maybe I need to use ListAsync
Ok, that cleared things up.
Oh nice! So you are getting all the info back that you want now?
I'm not sure just yet. I just know that the errors went away in VS. I'm working on the rest of the method and then I'll be able to test.
Sounds good, just let me know
Ok, so I'm unable to access Price or Product from x. I'll paste code.
return results.GetRange(0, results.Count() >= maxrecords ? maxrecords : results.Count())
.Select(x => new SubscriptionModel(x.Id)
{
Id = _guidGenerator.Create(),
SubscriptionId = x.Id,
CustomerName = x.Customer.Name,
Product = x.Items.Data.
}).ToList();
Do you have the ID of a subscription that you got back from that call that you didn't see that data for?
Nope. This is strictly in code. I haven't even gotten that far due to not being able to assign values.
Oh gotcha. Misunderstood the question. I'm not that familiar with our .NET library, is SubscriptionModel a class from our stripe-dotnet library?
No. it's a custom model that I made.
However, all the other items are being assigned values unless they are contained within Items.Data
Oh I see, I mixed up some of the code here. So x should be a Subscription object then? Is VS recognizing it as just a generic object or does it know that it will be a Subscription here?
Ok, so I have to use an indexer to get Price and Product. Like data[0].Price etc. Hmm
Yes, x is a Subscription object and yes, VS is recognizing x as a Subscription object.
Gotcha, I see now, yes the Items property on a Subscription object is a list so you need to access the Product property on a specific item in the list.
Cool. Thanks again for your help and patience.
Of course, and I am actually stepping out right now but my colleague two-shoes will be able to help if you have any followups
Great, thanks again.
@cobalt hollow hello. Pompey stated I could contact you if I ran into further issues.
Hi ๐ how can I assist?
I'm having some issues expanding subscriptions out. I'm trying to get the full customer, product and price.
I'd like to display: Customer.Name, Product.Name and Price.UnitPrice.
I'm hitting a null ref error no matter what I do. I"m probably not using correct syntax.
VS Studio
That's C# yeah?
Yes
Which object is null? It's hard to tell from the screenshot. Can you mouse over each of them?
sure
One of them is not being instantiated properly, I'm just not sure which one
If I remove Expand = {"customer"} I do get results back
initialPageOptions, when hovering over it says it's null. Which I'm not sure how that is...
interesting, okay. That's fine, it's probably null up until runtime.
Can you try this syntax in place of the line where you have Expand?
['expand' => ['customer']]
Expand = ["expand" => ["customer"]]
If that's what you meant, it does not like the syntax.
Ah, apologies. There was a bug with how my browser was displaying .NET on this page: https://stripe.com/docs/api/expanding_objects?lang=dotnet which caused me to send you PHP code
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
LOL. I didn't think that looked correct.
Yeah, it took me a second
Okay, so the example looks like this:
var service = new ChargeService();
var options = new ChargeGetOptions();
options.AddExpand("customer");
options.AddExpand("invoice.subscription");var charge = service.Get("ch_1EOeV7ILwdSSnvJbIahCycKI", options);
But that's for charges
Yeah, but should be able to be modified for other stuff I'd imagine.
Yup, exactly. So let me peek at the library
I'll circle back in a couple of minutes
Ok
Expand = new List<string> { "data.customer" }
Since Expand is a List<string>. I got what I needed, I believe. Hopefully I can expand more.
That worked for you? Apologies. I got caught up between getting the standard example to work and trying to adapt it to what you already have
It's ok. Yes, that did work. Now I just need to get product name and price.
Well, if you got Customer already, then those shouldn't be too far off. They're nested under data.price and data.price.product on the Subscription object
so I don't need to use data.items.data.price....?
I should just be able to use data.price?
I'm not sure. I think in your code you already have subscription.data, since you were able to get data.customer right?
yes
So you have subscription.data.customer, then I think you're right. You just need to get subscription.data.items.data.price and subscription.data.items.data.price.product
Hi ๐ I'm stepping in because @cobalt hollow needs to go.
Ok
The price and product info is actually exactly at 4 levels deep (you don't include the subscription when passing in the Expand parameters
Right now I have data.items.data.price
Yup, 4 levels
But the product name isn't in there, at least from what I can see.
I get the product id, but I need to display the product name.
Yeah, that may require a 2nd API call
Hmm
Ok. That's what I was thinking. Thanks to you both for your help. I'll give this a try and let ya know.
I hope it works out for you but we'll be here for any additional questions you might have.
thanks