Welcome to the new Box Support website. Check out all the details here on what’s changed.

Add Email Alias API returns bad request

Answered
New post

Comments

3 comments

  • THortert

    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"}

    0
    Comment actions Permalink
  • rocks

    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"

     

    Box Domains.png

     

    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

     

    0
    Comment actions Permalink
  • rocks

    fyi, see information above for testing.

    0
    Comment actions Permalink

Please sign in to leave a comment.