Create OneNote (client) Notebook with OneNote API - onenote

I can use the code below to create a page in a section and I can create a Notebook in the OneNote OneDrive using the APIGee console app, but I cannot figure out how to create a new Notebook in the OneNote client program. Below is a snippet of my code to create a page in the Foo section.
How can I modify this code to create a new Notebook in the client?
private static readonly Uri PagesEndPoint = new Uri("https://www.onenote.com/api/v1.0/pages?sectionName=Foo");
HttpResponseMessage response;
using (var imageContent = new StreamContent(await GetBinaryStream("assets\\SOAP.jpg")))
{
imageContent.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
HttpRequestMessage createMessage = new HttpRequestMessage(HttpMethod.Post, PagesEndPoint)
{
Content = new MultipartFormDataContent
{
{new StringContent(simpleHtml, System.Text.Encoding.UTF8, "text/html"), "Presentation"},{imageContent, imagePartName}
}
};
// Must send the request within the using block, or the image stream will have been disposed.
response = await client.SendAsync(createMessage);
}
tbResponse.Text = response.ToString();
return await TranslateResponse(response);

If the create notebook API call returns a success (201), it means the notebook has been created successfully on the user's OneDrive. However, the notebook will not automatically show up in the OneNote clients for the user. The user will need to open the newly created notebook in one of the OneNote client apps.
Alternatively, you can use the links.oneNoteClientUrl.href property from the API response message to open the notebook for the user in the OneNote client for them.
Hope that helps.
Thanks,
James

