# Update the Credits for 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}/credits","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 to update the Credits for a Subuser.**

## 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":{"title":"Subuser Credits reset request body","type":"object","required":["type"],"refName":"SubuserCreditsRequest","modelName":"SubuserCreditsRequest","properties":{"type":{"type":"string","description":"Type determines how credits are reset for a Subuser. `unlimited` indicates that there is no limit to the Subuser's credits. `recurring` indicates that the credits for the Subuser are reset according to the frequency determined by `reset_frequency`. `nonrecurring` indicates that there is no recurring schedule to reset credits and resets must be done on an ad hoc basis.","enum":["unlimited","recurring","nonrecurring"],"refName":"Type1","modelName":"Type1"},"reset_frequency":{"type":"string","description":"The frequency with which a Subuser's credits are reset if `type` is set to `recurring`. Do _not_ include `reset_frequency` if you choose a reset `type` value of `unlimited` or `nonrecurring`.","enum":["monthly","weekly","daily"],"refName":"ResetFrequency1","modelName":"ResetFrequency1"},"total":{"type":"integer","description":"Total number of credits to which the Subuser is to be reset. If `type` is `nonrecurring` then the Subuser's credits will be reset to `total` on a one-time basis. If `type` is `recurring` then the Subuser's credits will be reset to `total` every time a reset is scheduled in accordance with the `reset_frequency`. Do _not_ include `total` if you choose a reset `type` value of `unlimited`.","minimum":1}}},"encodingType":"application/json"}
```

### Responses

```json
[{"responseCode":"200","schema":{"description":"","content":{"application/json":{"schema":{"title":"Credits of a Subuser","type":"object","required":["type","reset_frequency","remain","total","used"],"example":{"type":"recurring","reset_frequency":"monthly","remain":99,"total":100,"used":1},"refName":"SubuserCredits","modelName":"SubuserCredits","properties":{"type":{"type":"string","description":"Type determines how credits are reset for a Subuser. `unlimited` indicates that there is no limit to the Subuser's credits. `recurring` indicates that the credits for the Subuser are reset according to the frequency determined by `reset_frequency`. `nonrecurring` indicates that there is no recurring schedule to reset credits and resets must be done on an ad hoc basis.","enum":["unlimited","recurring","nonrecurring"],"refName":"Type","modelName":"Type"},"reset_frequency":{"type":"string","nullable":true,"description":"The frequency with which a Subuser's credits are reset if `type` is set to `recurring`, otherwise `null`.","enum":["monthly","weekly","daily"],"refName":"ResetFrequency","modelName":"ResetFrequency"},"remain":{"type":"integer","nullable":true,"description":"Total number of remaining credits. `remain` is `null` if the reset `type` for the Subuser's credits is set to `unlimited`.","minimum":0},"total":{"type":"integer","nullable":true,"description":"Total number of allowable credits. `total` is `null` if the reset `type` for the Subuser's credits is set to `unlimited` or `nonrecurring`.","minimum":0},"used":{"type":"integer","nullable":true,"description":"Total number of used credits. `used` is `null` if the reset `type` for the Subuser's credits is set to `unlimited` or `nonrecurring`.","minimum":0}}},"examples":{"response":{"value":{"remain":100,"total":100,"used":0,"type":"recurring","reset_frequency":"monthly"}}}}}}},{"responseCode":"400","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":"type","message":"Type should be set to 'recurring', 'nonrecurring', or 'unlimited'"}]}}}}}}}]
```

Update the Credits for a Subuser (recurring)

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

const subuser_name = "some_one";
const data = {
  type: "recurring",
  reset_frequency: "monthly",
  total: 100,
};

const request = {
  url: `/v3/subusers/${subuser_name}/credits`,
  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 = "some_one"
data = {"type": "recurring", "reset_frequency": "monthly", "total": 100}

response = sg.client.subusers._(subuser_name).credits.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 = "some_one";
        var data =
            @"{
            ""type"": ""recurring"",
            ""reset_frequency"": ""monthly"",
            ""total"": 100
        }";

        var response = await client.RequestAsync(
            method: SendGridClient.Method.PUT,
            urlPath: $"subusers/{subuserName}/credits",
            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.JSONObject;
import java.util.HashMap;
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/some_one/credits");
            request.setBody(new JSONObject(new HashMap<String, Object>() {
                {
                    put("type", "recurring");
                    put("reset_frequency", "monthly");
                    put("total", 100);
                }
            }).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/some_one/credits", host)
	request.Method = "PUT"
	request.Body = []byte(`{
  "type": "recurring",
  "reset_frequency": "monthly",
  "total": 100
}`)
	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('{
    "type": "recurring",
    "reset_frequency": "monthly",
    "total": 100
}');
$subuser_name = "some_one";

try {
    $response = $sg->client
        ->subusers()
        ->_($subuser_name)
        ->credits()
        ->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('{
  "type": "recurring",
  "reset_frequency": "monthly",
  "total": 100
}')
subuser_name = "some_one"

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

```bash
curl -X PUT "https://api.sendgrid.com/v3/subusers/some_one/credits" \
--header "Authorization: Bearer $SENDGRID_API_KEY" \
--header "Content-Type: application/json" \
--data '{"type": "recurring", "reset_frequency": "monthly", "total": 100}'
```

Update the Credits for a Subuser (non-recurring)

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

const subuser_name = "some_one";
const data = {
  type: "nonrecurring",
  total: 100,
};

const request = {
  url: `/v3/subusers/${subuser_name}/credits`,
  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 = "some_one"
data = {"type": "nonrecurring", "total": 100}

response = sg.client.subusers._(subuser_name).credits.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 = "some_one";
        var data =
            @"{
            ""type"": ""nonrecurring"",
            ""total"": 100
        }";

        var response = await client.RequestAsync(
            method: SendGridClient.Method.PUT,
            urlPath: $"subusers/{subuserName}/credits",
            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.JSONObject;
import java.util.HashMap;
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/some_one/credits");
            request.setBody(new JSONObject(new HashMap<String, Object>() {
                {
                    put("type", "nonrecurring");
                    put("total", 100);
                }
            }).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/some_one/credits", host)
	request.Method = "PUT"
	request.Body = []byte(`{
  "type": "nonrecurring",
  "total": 100
}`)
	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('{
    "type": "nonrecurring",
    "total": 100
}');
$subuser_name = "some_one";

try {
    $response = $sg->client
        ->subusers()
        ->_($subuser_name)
        ->credits()
        ->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('{
  "type": "nonrecurring",
  "total": 100
}')
subuser_name = "some_one"

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

```bash
curl -X PUT "https://api.sendgrid.com/v3/subusers/some_one/credits" \
--header "Authorization: Bearer $SENDGRID_API_KEY" \
--header "Content-Type: application/json" \
--data '{"type": "nonrecurring", "total": 100}'
```

Update the Credits for a Subuser (unlimited)

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

const subuser_name = "some_one";
const data = {
  type: "unlimited",
};

const request = {
  url: `/v3/subusers/${subuser_name}/credits`,
  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 = "some_one"
data = {"type": "unlimited"}

response = sg.client.subusers._(subuser_name).credits.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 = "some_one";
        var data =
            @"{
            ""type"": ""unlimited""
        }";

        var response = await client.RequestAsync(
            method: SendGridClient.Method.PUT,
            urlPath: $"subusers/{subuserName}/credits",
            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.JSONObject;
import java.util.HashMap;
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/some_one/credits");
            request.setBody(new JSONObject(new HashMap<String, Object>() {
                {
                    put("type", "unlimited");
                }
            }).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/some_one/credits", host)
	request.Method = "PUT"
	request.Body = []byte(`{
  "type": "unlimited"
}`)
	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('{
    "type": "unlimited"
}');
$subuser_name = "some_one";

try {
    $response = $sg->client
        ->subusers()
        ->_($subuser_name)
        ->credits()
        ->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('{
  "type": "unlimited"
}')
subuser_name = "some_one"

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

```bash
curl -X PUT "https://api.sendgrid.com/v3/subusers/some_one/credits" \
--header "Authorization: Bearer $SENDGRID_API_KEY" \
--header "Content-Type: application/json" \
--data '{"type": "unlimited"}'
```
