> ## Documentation Index
> Fetch the complete documentation index at: https://translations.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Management API を使用したメール送信とチケット処理のカスタマイズ

> Management API を使用すると、標準ワークフロー外でメールを送信し、必要に応じてチケットを作成し、チケットの動作をカスタマイズできます。

export const AuthCodeGroup = ({children, dropdown}) => {
  const [processedChildren, setProcessedChildren] = useState(children);
  useEffect(() => {
    let unsubscribe = null;
    function init() {
      unsubscribe = window.autorun(() => {
        const processChildren = node => {
          if (typeof node === "string") {
            let processedNode = node;
            for (const [key, value] of window.rootStore.variableStore.values.entries()) {
              const escapedKey = key.replaceAll(/[.*+?^${}()|[\]\\]/g, (String.raw)`\$&`);
              processedNode = processedNode.replaceAll(new RegExp(escapedKey, "g"), value);
            }
            return processedNode;
          } else if (Array.isArray(node)) {
            return node.map(processChildren);
          } else if (node && node.props && node.props.children) {
            return {
              ...node,
              props: {
                ...node.props,
                children: processChildren(node.props.children)
              }
            };
          }
          return node;
        };
        setProcessedChildren(processChildren(children));
      });
    }
    if (window.rootStore) {
      init();
    } else {
      window.addEventListener("adu:storeReady", init);
    }
    return () => {
      window.removeEventListener("adu:storeReady", init);
      unsubscribe?.();
    };
  }, [children]);
  return <CodeGroup dropdown={dropdown}>{processedChildren}</CodeGroup>;
};

<Tooltip tip="Management API: 顧客が管理タスクを実行するための製品。" cta="用語集を見る" href="/ja/docs/glossary?term=Management+API">Management API</Tooltip> には、標準のメールワークフローを補完するために利用できる、メール関連のエンドポイントがいくつかあります。たとえば、次のことができます。

* 一部のメールタイプ (MFA 登録メールなど) を必要に応じて送信する

* チケットを作成する。チケットとは、メールワークフローのアクション (パスワードリセットなど) に使用する、オンデマンドで生成される URL です

* 確認メール用に異なる **Return To** URL を設定したり、パスワードリセットチケットでユーザーのメールアドレスを確認するよう設定したりするなど、チケットの動作をカスタマイズする

<div id="verification-email-endpoints">
  ## メールアドレス確認メールのエンドポイント
</div>

