Closed bradyguyc closed 8 months ago
Did you figure this out yet? if not ill take a look
Here you go:
Uri posturi = new Uri("https://openlibrary.org/works/OL42697W/bookshelves.json");
await LoginAsync("UserName", "Password");
HttpResponseMessage m;
var c = new MultipartFormDataContent
{
{ new StringContent("add"), "action" },
{ new StringContent("1"), "bookshelf_id" },
{ new StringContent("/works/OL42697W"), "work_id" },
{ new StringContent("/books/OL31914090M"), "edition_id" },
{ new StringContent("/people/luca3317"), "user-key" }
};
m = await client.PostAsync(posturi, c);
if (m.IsSuccessStatusCode)
{
Console.WriteLine("SUCCESS: " + m.StatusCode);
var responseBody = await m.Content.ReadAsStringAsync();
Console.WriteLine($"Response: {responseBody}");
}
else
{
//Handle error cases
Console.WriteLine($"Error: {m.StatusCode}");
}
This doesnt really seem to be part of the API yet (no entry on the API docs, doesnt work with json for me), but this works. Bookshelf ids are 1 = want-to-read, 2 = currently-reading, 3 = already-read
I exposed the SessionCookie off your base class and had to add it to the header to get it to work. However, something weird is happening with the data I am using. I can see that the work and edition id's are correct however a different book is getting added to my bookshelf with the already read status.
HttpClient client = new HttpClient(handler); client.DefaultRequestHeaders.Add("Cookie", OLclient.SessionCookie.ToString());
I go to the works id shown in the data below and I get The Chronicles of Narnia. Same for the edition id.
Yet when I log into openlibrary 'The dancing bear shows up. https://openlibrary.org/works/OL42697W/The_Dancing_Bear_%28Young_Lion_Storybook%29
Weird stuff...
This is the content of c MultipartFormDataContent --5c8435af-79a8-4d28-8ddf-8868b549f87e Content-Type: text/plain; charset=utf-8 Content-Disposition: form-data; name=action
add --5c8435af-79a8-4d28-8ddf-8868b549f87e Content-Type: text/plain; charset=utf-8 Content-Disposition: form-data; name=bookshelf_id
3 --5c8435af-79a8-4d28-8ddf-8868b549f87e Content-Type: text/plain; charset=utf-8 Content-Disposition: form-data; name=work_id
/works/OL20643179W --5c8435af-79a8-4d28-8ddf-8868b549f87e Content-Type: text/plain; charset=utf-8 Content-Disposition: form-data; name=edition_id
/books/OL27908917M --5c8435af-79a8-4d28-8ddf-8868b549f87e Content-Type: text/plain; charset=utf-8 Content-Disposition: form-data; name=user-key
/people/bradyguy --5c8435af-79a8-4d28-8ddf-8868b549f87e--
I exposed the SessionCookie off your base class and had to add it to the header to get it to work. However, something weird is happening with the data I am using. I can see that the work and edition id's are correct however a different book is getting added to my bookshelf with the already read status.
HttpClient client = new HttpClient(handler); client.DefaultRequestHeaders.Add("Cookie", OLclient.SessionCookie.ToString());
I go to the works id shown in the data below and I get The Chronicles of Narnia. Same for the edition id.
Yet when I log into openlibrary 'The dancing bear shows up. https://openlibrary.org/works/OL42697W/The_Dancing_Bear_%28Young_Lion_Storybook%29
Weird stuff...
This is the content of c MultipartFormDataContent --5c8435af-79a8-4d28-8ddf-8868b549f87e Content-Type: text/plain; charset=utf-8 Content-Disposition: form-data; name=action
add --5c8435af-79a8-4d28-8ddf-8868b549f87e Content-Type: text/plain; charset=utf-8 Content-Disposition: form-data; name=bookshelf_id
3 --5c8435af-79a8-4d28-8ddf-8868b549f87e Content-Type: text/plain; charset=utf-8 Content-Disposition: form-data; name=work_id
/works/OL20643179W --5c8435af-79a8-4d28-8ddf-8868b549f87e Content-Type: text/plain; charset=utf-8 Content-Disposition: form-data; name=edition_id
/books/OL27908917M --5c8435af-79a8-4d28-8ddf-8868b549f87e Content-Type: text/plain; charset=utf-8 Content-Disposition: form-data; name=user-key
/people/bradyguy --5c8435af-79a8-4d28-8ddf-8868b549f87e--
Did you replace the Works OLID in the Uri?
yes, and it's working now.... thanks much... I completely missed that.... thanks
Do you happen to know if there is away to update a users work/edition with their reading status? want to read, currently reading, read?