All Collections
Optiseller APIs
Access the API from code
Access the API from code

Example code to make an Optiseller api call

Raymond Booth avatar
Written by Raymond Booth
Updated over a week ago

Alternatively, API test tools such as postman can be used or with some simple scripting the API is accessible with a small amount of code, a c# example is below

Note that the header for the subscription key is named Ocp-Apim-Subscription-Key

using System.Net.Http.Headers;
using System;
using Newtonsoft.Json;

Console.WriteLine("Hello, World!");


using var client = new HttpClient();
var url = "https://connect.optiseller.com/suggestionapi/AspectSuggester";

var urlParameters = "?brandmpn=toshiba ct-8541";

client.BaseAddress = new Uri(url);

// Add an Accept header for JSON format.
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));

// Add header for subscription key
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "ADD_YOUR_KEY_HERE");

// Get data response
var response = client.GetAsync(urlParameters).Result;
if (response.IsSuccessStatusCode)
{
// Parse the response body
var result = response.Content.ReadAsStringAsync().Result;

var dynamicObject = JsonConvert.DeserializeObject<dynamic>(result)!;
foreach (var item in dynamicObject.aspects)
{
Console.WriteLine("{0}:{1}", item.name, item.values?[0]);
};
}
else
{
Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
}

If you have any questions or would like to chat to someone about the API please get in touch and we will be happy to help.

Did this answer your question?