If you have OneNote installed, you may use the OneNote COM API. There is a VanillaAddin you can modify here: https://github.com/OneNoteDev/VanillaAddIn
In addition you can just write a Console app using the same COM API to do this (so you don't need to write a COM Add-in).

Related

How to authenticate with Blockfrost.io API?

So I'm trying to import Cardano Blockchain data like address balance, amount staked, rewards etc into a Google Sheet. I found this project named Blockfrost.io which is an API for accessing Cardano blockchain info and import it into apps etc.
I think I can use this with Google Sheets. Problem is I don't know how to authenticate. I've searched all around on the documentation and it's not clear to me. It seems it's possible if your're building an app or using the terminal.
But I just want to authenticate in the easiest way possible like in the browser address bar that way it would be simple to get the JSON with the info I need and import the info to Google Sheets.
This is where it mentions the Authentication:
https://docs.blockfrost.io/#section/Authentication
I already have an API key to access. But how do I authenticate?
So if I want to check the blockchain metrics (mainnet1234567890 is a dummy key, I won't use mine here):
https://cardano-mainnet.blockfrost.io/api/v0/metrics/project_id:mainnet1234567890
The JSON will still output this:
status_code 403
error "Forbidden"
message "Missing project token. Please include project_id in your request."
Is there a correct way to authenticate on the browser address bar?
It's not clear which BlockFrost API you are using Go JavaScript etc...
the API key goes in as a header on the request object. I was manually trying to connect to the service and found for a request is what I had to do in C#...
var aWR = System.Net.WebRequest.Create(url);
aWR.Method = "GET";
aWR.Headers.Add("project_id", "mainnetTheRestOfMyKeyIsHidden");
var webResponse = aWR.GetResponse();
var webStream = webResponse.GetResponseStream();
var reader = new StreamReader(webStream);
var data = reader.ReadToEnd();
Later I realized I wanted to use their API cause they implement the rate limiter, something I would rather use than build... I use the following with the BlockFrost API in c#
const string apiKey = "mainnetPutYourKeyHere";
const string network = "mainnet";
// your key is set during the construction of the provider.
ServiceProvider provider = new ServiceCollection().AddBlockfrost(network, apiKey).BuildServiceProvider();
// from there individual services are created
var AddressService = provider.GetRequiredService<IAddressesService>();
// The call to get the data looked like
AddressTransactionsContentResponseCollection TXR = await AddressService.GetTransactionsAsync(sAddress, sHeightFrom, sHeightTo, 100, iAddressPage, ESortOrder.Desc, new System.Threading.CancellationToken());
// etc. your gonna need to set the bounds above in terms of block height
Try using postman and include the "project_id" header with api key as the value like this - it will clear up the concept for you I think:enter image description here

Upload files for Stripe managed account verification issue

I am trying to upload file (from Chrome browser on Linux machine ) to Stripe's server, the response from Stripe's server is
com.stripe.exception.InvalidRequestException: File for key file must
exist.
The problem comes due to C:/fakepath/file-name from form submit path
when I hard code its original path while upload, it works!
How I can resolve this problem?
Thanks.
That message does not come from Stripe's API, but rather from the Java bindings themselves: https://github.com/stripe/stripe-java/blob/c7d26216b09a5a5b288ef5550c59979209979bc5/src/main/java/com/stripe/net/LiveStripeResponseGetter.java#L529-L530
To reuse the example from Stripe's API reference:
Stripe.apiKey = "sk_test_...";
Map<String, Object> fileUploadParams = new HashMap<String, Object>();
fileUploadParams.put("purpose", dispute_evidence);
fileUploadParams.put("file", new File('/path/to/a/file.jpg'));
FileUpload fileUpload = FileUpload.create(fileUploadParams);
would cause the exact same error if /path/to/a/file.jpg does not exist.

Trying to get Google Drive to work with PCL Xamarin Forms application

I’m using Xamarin Forms to do some cross platform applications and I’d like to offer DropBox and GoogleDrive as places where users can do backups, cross platform data sharing and the like. I was able to get DropBox working without doing platform specific shenanagins just fine, but Google Drive is really giving me fits. I have my app setup properly with Google and have tested it with a regular CLI .NET application using their examples that read the JSON file off the drive and create a temporary credentials file – all fine and well but getting that to fly without access to the file system is proving elusive and I can’t find any examples on how to go about it.
I’m currently just using Auth0 as a gateway to allow users to provide creds/access to my app for their account which works dandy, the proper scope items are requested (I’m just using read only file access for testing) – I get an bearer token and refresh token from them – however when trying to actually use that data and just do a simple file listing, I get a 400 bad request error.
I’m sure this must be possible but I can’t find any examples anywhere that deviate from the slightest of using the JSON file downloaded from Google and creating a credentials file – surely you can create an instance of the DriveService object armed with only the bearer token...
Anyway – here’s a chunk of test code I’m trying to get the driveService object configured – if anyone has done this or has suggestions as to what to try here I’d very much appreciate your thoughts.
public bool AuthenticationTest(string pBearerToken)
{
try
{
var oInit = new BaseClientService.Initializer
{
ApplicationName = "MyApp",
ApiKey = pBearerToken,
};
_googleDrive = new DriveService(oInit);
FilesResource.ListRequest listRequest = _googleDrive.Files.List();
listRequest.PageSize = 10;
listRequest.Fields = "nextPageToken, files(id, name)";
//All is well till this call to list the files…
IList<Google.Apis.Drive.v3.Data.File> files = listRequest.Execute().Files;
foreach (var file in files)
{
Debug. WriteLine(file.Name);
}
}
catch (Exception ex)
{
RaiseError(ex);
}
}

How to consume AX dynamics web service in windows phone 8.1 universal app

I tried consume a AX dynamics secured web service in windows phone universal app. But i am unable to do so as windows phone run-time doesn't support service models(i.e. It doesn't provide option to add service reference). Hence Microsoft has proposed a work around using HttpClient Class.
So i did the following:
using (HttpClient client = new HttpClient())
{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://xxxxx/xppservice.svc/GetData");
HttpResponseMessage response = await client.SendAsync(request);
string data = await response.Content.ReadAsStringAsync();
var dialog = new MessageDialog(data);
await dialog.ShowAsync();
}
But the problem here is, the service which i am using is secured and i have the authentication credentials. But i am unable to figure out how supply them while sending the request. Can you please help me?
A

Posting Documents to OneNote via new REST API

For some reason, any document I upload to OneNote via the new REST API is corrupt when viewed from OneNote. Everything else is fine, but the file (for example a Word document) isn't clickable and if you try and open is shows as corrupt.
This is similar to what may happen when there is a problem with the byte array, or its in memory, but that doesn't seem to be the case. I use essentially the same process to upload the file bytes to SharePoint, OneDrive, etc. It's only to OneNote that the file seems to be corrupt.
Here is a simplified version of the C#
HttpRequestMessage createMessage = null;
HttpResponseMessage response = null;
using (var streamContent = new ByteArrayContent(fileBytes))
{
streamContent.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
streamContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data");
streamContent.Headers.ContentDisposition.Name = fileName;
createMessage = new HttpRequestMessage(HttpMethod.Post, authorizationUrl)
{
Content = new MultipartFormDataContent
{
{
new StringContent(simpleHtml,
System.Text.Encoding.UTF8, "text/html"), "Presentation"
},
{streamContent}
}
};
response = await client.SendAsync(createMessage);
var stream = await response.Content.ReadAsStreamAsync();
successful = response.IsSuccessStatusCode;
}
Does anyone have any thoughts or working code uploading an actual binary document via the OneNote API via a Windows Store app?
The WinStore code sample contains a working example (method: CreatePageWithAttachedFile) of how to upload an attachment.
The slight differences I can think of between the above code snippet and the code sample are that the code sample uploads a pdf file (instead of a document) and the sample uses StreamContent (while the above code snippet uses ByteArrayContent).
I downloaded the code sample and locally modified it to use a document file and ByteArrayContent. I was able to upload the attachment and view it successfully. Used the following to get a byte array from a given stream:
using (BinaryReader br = new BinaryReader(stream))
{
byte[] b = br.ReadBytes(Convert.ToInt32(s.Length));
}
The rest of the code looks pretty similar to the above snippet and overall worked successfully for me.
Here are a few more things to consider while troubleshooting the issue:
Verify the attachment file itself isn't corrupt in the first place. for e.g. can it be opened without the OneNote API being in the mix?
Verify the API returned a 201 Http Status code back and the resulting page contains the attachment icon and allows downloading/viewing the attached file.
So, the issue was (strangely) the addition of the meta Content Type in the tag sent over in the HTML content that's not shown. The documentation refers to adding a type=[mime type] in the object tag, and since the WinStore example didn't do this (it only adds the mime type to the MediaTypeHeaderValue I removed it and it worked perfectly.
Just changing it to this worked:
<object data-attachment=\"" + fileName + "\" data=\"name:" + attachmentPartName + "\" />
Thanks for pointing me in the right direction with the sample code!