wp-net / WordPressPCL

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

"Invalid status" error #311

Open DorYos opened 2 years ago

DorYos commented 2 years ago

Post ID: 1859 is scheduled.

When I try to run this code: var poststatus = await client.PostStatuses.GetByIDAsync(1859);

I get an error: "Invalid status"

Also when I try to use this code:

var queryBuilder = new PostsQueryBuilder
                {
                    PerPage = 50,
                    Page = 1,
                    Order = Order.DESC,
                    //OrderBy = PostsOrderBy.Modified,
                    Statuses = new List<Status> { Status.Future, Status.Pending }
                };
                var postsTask = await client.Posts.QueryAsync(queryBuilder);

I get the following Exception error: Invalid parameter(s): status

WordPressPCL.Models.Exceptions.WPException: 'Invalid parameter(s): status'
{{
  "status": 400,
  "params": {
    "status": "Status is forbidden."
  },
  "details": {
    "status": {
      "code": "rest_forbidden_status",
      "message": "Status is forbidden.",
      "data": {
        "status": 401
      }
    }
  }
}}
ThomasPe commented 2 years ago

Since unauthorized calls are only allowed to see Posts with the Status Publish (which is the default) you'll need to tell the Query that it should send auth headers:

var postsTask = await client.Posts.QueryAsync(queryBuilder, true);