Add Email Alias API returns bad request
回答済みHello, I am trying to add an Email address to a user, but am getting 400 response and I do not know why. What limitations are there for adding email address?
API: https://docs.box.com/reference#add-an-email-alias-for-a-user
Here is my test user before modification:
GET https://api.box.com/2.0/users/ID
{
"type": "user",
"id": [some id],
"name": "prov26",
"login": "***@example.com",
"created_at": "20**removed**T03:06:**removed**:00",
"modified_at": "20**removed**T03:06:**removed**:00",
"language": "en",
"timezone": "America/Los_Angeles",
"space_amount": removed for privacy0,
"space_used": 0,
"max_upload_size": removed for privacy0,
"status": "active",
"job_title": "",
"phone": "",
"address": "china1",
"avatar_url": "https://wesoft.app.box.com/api/avatar/large/removed for privacy"
}
Here is a screenshot of my API call using postman
-
I am also having the same issue although if I manually add the alias via settings it works fine. I am trying to add an email alias to the user and according to the documentation the request should send the attribute as email and the email address following a colon after it. This is almost exactly like the Update User API except it is a Post instead of a Put and the update user function works fine for me. Following are the Powershell snippets I am using\API Examples and the error message that is returned when attempting to add the email alias, any help would be appreciated.
Email Alias Add Function:
function Add-BoxUserAlias($id, $value, $token)
{
#sets the given attribute to be the value passed
$attribute = "email"
$uri = "https://api.box.com/2.0/users/" + $id + "/email_aliases/"
$headers = @{"Authorization"="Bearer $token"}$json = '{ "' + $attribute + '": "' + $value + '"}'$return = Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $json -ContentType "application/json"}Update User PowerShell Function:
function Set-BoxUser($id, $attribute, $value, $token)
{
#sets the given attribute to be the value passed
$uri = "https://api.box.com/2.0/users/" + $id
$headers = @{"Authorization"="Bearer $token"}$json = '{ "' + $attribute + '": "' + $value + '"}'$return = Invoke-RestMethod -Uri $uri -Method Put -Headers $headers -Body $json -ContentType "application/json"}Update User API Example: "curl https://api.box.com/2.0/users/USER_ID \ -H "Authorization: Bearer ACCESS_TOKEN" \ -d '{"name": "sean"}' \ -X PUT"
Add Email Alias Example: "curl https://api.box.com/2.0/users/USER_ID/email_aliases \ -H "Authorization: Bearer ACCESS_TOKEN" \ -d '{"email": "***@example.com"}' -X POST"
Error Returned: Invoke-RestMethod : {"type":"error","status":400,"code":"bad_request","context_info":{"errors":[{"reason":"invalid_parameter","name":"email","message":"Invalid value'EmailAddressRemoved'."}]},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"BadRequest","request_id":"removed for privacy579935fdc188b"}
-
Hey ,
Your Postman syntax looks correct and if you copy the example straight from the documentation it will work provided the email value you are adding is valid.
curl https://api.box.com/2.0/users/USER_ID/email_aliases \ -H "Authorization: Bearer ACCESS_TOKEN" \ -d '{"email": "procks+jamesdean-alias-2@box.com"}' -X POST
{"type":"email_alias","id":"52xxx1","is_confirmed":true,"email":"procks+jamesdean-alias-2@box.com"}If you login to your Admin console and check the Enterprise Settings --> Account Info page you will see a list of registered domains for your enteprise. In my example below I only have "box.com"
Therefore, if i try to run the same API call with a random unregistered domain I will hit the same error you are seeing. i.e.
curl https://api.box.com/2.0/users/USER_ID/email_aliases \
-H "Authorization: Bearer ACCESS_TOKEN" \
-d '{"email": "procks+jamesdean-alias4@box10.com"}'
-X POST"errors": [ { "reason": "invalid_parameter", "name": "email", "message": "Invalid value 'procks+jamesdean-alias4@box10.com'." }
Please re-test with a registered domain and let me know if this works.
To add additional owned domains to your Box enteprise please reach out to your Customer Success Manager if known or raise a request with our User Services team
Peter
サインインしてコメントを残してください。
コメント
3件のコメント