コードを使用したカスタム API を作成する

注意

これは、これらのトピックをすでに読んで、理解していることを前提とした高度なトピックです:

Web API または .NET 用 SDK のいずれかを使用して、Microsoft Dataverse レコードを作成する方法を理解する必要もあります。 詳細については、以下を参照してください。

カスタム API のデータはテーブルに保存されるため、Web API または .NET 用 SDK を使用してプログラムにより新しい API を作成することができます。

カスタム API テーブル のテーブルで、コードを使用して設定できるすべてのプロパティを記述します。

このコードは、アーリーバウンドのプログラミング スタイルで CrmServiceClient を使用しています。 ServiceClient を使うこともできます。 詳細情報:

この例では、1 つの要求パラメーターと 1 つの応答プロパティを持つカスタム API アクションをひとつの操作で作成しています。 詳細: 1 回の操作で関連するエンティティを作成する

このカスタム APIは、CustomAPIExample という一意の名称のソリューションの一部として作成され、id = 00000000-0000-0000-0000-000000000001 というプラグイン タイプに関連付けられています。

string conn = $@"
    Url = {url};
    AuthType = OAuth;
    UserName = {userName};
    Password = {password};
    AppId = 51f81489-12ee-4a9e-aaae-a2591f45987d;
    RedirectUri = app://58145B91-0C36-4500-8554-080854F2AC97;
    LoginPrompt=Auto;
    RequireNewInstance = True";

//var service = new ServiceClient(conn);
var service = new CrmServiceClient(conn);
// var service = new ServiceClient(conn);

//The plug-in type
var pluginType = new EntityReference("plugintype", new Guid("00000000-0000-0000-0000-000000000001"));
var solutionUniqueName = "CustomAPIExample";

//The custom API
var customAPI = new CustomAPI
{
    AllowedCustomProcessingStepType = new OptionSetValue(0),//None
    BindingType = new OptionSetValue(0), //Global
    Description = "A simple example of a custom API",
    DisplayName = "Custom API Example",
    ExecutePrivilegeName = null,
    IsFunction = false,
    IsPrivate = false,
    Name = "sample_CustomAPIExample",
    PluginTypeId = pluginType,
    UniqueName = "sample_CustomAPIExample",
    IsCustomizable = new BooleanManagedProperty(false),
    customapi_customapirequestparameter = new List<CustomAPIRequestParameter>()
    {
        new CustomAPIRequestParameter {
            Description = "The StringParameter request parameter for custom API Example",
            DisplayName = "Custom API Example String Parameter",
            LogicalEntityName = null,
            IsOptional = false,
            Name = "sample_CustomAPIExample.StringParameter",
            Type = new OptionSetValue(10), //String
            UniqueName = "StringParameter",
            IsCustomizable = new BooleanManagedProperty(false)
        }
    },
    customapi_customapiresponseproperty = new List<CustomAPIResponseProperty>()
    {
        new CustomAPIResponseProperty {
            Description = "The StringProperty response property for custom API Example",
            DisplayName = "Custom API Example String Property",
            Name = "sample_CustomAPIExample.StringProperty",
            Type = new OptionSetValue(10), //String
            UniqueName = "StringProperty",
            IsCustomizable = new BooleanManagedProperty(false)
        }
    }
};

var createReq = new CreateRequest
{
    Target = customAPI
};
createReq["SolutionUniqueName"] = solutionUniqueName;

Guid customAPIId = ((CreateResponse)service.Execute(createReq)).id;

参照

カスタム API の作成と使用
カスタム API テーブル
プラグイン登録ツールを使用してカスタム API を作成する
Power Apps でカスタム API を作成する
ソリューション ファイルを使用したカスタム API の作成

注意

ドキュメントの言語設定についてお聞かせください。 簡単な調査を行います。 (この調査は英語です)

この調査には約 7 分かかります。 個人データは収集されません (プライバシー ステートメント)。