I’m trying to figure out why I keep getting this error: "this must be a object
type, but the final value was: null
" when I post data to my strapi backend. I have a table called Post and I created a custom class in C# that mimics the data types and the table structure. All permissions on the table are open and I should be able to post to the api but that error keeps happening. Here is an example of the json that I’m sending and the code I’m using.
//My strapi url
var client2 = new RestClient(postUri);
var request = new RestRequest();
request.Method = Method.Post;
// serialize the object to JSON and add it as the request body
request.AddJsonBody(JsonConvert.SerializeObject(payload));
var response = client2.Execute(request);
string responseContent = response.Content;
{"data":[{"Id":"yt:video:o82sUI7AGh4","Title":"Who Sells the Cheapest Switch Games?","Summary":null,"Author":null,"Content":null,"PublishDate":"2023-03-19T16:00:35","LastUpdatedDate":"2023-03-19T16:05:32","Uri":"https://www.youtube.com/watch?v=o82sUI7AGh4","Image":null},{"Id":"yt:video:Ts1kR11zCFw","Title":"What is the cheapest Switch game at GameStop?","Summary":null,"Author":null,"Content":null,"PublishDate":"2023-03-17T20:00:15","LastUpdatedDate":"2023-03-17T20:29:41","Uri":"https://www.youtube.com/watch?v=Ts1kR11zCFw","Image":null},{"Id":"yt:video:YmUrm_65KVM","Title":"How to ship dozens of orders in one day #ad","Summary":null,"Author":null,"Content":null,"PublishDate":"2023-03-17T18:00:22","LastUpdatedDate":"2023-03-17T18:02:04","Uri":"https://www.youtube.com/watch?v=YmUrm_65KVM","Image":null}]}
Example of Json formatted in json viewer:
Any ideas why it’s throwing this error?
Here’s all of the code:
var feeds = await client.GetStringAsync(rssUri);
RssFeed? rssfeeds = System.Text.Json.JsonSerializer.Deserialize<RssFeed>(feeds);
if (rssfeeds != null)
{
Payload payload = new Payload();
payload.data = new List<Post>();
foreach (var feed in rssfeeds.data)
{
var reader = new FeedReader(true);
var items = reader.RetrieveFeed(feed?.attributes?.uri);
foreach (var i in items)
{
Post post = new Post();
post.Title = i.Title;
post.Id = i.Id;
post.Summary = i.Summary;
post.PublishDate = i.PublishDate.DateTime;
post.LastUpdatedDate = i.LastUpdatedDate.DateTime;
post.Uri = i.Uri;
payload.data?.Add(post);
}
}
var client2 = new RestClient(postUri);
var request = new RestRequest();
request.Method = Method.Post;
// serialize the object to JSON and add it as the request body
request.AddJsonBody(payload.data);
var response = client2.Execute(request);
string responseContent = response.Content;
Console.WriteLine(responseContent);
}
System Information
- Strapi Version:
- Operating System:
- Database:
- Node Version:
- NPM Version:
- Yarn Version: