Create identityApiConnector
Article
07/06/2023
5 contributors
Feedback
In this article
Namespace: microsoft.graph
Create a new identityApiConnector object.
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions .
Permission type
Permissions (from least to most privileged)
Delegated (work or school account)
APIConnectors.ReadWrite.All
Delegated (personal Microsoft account)
Not supported.
Application
APIConnectors.ReadWrite.All
The work or school account needs to belong to one of the following roles:
Global administrator
External Identity User Flow administrator
HTTP request
POST /identity/apiConnectors
Name
Description
Authorization
Bearer {token}. Required.
Content-Type
application/json. Required.
Request body
In the request body, supply a JSON representation of the identityApiConnector object.
The following table shows the properties that are required when you create the identityApiConnector .
Response
If successful, this method returns a 201 Created
response code and an identityApiConnector object in the response body.
Examples
Example 1: Create an API connector with basic authentication
Request
The following is an example of the request.
POST https://graph.microsoft.com/v1.0/identity/apiConnectors
Content-Type: application/json
{
"displayName":"Test API",
"targetUrl":"https://someapi.com/api",
"authenticationConfiguration": {
"@odata.type":"#microsoft.graph.basicAuthentication",
"username": "MyUsername",
"password": "MyPassword"
}
}
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new IdentityApiConnector
{
DisplayName = "Test API",
TargetUrl = "https://someapi.com/api",
AuthenticationConfiguration = new BasicAuthentication
{
OdataType = "#microsoft.graph.basicAuthentication",
Username = "MyUsername",
Password = "MyPassword",
},
};
var result = await graphClient.Identity.ApiConnectors.PostAsync(requestBody);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc identity api-connectors create --body '{\
"displayName":"Test API",\
"targetUrl":"https://someapi.com/api",\
"authenticationConfiguration": {\
"@odata.type":"#microsoft.graph.basicAuthentication",\
"username": "MyUsername",\
"password": "MyPassword"\
}\
}\
'
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewIdentityApiConnector()
displayName := "Test API"
requestBody.SetDisplayName(&displayName)
targetUrl := "https://someapi.com/api"
requestBody.SetTargetUrl(&targetUrl)
authenticationConfiguration := graphmodels.NewBasicAuthentication()
username := "MyUsername"
authenticationConfiguration.SetUsername(&username)
password := "MyPassword"
authenticationConfiguration.SetPassword(&password)
requestBody.SetAuthenticationConfiguration(authenticationConfiguration)
apiConnectors, err := graphClient.Identity().ApiConnectors().Post(context.Background(), requestBody, nil)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
IdentityApiConnector identityApiConnector = new IdentityApiConnector();
identityApiConnector.displayName = "Test API";
identityApiConnector.targetUrl = "https://someapi.com/api";
BasicAuthentication authenticationConfiguration = new BasicAuthentication();
authenticationConfiguration.username = "MyUsername";
authenticationConfiguration.password = "MyPassword";
identityApiConnector.authenticationConfiguration = authenticationConfiguration;
graphClient.identity().apiConnectors()
.buildRequest()
.post(identityApiConnector);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
const options = {
authProvider,
};
const client = Client.init(options);
const identityApiConnector = {
displayName: 'Test API',
targetUrl: 'https://someapi.com/api',
authenticationConfiguration: {
'@odata.type':'#microsoft.graph.basicAuthentication',
username: 'MyUsername',
password: 'MyPassword'
}
};
await client.api('/identity/apiConnectors')
.post(identityApiConnector);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
<?php
// THIS SNIPPET IS A PREVIEW VERSION OF THE SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new IdentityApiConnector();
$requestBody->setDisplayName('Test API');
$requestBody->setTargetUrl('https://someapi.com/api');
$authenticationConfiguration = new BasicAuthentication();
$authenticationConfiguration->setOdataType('#microsoft.graph.basicAuthentication');
$authenticationConfiguration->setUsername('MyUsername');
$authenticationConfiguration->setPassword('MyPassword');
$requestBody->setAuthenticationConfiguration($authenticationConfiguration);
$result = $graphServiceClient->identity()->apiConnectors()->post($requestBody)->wait();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Import-Module Microsoft.Graph.Identity.SignIns
$params = @{
displayName = "Test API"
targetUrl = "https://someapi.com/api"
authenticationConfiguration = @{
"@odata.type" = "#microsoft.graph.basicAuthentication"
username = "MyUsername"
password = "MyPassword"
}
}
New-MgIdentityApiConnector -BodyParameter $params
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
# THE PYTHON SDK IS IN PREVIEW. FOR NON-PRODUCTION USE ONLY
graph_client = GraphServiceClient(request_adapter)
request_body = IdentityApiConnector(
display_name = "Test API",
target_url = "https://someapi.com/api",
authentication_configuration = BasicAuthentication(
odata_type = "#microsoft.graph.basicAuthentication",
username = "MyUsername",
password = "MyPassword",
),
)
result = await graph_client.identity.api_connectors.post(body = request_body)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Response
The following is an example of the response.
Note: The response object shown here might be shortened for readability.
HTTP/1.1 201 Created
Content-Type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#identity/apiConnectors/$entity",
"id":"45715bb8-13f9-4bf6-927f-ef96c102d394",
"displayName": "Test API",
"targetUrl": "https://someapi.com/api",
"authenticationConfiguration": {
"@odata.type": "#microsoft.graph.basicAuthentication",
"username": "MyUsername",
"password": "******"
}
}
Example 2: Create an API connector with client certificate authentication
Request
The following is an example of the request.
Note: authenticationConfiguration
in the request is of type microsoft.graph.pkcs12certificate , which represents the configuration of a certificate needed on upload or create.
POST https://graph.microsoft.com/v1.0/identity/apiConnectors
Content-Type: application/json
{
"displayName":"Test API",
"targetUrl":"https://someotherapi.com/api",
"authenticationConfiguration": {
"@odata.type":"#microsoft.graph.pkcs12Certificate",
"pkcs12Value": "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ...kDJ04sJShkkgjL9Bm49plA",
"password": "CertificatePassword"
}
}
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new IdentityApiConnector
{
DisplayName = "Test API",
TargetUrl = "https://someotherapi.com/api",
AuthenticationConfiguration = new Pkcs12Certificate
{
OdataType = "#microsoft.graph.pkcs12Certificate",
Pkcs12Value = "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ...kDJ04sJShkkgjL9Bm49plA",
Password = "CertificatePassword",
},
};
var result = await graphClient.Identity.ApiConnectors.PostAsync(requestBody);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc identity api-connectors create --body '{\
"displayName":"Test API",\
"targetUrl":"https://someotherapi.com/api",\
"authenticationConfiguration": {\
"@odata.type":"#microsoft.graph.pkcs12Certificate",\
"pkcs12Value": "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ...kDJ04sJShkkgjL9Bm49plA",\
"password": "CertificatePassword"\
}\
}\
'
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewIdentityApiConnector()
displayName := "Test API"
requestBody.SetDisplayName(&displayName)
targetUrl := "https://someotherapi.com/api"
requestBody.SetTargetUrl(&targetUrl)
authenticationConfiguration := graphmodels.NewPkcs12Certificate()
pkcs12Value := "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ...kDJ04sJShkkgjL9Bm49plA"
authenticationConfiguration.SetPkcs12Value(&pkcs12Value)
password := "CertificatePassword"
authenticationConfiguration.SetPassword(&password)
requestBody.SetAuthenticationConfiguration(authenticationConfiguration)
apiConnectors, err := graphClient.Identity().ApiConnectors().Post(context.Background(), requestBody, nil)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
IdentityApiConnector identityApiConnector = new IdentityApiConnector();
identityApiConnector.displayName = "Test API";
identityApiConnector.targetUrl = "https://someotherapi.com/api";
Pkcs12Certificate authenticationConfiguration = new Pkcs12Certificate();
authenticationConfiguration.pkcs12Value = "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ...kDJ04sJShkkgjL9Bm49plA";
authenticationConfiguration.password = "CertificatePassword";
identityApiConnector.authenticationConfiguration = authenticationConfiguration;
graphClient.identity().apiConnectors()
.buildRequest()
.post(identityApiConnector);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
const options = {
authProvider,
};
const client = Client.init(options);
const identityApiConnector = {
displayName: 'Test API',
targetUrl: 'https://someotherapi.com/api',
authenticationConfiguration: {
'@odata.type':'#microsoft.graph.pkcs12Certificate',
pkcs12Value: 'eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ...kDJ04sJShkkgjL9Bm49plA',
password: 'CertificatePassword'
}
};
await client.api('/identity/apiConnectors')
.post(identityApiConnector);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
<?php
// THIS SNIPPET IS A PREVIEW VERSION OF THE SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new IdentityApiConnector();
$requestBody->setDisplayName('Test API');
$requestBody->setTargetUrl('https://someotherapi.com/api');
$authenticationConfiguration = new Pkcs12Certificate();
$authenticationConfiguration->setOdataType('#microsoft.graph.pkcs12Certificate');
$authenticationConfiguration->setPkcs12Value('eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ...kDJ04sJShkkgjL9Bm49plA');
$authenticationConfiguration->setPassword('CertificatePassword');
$requestBody->setAuthenticationConfiguration($authenticationConfiguration);
$result = $graphServiceClient->identity()->apiConnectors()->post($requestBody)->wait();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Import-Module Microsoft.Graph.Identity.SignIns
$params = @{
displayName = "Test API"
targetUrl = "https://someotherapi.com/api"
authenticationConfiguration = @{
"@odata.type" = "#microsoft.graph.pkcs12Certificate"
pkcs12Value = "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ...kDJ04sJShkkgjL9Bm49plA"
password = "CertificatePassword"
}
}
New-MgIdentityApiConnector -BodyParameter $params
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
# THE PYTHON SDK IS IN PREVIEW. FOR NON-PRODUCTION USE ONLY
graph_client = GraphServiceClient(request_adapter)
request_body = IdentityApiConnector(
display_name = "Test API",
target_url = "https://someotherapi.com/api",
authentication_configuration = Pkcs12Certificate(
odata_type = "#microsoft.graph.pkcs12Certificate",
pkcs12_value = "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkEyNTZHQ00ifQ...kDJ04sJShkkgjL9Bm49plA",
password = "CertificatePassword",
),
)
result = await graph_client.identity.api_connectors.post(body = request_body)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Response
The following is an example of the response.
Note: authenticationConfiguration
in the response is of type microsoft.graph.clientCertificateAuthentication because this represents the public information of uploaded certificates.
HTTP/1.1 201 Created
Content-Type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#identity/apiConnectors/$entity",
"id":"45715bb8-13f9-4bf6-927f-ef96c102d394",
"displayName": "Test API",
"targetUrl": "https://someotherapi.com/api",
"authenticationConfiguration": {
"@odata.type": "#microsoft.graph.clientCertificateAuthentication",
"certificateList": [
{
"thumbprint": "0EB255CC895477798BA418B378255204304897AD",
"notAfter": 1666350522,
"notBefore": 1508670522,
"isActive": true
}
]
}
}