wp-net / WordPressPCL

This is a portable library for consuimg the WordPress REST-API in (almost) any C# application
MIT License
337 stars 129 forks source link

Woocommerce CustomRequest #210

Closed Alirss closed 4 years ago

Alirss commented 4 years ago

Hello.

I am working on a small project. Users log in to their account and they see a list of their downloadable orders.

But there is always 401 error.

`
public class OrderItems { public string download_id; public string download_url; public int? product_id; public string product_name; }

   var client = new WordPressClient("https://zenithartwork.ir/wp-json/");
        client.AuthMethod = AuthMethod.JWT;
        await client.RequestJWToken(user, pass);
        var forms = client.CustomRequest.Get<IEnumerable<OrderItems>>("wc/v3/customers/" + client.Users.GetCurrentUser().Result.Id + "/downloads");

`

Is there a way to see the orders download link?

ThomasPe commented 4 years ago

I haven't worked with Woocommerce yet, but 401 indicates there's an auth issue. Are you able to get regular posts using the credentials you've passed?

polushinmk commented 4 years ago

@Alirss seems that you should set parameter useAuth to true

var forms = client.CustomRequest.Get<IEnumerable<OrderItems>>("wc/v3/customers/" + client.Users.GetCurrentUser().Result.Id + "/downloads", useAuth: true);

by default all GET requests performs without providing authorization header

Alirss commented 4 years ago

@Alirss seems that you should set parameter useAuth to true

var forms = client.CustomRequest.Get<IEnumerable<OrderItems>>("wc/v3/customers/" + client.Users.GetCurrentUser().Result.Id + "/downloads", useAuth: true);

by default all GET requests performs without providing authorization header

Thank for your answer. But this method does not make a difference.

Alirss commented 4 years ago

I haven't worked with Woocommerce yet, but 401 indicates there's an auth issue. Are you able to get regular posts using the credentials you've passed?

Yes. Everything else is almost working.

Alirss commented 4 years ago

OK. I did something different.

Using a small "API", I matched the orders with the user's email. This gives me "Product_id" , "DownloadKey" and "Orderkey" , which can also be used to find the product name.

So the download link will be like this : https://example.com/?download_file="Product_id"&order="Orderkey"&email="Email"&key="DownloadKey"

So my problem is solved. I hope this problem will be fixed in the future.