Skip to content

Performing requests

Håkon André Knudsen edited this page Sep 25, 2019 · 1 revision

Get

GetParameters parameters = new GetParameters()
{
    Db = "ERP-NO"
};

try
{
    ApiResponse res = await api.GetAsync("sales/orders", parameters);
    dynamic salesOrders = res.To<ExpandoObject>();

    foreach (dynamic salesOrder in salesOrders.salesOrders)
    {
        Console.WriteLine(salesOrder.salesOrderId);
    }
}
catch (RequestException ex)
{
    Console.WriteLine(ex);
}

In the example we used to GetParameter class to add query parameters to the request. You can read more about query parameters on the Parameters page.

Post

string newOrder = "{ salesOrder: { customer: { customerId: 100013 } } }";

try
{
    ApiResponse res = await api.PostAsync("sales/orders", newOrder);
}
catch(RequestException ex)
{
    Console.WriteLine(ex);
}

You should provide the body of the POST request as a valid JSON string.

Put

var updatedCustomerId = "{ salesOrder: { customer: { customerId: 100013 } } }";

try
{
    ApiResponse res = await api.PutAsync("sales/orders/101613", updatedCustomerId);
}
catch (RequestException ex)
{
    Console.WriteLine(ex);
}

In this example we update the customerId on the order with order id 101613. Note that in the body we only include the fields that we intend to change.

Delete

try
{
    ApiResponse res = await api.DeleteAsync("sales/orders/101613");
}
catch (RequestException ex)
{
    Console.WriteLine(ex);
}