# Update IPs assigned to a subuser

## API Overview

For more information about Subusers, visit the [longform Subusers documentation](/docs/sendgrid/ui/account-and-settings/subusers/). You can also [manage Subusers in the SendGrid console](https://app.sendgrid.com/settings/subusers).

## Operation overview

```json
{"path":"https://api.sendgrid.com/v3/subusers/{subuser_name}/ips","method":"put","servers":[{"url":"https://api.sendgrid.com","description":"for global users and subusers"},{"url":"https://api.eu.sendgrid.com","description":"for EU regional subusers"}]}
```

**This endpoint allows you update your subusers' assigned IP.**

Each subuser should be assigned to an IP address from which all of this subuser's mail will be sent. Often, this is the same IP as the parent account, but each subuser can have one or more of their own IP addresses as well.

More information:

* [How to request more IPs](/docs/sendgrid/ui/account-and-settings/dedicated-ip-addresses/)
* [Setup Reverse DNS](/docs/sendgrid/ui/account-and-settings/how-to-set-up-reverse-dns/)

## Operation details

### Authentication

API Key

### Headers

```json
[{"in":"header","name":"Authorization","required":true,"default":"Bearer <<YOUR_API_KEY_HERE>>","schema":{"type":"string"}}]
```

### Path parameters

```json
[{"name":"subuser_name","in":"path","required":true,"description":"The username of the Subuser.","schema":{"type":"string"},"refName":"#/components/parameters/UserName","modelName":"__components_parameters_UserName"}]
```

### Request body

```json
{"schema":{"type":"array","description":"The IP addresses you would like to assign to the subuser.","example":["127.0.0.1"],"items":{"type":"string","format":"ipv4"}},"encodingType":"application/json"}
```

### Responses

```json
[{"responseCode":"200","schema":{"description":"","content":{"application/json":{"schema":{"type":"object","properties":{"ips":{"type":"array","description":"The IP addresses that are assigned to the subuser.","items":{"type":"string","format":"ipv4"}}}},"examples":{"response":{"value":{"ips":["127.0.0.1"]}}}}}}},{"responseCode":"401","schema":{"description":"","content":{"application/json":{"schema":{"type":"object","example":{"errors":[{"field":"field_name","message":"error message"}]},"refName":"ErrorResponse","modelName":"ErrorResponse","properties":{"errors":{"type":"array","items":{"type":"object","properties":{"message":{"type":"string","description":"An error message."},"field":{"description":"When applicable, this property value will be the field that generated the error.","nullable":true,"type":"string"},"help":{"type":"object","description":"When applicable, this property value will be helper text or a link to documentation to help you troubleshoot the error."}}}},"id":{"type":"string","description":"When applicable, this property value will be an error ID."}}},"examples":{"response":{"value":{"errors":[{"field":null,"message":"authorization required"}]}}}}}}}]
```

Update IPs assigned to a subuser

```js
const client = require("@sendgrid/client");
client.setApiKey(process.env.SENDGRID_API_KEY);

const subuser_name = "subuser_name";
const data = ["127.0.0.1"];

const request = {
  url: `/v3/subusers/${subuser_name}/ips`,
  method: "PUT",
  body: data,
};

client
  .request(request)
  .then(([response, body]) => {
    console.log(response.statusCode);
    console.log(response.body);
  })
  .catch((error) => {
    console.error(error);
  });
```

```python
import os
from sendgrid import SendGridAPIClient


sg = SendGridAPIClient(os.environ.get("SENDGRID_API_KEY"))

subuser_name = "subuser_name"
data = ["127.0.0.1"]

response = sg.client.subusers._(subuser_name).ips.put(request_body=data)

print(response.status_code)
print(response.body)
print(response.headers)
```

```csharp
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using SendGrid;

public class Program {
    public static async Task Main() {
        string apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
        var client = new SendGridClient(apiKey);

        var subuserName = "subuser_name";
        var data =
            @"[
            ""127.0.0.1""
        ]";

        var response = await client.RequestAsync(
            method: SendGridClient.Method.PUT,
            urlPath: $"subusers/{subuserName}/ips",
            requestBody: data);

        Console.WriteLine(response.StatusCode);
        Console.WriteLine(response.Body.ReadAsStringAsync().Result);
        Console.WriteLine(response.Headers.ToString());
    }
}
```

```java
import com.sendgrid.*;
import java.io.IOException;
import org.json.JSONArray;
import java.util.Arrays;

public class Example {
    public static void main(String[] args) throws IOException {
        try {
            SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
            Request request = new Request();
            request.setMethod(Method.PUT);
            request.setEndpoint("/subusers/subuser_name/ips");
            request.setBody(new JSONArray(Arrays.asList("127.0.0.1")).toString());
            Response response = sg.api(request);
            System.out.println(response.getStatusCode());
            System.out.println(response.getBody());
            System.out.println(response.getHeaders());
        } catch (IOException ex) {
            throw ex;
        }
    }
}
```

```go
package main

import (
	"fmt"
	"github.com/sendgrid/sendgrid-go"
	"os"
)

func main() {
	apiKey := os.Getenv("SENDGRID_API_KEY")
	host := "https://api.sendgrid.com"
	request := sendgrid.GetRequest(apiKey, "/v3/subusers/subuser_name/ips", host)
	request.Method = "PUT"
	request.Body = []byte(`[
  "127.0.0.1"
]`)
	response, err := sendgrid.API(request)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		fmt.Println(response.StatusCode)
		fmt.Println(response.Body)
		fmt.Println(response.Headers)
	}
}
```

```php
<?php
// Uncomment the next line if you're using a dependency loader (such as Composer) (recommended)
// require 'vendor/autoload.php';

// Uncomment next line if you're not using a dependency loader (such as Composer)
// require_once '<PATH TO>/sendgrid-php.php';

$apiKey = getenv("SENDGRID_API_KEY");
$sg = new \SendGrid($apiKey);
$request_body = json_decode('[
    "127.0.0.1"
]');
$subuser_name = "subuser_name";

try {
    $response = $sg->client
        ->subusers()
        ->_($subuser_name)
        ->ips()
        ->put($request_body);
    print $response->statusCode() . "\n";
    print_r($response->headers());
    print $response->body() . "\n";
} catch (Exception $ex) {
    echo "Caught exception: " . $ex->getMessage();
}
```

```ruby
require 'sendgrid-ruby'
include SendGrid

sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
data = JSON.parse('[
  "127.0.0.1"
]')
subuser_name = "subuser_name"

response = sg.client.subusers._(subuser_name).ips.put(request_body: data)
puts response.status_code
puts response.headers
puts response.body
```

```bash
curl -X PUT "https://api.sendgrid.com/v3/subusers/subuser_name/ips" \
--header "Authorization: Bearer $SENDGRID_API_KEY" \
--header "Content-Type: application/json" \
--data '["127.0.0.1"]'
```
