async Task <string> GetNewSessionToken() { var endpoint = new Uri("/api/session", UriKind.Relative); var requestJson = JObj.Obj(new[] { JObj.Prop("username", _settings.MetabaseApiUsername), JObj.Prop("password", _settings.MetabaseApiPassword), }); var requestContent = new StringContent(requestJson.ToString(), Encoding.UTF8, mediaType: "application/json"); var response = await _http.PostAsync(endpoint, requestContent); if (response.IsSuccessStatusCode == false) { throw new MetabaseApiException("Error logging in to Metabase API. Status code: " + response.StatusCode); } var rawContent = await response.Content.ReadAsStringAsync(); try { var responseContent = JObject.Parse(rawContent); return((string)responseContent["id"]); } catch (Exception e) { throw new MetabaseApiException("Error parsing session token response from:\n" + rawContent, e); } }
async Task <DashboardCard> AddCardToDashboard(CardId cardId, DashboardId dashboardId) { var content1 = JObj.Obj(new[] { JObj.Prop("cardId", cardId.Value) }); HttpRequestMessage request1() => new HttpRequestMessage(HttpMethod.Post, new Uri($"/api/dashboard/{dashboardId}/cards", UriKind.Relative)) { Content = ToJsonContent(content1).HttpContent }; var response = await sessionManager.Send(request1); var dashboardCard = JsonConvert.DeserializeObject <DashboardCard>(response); return(dashboardCard); }
async Task <DashboardCard> AddCardToDashboard(CardId cardId, DashboardId dashboardId) { var content1 = JObj.Obj(new[] { JObj.Prop("cardId", cardId.Value) }); HttpRequestMessage request1() => new HttpRequestMessage(HttpMethod.Post, new Uri($"/api/dashboard/{dashboardId}/cards", UriKind.Relative)) { Content = ToJsonContent(content1).HttpContent }; var response = await sessionManager.Send(request1); try { return(JsonConvert.DeserializeObject <DashboardCard>(response)); } catch (JsonSerializationException e) { throw new MetabaseApiException($"Error parsing response for {nameof(DashboardCard)} from:\n{response}", e); } }