C# Library Quickstart

Configure Project

  1. First install the library from nuget and add it to your project.
<PackageReference Include="Dapi" Version="1.0.0"/>
  1. Import Dapi's library in your code.
using Dapi;
using Dapi.Products;
using Dapi.Response;
using Dapi.Types;
  1. Create a Dapi app with your App Secret
namespace TestConsoleApp {
    public class TestClass {
        private DapiApp myApp;

        public TestClass() {
            myApp = new DapiApp("YOUR_APP_SECRET");
        }
    }
}
  1. Now you can use any of the functions of the DapiApp instance, myApp. Here is an example for getAccounts.
namespace TestConsoleApp {
    public class TestClass {
        public void TestFunc() {
            var resp = myApp.getAccounts("YOUR_ACCESS_TOKEN", "YOUR_USER_SECRET");
            // do something with the resp
        }
    }
}

Complete example

You need to replace the placeholders in this code snippet(appSecret, accessToken, userSecret) with your own values.

using System.Collections.Generic;
using Dapi;
using Dapi.Products;
using Dapi.Response;
using Dapi.Types;


namespace TestConsoleApp {
    public class TestClass {
        private DapiApp myApp;

        public TestClass() {
            myApp = new DapiApp("YOUR_APP_SECRET");
        }

        public void TestFunc() {
            var resp = myApp.getAccounts("YOUR_ACCESS_TOKEN", "YOUR_USER_SECRET");
            // do something with the resp
        }
    }
}

Configure SDK Server

  1. Follow the steps in Configure Project first in order to obtain and import the library.

  2. Our code will basically update the request to add your app's appSecret to it, and forward the request to Dapi, then return the result.

namespace TestConsoleApp {
    public class TestClass {
        public void HandlerFunc(string requestBodyJson, ICollection<KeyValuePair<string, string>> requestHeaders) {
            var resp = myApp.handleSDKRequest(requestBodyJson, requestHeaders);
            //resp = myApp.handleSDKRequest(requestBodyJson); // or with no headers
            // do something with the resp
        }
    }
}

Complete example

You need to replace the placeholder in this code snippet(appSecret).
For set-up instructions follow the documentation here.

using Dapi;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace DapiSDKExample
{
    public class Startup
    {
        public static DapiApp dapiApp = new("YOUR_APP_SECRET");

        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }
}