メールアドレス確認ワークフローとは別に、[メールアドレス確認メールを送信するエンドポイント](https://auth0.com/docs/api/management/v2/jobs/post_verification_email)を使用して、必要に応じてこれらのメールを送信できます。

<AuthCodeGroup>
  ```bash cURL theme={null}
  curl --request POST \
    --url 'https://{yourDomain}/api/v2/jobs/verification-email' \
    --header 'authorization: Bearer <YOUR_MANAGEMENT_API_TOKEN>' \
    --header 'content-type: application/json' \
    --data '{ "user_id": "{USER_ID_OF_EMAIL_RECIPIENT}", "client_id": "{YOUR_APP_CLIENT_ID}","identity": {"user_id": "5457edea1b8f22891a000004","provider": "google-oauth2"}, "organization_id": "{YOUR_ORGANIZATION_ID}" }'
  ```

  ```csharp C# theme={null}
  var client = new RestClient("https://{yourDomain}/api/v2/jobs/verification-email");
  var request = new RestRequest(Method.POST);
  request.AddHeader("content-type", "application/json");
  request.AddHeader("authorization", "Bearer {YOUR_MANAGEMENT_API_TOKEN}");
  request.AddParameter("application/json", "{ "user_id": "{USER_ID_OF_EMAIL_RECIPIENT}", "client_id": "{YOUR_APP_CLIENT_ID}","identity": {"user_id": "5457edea1b8f22891a000004","provider": "google-oauth2"}, "organization_id": "{YOUR_ORGANIZATION_ID}" }", ParameterType.RequestBody);
  IRestResponse response = client.Execute(request);
  ```

  ```go Go theme={null}
  package main

  import (
      "fmt"
      "strings"
      "net/http"
      "io/ioutil"
  )

  func main() {
      url := "https://{yourDomain}/api/v2/jobs/verification-email"
      payload := strings.NewReader("{ "user_id": "{USER_ID_OF_EMAIL_RECIPIENT}", "client_id": "{YOUR_APP_CLIENT_ID}","identity": {"user_id": "5457edea1b8f22891a000004","provider": "google-oauth2"}, "organization_id": "{YOUR_ORGANIZATION_ID}" }")

      req, _ := http.NewRequest("POST", url, payload)
      req.Header.Add("content-type", "application/json")
      req.Header.Add("authorization", "Bearer {YOUR_MANAGEMENT_API_TOKEN}")

      res, _ := http.DefaultClient.Do(req)
      defer res.Body.Close()
      body, _ := ioutil.ReadAll(res.Body)

      fmt.Println(res)
      fmt.Println(string(body))
  }
  ```

  ```java Java theme={null}
  HttpResponse<String> response = Unirest.post("https://{yourDomain}/api/v2/jobs/verification-email")
      .header("content-type", "application/json")
      .header("authorization", "Bearer <YOUR_MANAGEMENT_API_TOKEN>")
      .body("{ "user_id": "{USER_ID_OF_EMAIL_RECIPIENT}", "client_id": "{YOUR_APP_CLIENT_ID}","identity": {"user_id": "5457edea1b8f22891a000004","provider": "google-oauth2"}, "organization_id": "{YOUR_ORGANIZATION_ID}" }")
      .asString();
  ```

  ```javascript Node.JS theme={null}
  var axios = require("axios").default;

  var options = {
      method: 'POST',
      url: 'https://{yourDomain}/api/v2/jobs/verification-email',
      headers: {
          'content-type': 'application/json',
          authorization: 'Bearer {YOUR_MANAGEMENT_API_TOKEN}'
      },
      data: {
          user_id: '{USER_ID_OF_EMAIL_RECIPIENT}',
          client_id: '{YOUR_APP_CLIENT_ID}',
          identity: {user_id: '5457edea1b8f22891a000004', provider: 'google-oauth2'},
          organization_id: '{YOUR_ORGANIZATION_ID}'
      }
  };

  axios.request(options).then(function (response) {
      console.log(response.data);
  }).catch(function (error) {
      console.error(error);
  });
  ```

  ```objc Obj-C theme={null}
  #import <Foundation/Foundation.h>

  NSDictionary *headers = @{ @"content-type": @"application/json",
                             @"authorization": @"Bearer {YOUR_MANAGEMENT_API_TOKEN}" };
  NSDictionary *parameters = @{ @"user_id": @"{USER_ID_OF_EMAIL_RECIPIENT}",
                                @"client_id": @"{YOUR_APP_CLIENT_ID}",
                                @"identity": @{ @"user_id": @"5457edea1b8f22891a000004", @"provider": @"google-oauth2" },
                                @"organization_id": @"{YOUR_ORGANIZATION_ID}" };

  NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];

  NSMutableURLRequest *request = [NSMutableURLRequest
      requestWithURL:[NSURL URLWithString:@"https://{yourDomain}/api/v2/jobs/verification-email"]
      cachePolicy:NSURLRequestUseProtocolCachePolicy
      timeoutInterval:10.0
  ];

  [request setHTTPMethod:@"POST"];
  [request setAllHTTPHeaderFields:headers];
  [request setHTTPBody:postData];

  NSURLSession *session = [NSURLSession sharedSession];
  NSURLSessionDataTask *dataTask = [
      session dataTaskWithRequest:request
      completionHandler:^( NSData *data, NSURLResponse *response, NSError *error) {
          if (error) {
              NSLog(@"%@", error);
          } else {
              NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
              NSLog(@"%@", httpResponse);
          }
      }
  ];
  [dataTask resume];
  ```

  ```php PHP theme={null}
  $curl = curl_init();

  curl_setopt_array($curl, [
      CURLOPT_URL => "https://{yourDomain}/api/v2/jobs/verification-email",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST",
      CURLOPT_POSTFIELDS => "{ "user_id": "{USER_ID_OF_EMAIL_RECIPIENT}", "client_id": "{YOUR_APP_CLIENT_ID}","identity": {"user_id": "5457edea1b8f22891a000004","provider": "google-oauth2"}, "organization_id": "{YOUR_ORGANIZATION_ID}" }",
      CURLOPT_HTTPHEADER => [
          "authorization: Bearer {YOUR_MANAGEMENT_API_TOKEN}",
          "content-type: application/json"
      ],
  ]);

  $response = curl_exec($curl);
  $err = curl_error($curl);

  curl_close($curl);

  if ($err) {
      echo "cURL Error #:" . $err;
  } else {
      echo $response;
  }
  ```

  ```python Python theme={null}
  import http.client

  conn = http.client.HTTPSConnection("")
  payload = "{ "user_id": "{USER_ID_OF_EMAIL_RECIPIENT}", "client_id": "{YOUR_APP_CLIENT_ID}","identity": {"user_id": "5457edea1b8f22891a000004","provider": "google-oauth2"}, "organization_id": "{YOUR_ORGANIZATION_ID}" }"
  headers = {
      'content-type': "application/json",
      'authorization': "Bearer {YOUR_MANAGEMENT_API_TOKEN}"
  }

  conn.request("POST", "/{yourDomain}/api/v2/jobs/verification-email", payload, headers)

  res = conn.getresponse()
  data = res.read()

  print(data.decode("utf-8"))
  ```

  ```ruby Ruby theme={null}
  require 'uri'
  require 'net/http'
  require 'openssl'

  url = URI("https://{yourDomain}/api/v2/jobs/verification-email")

  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE

  request = Net::HTTP::Post.new(url)
  request["content-type"] = 'application/json'
  request["authorization"] = 'Bearer {YOUR_MANAGEMENT_API_TOKEN}'
  request.body = "{ "user_id": "{USER_ID_OF_EMAIL_RECIPIENT}", "client_id": "{YOUR_APP_CLIENT_ID}","identity": {"user_id": "5457edea1b8f22891a000004","provider": "google-oauth2"}, "organization_id": "{YOUR_ORGANIZATION_ID}" }"

  response = http.request(request)
  puts response.read_body
  ```

  ```swift Swift theme={null}
  import Foundation

  let headers = [
      "content-type": "application/json",
      "authorization": "Bearer {YOUR_MANAGEMENT_API_TOKEN}"
  ]
  let parameters = [
      "user_id": "{USER_ID_OF_EMAIL_RECIPIENT}",
      "client_id": "{YOUR_APP_CLIENT_ID}",
      "identity": [
          "user_id": "5457edea1b8f22891a000004",
          "provider": "google-oauth2"
      ],
      "organization_id": "{YOUR_ORGANIZATION_ID}"
  ] as [String : Any]

  let postData = JSONSerialization.data(withJSONObject: parameters, options: [])
  let request = NSMutableURLRequest(
      url: NSURL(string: "https://{yourDomain}/api/v2/jobs/verification-email")! as URL,
      cachePolicy: .useProtocolCachePolicy,
      timeoutInterval: 10.0
  )

  request.httpMethod = "POST"
  request.allHTTPHeaderFields = headers
  request.httpBody = postData as Data

  let session = URLSession.shared
  let dataTask = session.dataTask(
      with: request as URLRequest,
      completionHandler: { (data, response, error) -> Void in
          if (error != nil) {
              print(error)
          } else {
              let httpResponse = response as? HTTPURLResponse
              print(httpResponse)
          }
      }
  )

  dataTask.resume()
  ```
</AuthCodeGroup>

さらに、[メールアドレス確認チケットを作成](https://auth0.com/docs/api/management/v2/tickets/post-email-verification) エンドポイントを使用して、メールアドレス確認チケットを生成することもできます。

<div id="password-change-endpoints">
  ## パスワード変更エンドポイント
</div>

change password link ワークフロー以外では、[パスワード変更チケットを作成する](https://auth0.com/docs/api/management/v2/tickets/post-password-change) エンドポイントを使用して、パスワード変更チケットを生成できます。

change password link テンプレートには、ユーザーの id などの変数をサポートする **Redirect To** フィールドがあります。より細かく制御するには、このエンドポイントで生成したパスワードリセットチケットをユーザーにメールで送信し、独自の条件に基づいて `result_url` を設定できます。

このエンドポイントでは、ユーザーのメールアドレスを確認済みにするかどうか、また `return_url` の一部としてメールアドレスを含めるかどうかもカスタマイズできます。

<div id="mfa-enrollment-endpoints">
  ## MFA登録エンドポイント
</div>

MFA 登録ワークフロー以外では、[多要素認証登録チケットを作成する](https://auth0.com/docs/api/management/v2/guardian/post-ticket) エンドポイントを使用して MFA 登録チケットを生成し、必要に応じて、作成したチケットを含むメールを送信できます。

Universal Login を使用する場合、このエンドポイントでは、ユーザーが登録する必要のある認証要素や、すでに MFA に登録済みのユーザーが追加の認証要素を登録できるかどうかも指定できます。
