SendGrid 通过 API 3.0 邀请队友

SendGrid Invite Teammate via API 3.0

我正在尝试通过 API 邀请用户加入我的 SendGrid 订阅。 为此,我创建了一个完全访问密钥。

如果我尝试使用 TeamMates api ( https://sendgrid.com/docs/API_Reference/Web_API_v3/teammates.html ) 创建用户,我会收到 "forbidden" 响应。

如果我向系统询问我的密钥:

GET https://api.sendgrid.com/v3/api_keys/[KEY_ID]

我得到一个权限列表:

{
"api_key_id": "__ID__",
"name": "__NAME__",
"scopes": [
    "alerts.create",
    "alerts.read",
    "alerts.update",
    "alerts.delete",
    "asm.groups.create",
    "asm.groups.read",
    "asm.groups.update",
    "asm.groups.delete",
    "ips.pools.ips.read",
    "mail.send",
    "mail_settings.bcc.read",
    "mail_settings.bcc.update",
    "mail_settings.address_whitelist.read",
    "mail_settings.address_whitelist.update",
    "mail_settings.footer.read",
    "mail_settings.footer.update",
    "mail_settings.forward_spam.read",
    "mail_settings.forward_spam.update",
    "mail_settings.plain_content.read",
    "mail_settings.plain_content.update",
    "mail_settings.spam_check.read",
    "mail_settings.spam_check.update",
    "mail_settings.bounce_purge.read",
    "mail_settings.bounce_purge.update",
    "mail_settings.forward_bounce.read",
    "mail_settings.forward_bounce.update",
    "partner_settings.new_relic.read",
    "partner_settings.new_relic.update",
    "partner_settings.sendwithus.read",
    "partner_settings.sendwithus.update",
    "tracking_settings.click.read",
    "tracking_settings.click.update",
    "tracking_settings.subscription.read",
    "tracking_settings.subscription.update",
    "tracking_settings.open.read",
    "tracking_settings.open.update",
    "tracking_settings.google_analytics.read",
    "tracking_settings.google_analytics.update",
    "user.webhooks.event.settings.read",
    "user.webhooks.event.settings.update",
    "user.webhooks.event.test.create",
    "user.webhooks.event.test.read",
    "user.webhooks.event.test.update",
    "user.webhooks.parse.settings.create",
    "user.webhooks.parse.settings.read",
    "user.webhooks.parse.settings.update",
    "user.webhooks.parse.settings.delete",
    "stats.read",
    "stats.global.read",
    "categories.stats.read",
    "categories.stats.sums.read",
    "devices.stats.read",
    "clients.stats.read",
    "clients.phone.stats.read",
    "clients.tablet.stats.read",
    "clients.webmail.stats.read",
    "clients.desktop.stats.read",
    "geo.stats.read",
    "mailbox_providers.stats.read",
    "browsers.stats.read",
    "user.webhooks.parse.stats.read",
    "templates.create",
    "templates.read",
    "templates.update",
    "templates.delete",
    "templates.versions.create",
    "templates.versions.read",
    "templates.versions.update",
    "templates.versions.delete",
    "templates.versions.activate.create",
    "user.timezone.read",
    "user.timezone.update",
    "user.settings.enforced_tls.read",
    "user.settings.enforced_tls.update",
    "api_keys.create",
    "api_keys.read",
    "api_keys.update",
    "api_keys.delete",
    "email_activity.read",
    "categories.create",
    "categories.read",
    "categories.update",
    "categories.delete",
    "mail_settings.template.read",
    "mail_settings.template.update",
    "marketing_campaigns.create",
    "marketing_campaigns.read",
    "marketing_campaigns.update",
    "marketing_campaigns.delete",
    "mail.batch.create",
    "mail.batch.read",
    "mail.batch.update",
    "mail.batch.delete",
    "user.scheduled_sends.create",
    "user.scheduled_sends.read",
    "user.scheduled_sends.update",
    "user.scheduled_sends.delete",
    "access_settings.whitelist.create",
    "access_settings.whitelist.read",
    "access_settings.whitelist.update",
    "access_settings.whitelist.delete",
    "access_settings.activity.read",
    "whitelabel.create",
    "whitelabel.read",
    "whitelabel.update",
    "whitelabel.delete",
    "suppression.create",
    "suppression.read",
    "suppression.update",
    "suppression.delete"
]

}

但是没有"user-related"权限。出于这个原因,我尝试 "change" 我的密钥权限,例如:

{
"name": "__NAME__",
"scopes": [
    "alerts.create",
    "alerts.read",
    "alerts.update",
    "alerts.delete",
    "asm.groups.create",
    "asm.groups.read",
    "asm.groups.update",
    "asm.groups.delete",
    "ips.pools.ips.read",
    "mail.send",
    "mail_settings.bcc.read",
    "mail_settings.bcc.update",
    "mail_settings.address_whitelist.read",
    "mail_settings.address_whitelist.update",
    "mail_settings.footer.read",
    "mail_settings.footer.update",
    "mail_settings.forward_spam.read",
    "mail_settings.forward_spam.update",
    "mail_settings.plain_content.read",
    "mail_settings.plain_content.update",
    "mail_settings.spam_check.read",
    "mail_settings.spam_check.update",
    "mail_settings.bounce_purge.read",
    "mail_settings.bounce_purge.update",
    "mail_settings.forward_bounce.read",
    "mail_settings.forward_bounce.update",
    "partner_settings.new_relic.read",
    "partner_settings.new_relic.update",
    "partner_settings.sendwithus.read",
    "partner_settings.sendwithus.update",
    "tracking_settings.click.read",
    "tracking_settings.click.update",
    "tracking_settings.subscription.read",
    "tracking_settings.subscription.update",
    "tracking_settings.open.read",
    "tracking_settings.open.update",
    "tracking_settings.google_analytics.read",
    "tracking_settings.google_analytics.update",
    "user.webhooks.event.settings.read",
    "user.webhooks.event.settings.update",
    "user.webhooks.event.test.create",
    "user.webhooks.event.test.read",
    "user.webhooks.event.test.update",
    "user.webhooks.parse.settings.create",
    "user.webhooks.parse.settings.read",
    "user.webhooks.parse.settings.update",
    "user.webhooks.parse.settings.delete",
    "stats.read",
    "stats.global.read",
    "categories.stats.read",
    "categories.stats.sums.read",
    "devices.stats.read",
    "clients.stats.read",
    "clients.phone.stats.read",
    "clients.tablet.stats.read",
    "clients.webmail.stats.read",
    "clients.desktop.stats.read",
    "geo.stats.read",
    "mailbox_providers.stats.read",
    "browsers.stats.read",
    "user.webhooks.parse.stats.read",
    "templates.create",
    "templates.read",
    "templates.update",
    "templates.delete",
    "templates.versions.create",
    "templates.versions.read",
    "templates.versions.update",
    "templates.versions.delete",
    "templates.versions.activate.create",
    "user.timezone.read",
    "user.timezone.update",
    "user.settings.enforced_tls.read",
    "user.settings.enforced_tls.update",
    "api_keys.create",
    "api_keys.read",
    "api_keys.update",
    "api_keys.delete",
    "email_activity.read",
    "categories.create",
    "categories.read",
    "categories.update",
    "categories.delete",
    "mail_settings.template.read",
    "mail_settings.template.update",
    "marketing_campaigns.create",
    "marketing_campaigns.read",
    "marketing_campaigns.update",
    "marketing_campaigns.delete",
    "mail.batch.create",
    "mail.batch.read",
    "mail.batch.update",
    "mail.batch.delete",
    "user.scheduled_sends.create",
    "user.scheduled_sends.read",
    "user.scheduled_sends.update",
    "user.scheduled_sends.delete",
    "access_settings.whitelist.create",
    "access_settings.whitelist.read",
    "access_settings.whitelist.update",
    "access_settings.whitelist.delete",
    "access_settings.activity.read",
    "whitelabel.create",
    "whitelabel.read",
    "whitelabel.update",
    "whitelabel.delete",
    "suppression.create",
    "suppression.read",
    "suppression.update",
    "suppression.delete",
    "user.account.read",
      "user.credits.read",
      "user.email.create",
      "user.email.delete",
      "user.email.read",
      "user.email.update"
]
}

但我运气不好:

{
"errors": [
    {
        "field": null,
        "message": "unauthorized scopes: [user.account.read user.credits.read user.email.create user.email.delete user.email.read user.email.update]"
    }
]
}

有什么方法可以通过 API KEY 邀请某些用户加入 SendGrid?我做错了什么或与我的计划有关吗?

谢谢

回复在文档中,总结:

您必须使用用户名+密码创建超能力API KEY,然后使用它们。

来自: https://sendgrid.com/docs/Classroom/Basics/API/api_key_permissions.html

“在提出上述 API 请求之前需要了解的重要事项:

  1. 您需要使用 parent 帐户的用户名和密码验证上述请求,因为您的 API 密钥没有所需的 API 密钥权限。有两种使用用户名和密码进行身份验证的方法:

您可以通过对您的用户名和密码进行 base64 编码来为您的 API 调用自己添加基本授权,如下所示:username:password 并将其作为基本授权添加到您的授权 header 中。我们在这里对此进行更详细的介绍。 或者您可以使用像 Postman 或 Paw 这样的休息客户端,您可以在其中 select 使用基本身份验证(您的 SendGrid parent 帐户用户名和密码)进行身份验证,然后更新请求以添加您的 parent编码到 header 中的帐户凭据。 我们只建议在更新您的 API 密钥权限时使用您的用户名和密码进行身份验证。所有其他 API 调用都应通过您的 API 密钥进行身份验证。

  1. 确保在发出请求时添加了您希望 API 键拥有的所有范围。例如,如果您发出请求并仅将“categories.read”列为范围,那么您将拥有一个仅包含“categories.read”范围的键。除了要添加的新范围之外,请确保列出从获取现有密钥请求中获得的所有内容。