I can see list of all invoices for organisations using the Xero OAuth 2 sample from Xero-NetStandard. I want to create a new invoice for a particular tenant/organisation, how do I create an invoice object and what should the POST Method look like? Below code is what I have so far :
public async Task<string> InvoicesPostAsync()
{
var token = await _tokenStore.GetAccessTokenAsync(User.XeroUserId());
var connections = await _xeroClient.GetConnectionsAsync(token);
List<string> allinvoicenames = new List<string>();
foreach (var connection in connections)
{
var tenantID = connection.TenantId.ToString();
var request = (HttpWebRequest)WebRequest.Create("https://api.xero.com/api.xro/2.0/Invoices");
var postData = "thing1=hello";
var data = Encoding.ASCII.GetBytes(postData);
request.Method = "POST";
request.Headers.Add("Authorization" , "Bearer "+ token);
request.Headers.Add("Xero-tenant-id" , tenantID);
request.ContentType = "application/x-www-form-urlencoded";
request.Credentials = CredentialCache.DefaultCredentials;
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
var response = (HttpWebResponse)request.GetResponse();
}