> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://learning.postman.com/llms.txt. For full content including API reference and SDK examples, see https://learning.postman.com/llms-full.txt.

# Update global variables

PUT https://api.getpostman.com/workspaces/{workspaceId}/global-variables
Content-Type: application/json

Updates and replaces a workspace's global [variables](https://learning.postman.com/docs/sending-requests/variables/#variable-scopes). This endpoint replaces all existing global variables with the variables you pass in the request body.

Reference: https://learning.postman.com/api-docs/api-reference/workspaces/update-workspace-global-variables

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: Postman API
  version: 1.0.0
paths:
  /workspaces/{workspaceId}/global-variables:
    put:
      operationId: updateWorkspaceGlobalVariables
      summary: Update global variables
      description: >-
        Updates and replaces a workspace's global
        [variables](https://learning.postman.com/docs/sending-requests/variables/#variable-scopes).
        This endpoint replaces all existing global variables with the variables
        you pass in the request body.
      tags:
        - workspaces
      parameters:
        - name: workspaceId
          in: path
          description: The workspace's ID.
          required: true
          schema:
            $ref: '#/components/schemas/workspaceId'
        - name: x-api-key
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/updateWorkspaceGlobalVariablesResponse'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/commonErrorTypeTitleDetail'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/updateWorkspaceGlobalVariables'
servers:
  - url: https://api.getpostman.com
    description: https://api.getpostman.com
  - url: https://api.eu.postman.com
    description: https://api.eu.postman.com
components:
  schemas:
    workspaceId:
      type: string
      title: workspaceId
    GlobalVariableType:
      type: string
      enum:
        - default
        - secret
      description: >-
        The
        [type](https://learning.postman.com/docs/sending-requests/variables/#variable-types)
        of variable.
      title: GlobalVariableType
    globalVariable:
      type: object
      properties:
        key:
          type: string
          description: The variable's name.
        type:
          $ref: '#/components/schemas/GlobalVariableType'
          description: >-
            The
            [type](https://learning.postman.com/docs/sending-requests/variables/#variable-types)
            of variable.
        value:
          type: string
          description: The variable's value.
        enabled:
          type: boolean
          description: If true, the variable is enabled.
        description:
          type: string
          description: The variable's description.
      description: Information about the global variable.
      title: globalVariable
    updateWorkspaceGlobalVariables:
      type: object
      properties:
        values:
          type: array
          items:
            $ref: '#/components/schemas/globalVariable'
          description: A list of the workspace's global variables.
      title: updateWorkspaceGlobalVariables
    updateWorkspaceGlobalVariablesResponse:
      type: object
      properties:
        values:
          type: array
          items:
            $ref: '#/components/schemas/globalVariable'
          description: A list of the workspace's global variables.
      description: Information about the workspace's updated global variables.
      title: updateWorkspaceGlobalVariablesResponse
    CommonErrorTypeTitleDetailDetail:
      oneOf:
        - type: string
        - type: object
          additionalProperties:
            description: Any type
      description: Information about the error.
      title: CommonErrorTypeTitleDetailDetail
    commonErrorTypeTitleDetail:
      type: object
      properties:
        type:
          type: string
          description: The type of error.
        title:
          type: string
          description: A short summary of the problem.
        detail:
          $ref: '#/components/schemas/CommonErrorTypeTitleDetailDetail'
          description: Information about the error.
      title: commonErrorTypeTitleDetail
  securitySchemes:
    PostmanApiKey:
      type: apiKey
      in: header
      name: x-api-key
    scimApiKey:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        A valid [SCIM API
        key](https://learning.postman.com/docs/administration/scim-provisioning/scim-provisioning-overview/#generating-scim-api-key)
        for calls to SCIM endpoints.
    basicAuth:
      type: http
      scheme: basic

```

## Examples

### Global Variables Updated



**Request**

```json
undefined
```

**Response**

```json
{
  "values": [
    {
      "key": "x-api-key",
      "type": "secret",
      "value": "{{postman-api-key}}",
      "enabled": true,
      "description": "A valid Postman API key."
    },
    {
      "key": "collectionId",
      "type": "default",
      "value": "12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2",
      "enabled": true,
      "description": "The collection's ID."
    }
  ]
}
```

**SDK Code**

```python Global Variables Updated
import requests

url = "https://api.getpostman.com/workspaces/1f0df51a-8658-4ee8-a2a1-d2567dfa09a9/global-variables"

headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.put(url, headers=headers)

print(response.json())
```

```javascript Global Variables Updated
const url = 'https://api.getpostman.com/workspaces/1f0df51a-8658-4ee8-a2a1-d2567dfa09a9/global-variables';
const options = {
  method: 'PUT',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: undefined
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Global Variables Updated
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.getpostman.com/workspaces/1f0df51a-8658-4ee8-a2a1-d2567dfa09a9/global-variables"

	req, _ := http.NewRequest("PUT", url, nil)

	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Global Variables Updated
require 'uri'
require 'net/http'

url = URI("https://api.getpostman.com/workspaces/1f0df51a-8658-4ee8-a2a1-d2567dfa09a9/global-variables")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Put.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'

response = http.request(request)
puts response.read_body
```

```java Global Variables Updated
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.put("https://api.getpostman.com/workspaces/1f0df51a-8658-4ee8-a2a1-d2567dfa09a9/global-variables")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .asString();
```

```php Global Variables Updated
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://api.getpostman.com/workspaces/1f0df51a-8658-4ee8-a2a1-d2567dfa09a9/global-variables', [
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Global Variables Updated
using RestSharp;

var client = new RestClient("https://api.getpostman.com/workspaces/1f0df51a-8658-4ee8-a2a1-d2567dfa09a9/global-variables");
var request = new RestRequest(Method.PUT);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
IRestResponse response = client.Execute(request);
```

```swift Global Variables Updated
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]

let request = NSMutableURLRequest(url: NSURL(string: "https://api.getpostman.com/workspaces/1f0df51a-8658-4ee8-a2a1-d2567dfa09a9/global-variables")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### Update Global Variables



**Request**

```json
{
  "values": [
    {
      "key": "x-api-key",
      "type": "secret",
      "value": "{{postman-api-key}}",
      "enabled": true,
      "description": "A valid Postman API key."
    },
    {
      "key": "collectionId",
      "type": "default",
      "value": "12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2",
      "enabled": true,
      "description": "The collection's ID."
    }
  ]
}
```

**Response**

```json
{
  "values": [
    {
      "key": "x-api-key",
      "type": "secret",
      "value": "{{postman-api-key}}",
      "enabled": true,
      "description": "A valid Postman API key."
    },
    {
      "key": "collectionId",
      "type": "default",
      "value": "12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2",
      "enabled": true,
      "description": "The collection's ID."
    }
  ]
}
```

**SDK Code**

```python Update Global Variables
import requests

url = "https://api.getpostman.com/workspaces/1f0df51a-8658-4ee8-a2a1-d2567dfa09a9/global-variables"

payload = { "values": [
        {
            "key": "x-api-key",
            "type": "secret",
            "value": "{{postman-api-key}}",
            "enabled": True,
            "description": "A valid Postman API key."
        },
        {
            "key": "collectionId",
            "type": "default",
            "value": "12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2",
            "enabled": True,
            "description": "The collection's ID."
        }
    ] }
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.put(url, json=payload, headers=headers)

print(response.json())
```

```javascript Update Global Variables
const url = 'https://api.getpostman.com/workspaces/1f0df51a-8658-4ee8-a2a1-d2567dfa09a9/global-variables';
const options = {
  method: 'PUT',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"values":[{"key":"x-api-key","type":"secret","value":"{{postman-api-key}}","enabled":true,"description":"A valid Postman API key."},{"key":"collectionId","type":"default","value":"12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2","enabled":true,"description":"The collection\'s ID."}]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Update Global Variables
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.getpostman.com/workspaces/1f0df51a-8658-4ee8-a2a1-d2567dfa09a9/global-variables"

	payload := strings.NewReader("{\n  \"values\": [\n    {\n      \"key\": \"x-api-key\",\n      \"type\": \"secret\",\n      \"value\": \"{{postman-api-key}}\",\n      \"enabled\": true,\n      \"description\": \"A valid Postman API key.\"\n    },\n    {\n      \"key\": \"collectionId\",\n      \"type\": \"default\",\n      \"value\": \"12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2\",\n      \"enabled\": true,\n      \"description\": \"The collection's ID.\"\n    }\n  ]\n}")

	req, _ := http.NewRequest("PUT", url, payload)

	req.Header.Add("x-api-key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Update Global Variables
require 'uri'
require 'net/http'

url = URI("https://api.getpostman.com/workspaces/1f0df51a-8658-4ee8-a2a1-d2567dfa09a9/global-variables")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Put.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"values\": [\n    {\n      \"key\": \"x-api-key\",\n      \"type\": \"secret\",\n      \"value\": \"{{postman-api-key}}\",\n      \"enabled\": true,\n      \"description\": \"A valid Postman API key.\"\n    },\n    {\n      \"key\": \"collectionId\",\n      \"type\": \"default\",\n      \"value\": \"12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2\",\n      \"enabled\": true,\n      \"description\": \"The collection's ID.\"\n    }\n  ]\n}"

response = http.request(request)
puts response.read_body
```

```java Update Global Variables
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.put("https://api.getpostman.com/workspaces/1f0df51a-8658-4ee8-a2a1-d2567dfa09a9/global-variables")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"values\": [\n    {\n      \"key\": \"x-api-key\",\n      \"type\": \"secret\",\n      \"value\": \"{{postman-api-key}}\",\n      \"enabled\": true,\n      \"description\": \"A valid Postman API key.\"\n    },\n    {\n      \"key\": \"collectionId\",\n      \"type\": \"default\",\n      \"value\": \"12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2\",\n      \"enabled\": true,\n      \"description\": \"The collection's ID.\"\n    }\n  ]\n}")
  .asString();
```

```php Update Global Variables
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://api.getpostman.com/workspaces/1f0df51a-8658-4ee8-a2a1-d2567dfa09a9/global-variables', [
  'body' => '{
  "values": [
    {
      "key": "x-api-key",
      "type": "secret",
      "value": "{{postman-api-key}}",
      "enabled": true,
      "description": "A valid Postman API key."
    },
    {
      "key": "collectionId",
      "type": "default",
      "value": "12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2",
      "enabled": true,
      "description": "The collection\'s ID."
    }
  ]
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp Update Global Variables
using RestSharp;

var client = new RestClient("https://api.getpostman.com/workspaces/1f0df51a-8658-4ee8-a2a1-d2567dfa09a9/global-variables");
var request = new RestRequest(Method.PUT);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"values\": [\n    {\n      \"key\": \"x-api-key\",\n      \"type\": \"secret\",\n      \"value\": \"{{postman-api-key}}\",\n      \"enabled\": true,\n      \"description\": \"A valid Postman API key.\"\n    },\n    {\n      \"key\": \"collectionId\",\n      \"type\": \"default\",\n      \"value\": \"12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2\",\n      \"enabled\": true,\n      \"description\": \"The collection's ID.\"\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Update Global Variables
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["values": [
    [
      "key": "x-api-key",
      "type": "secret",
      "value": "{{postman-api-key}}",
      "enabled": true,
      "description": "A valid Postman API key."
    ],
    [
      "key": "collectionId",
      "type": "default",
      "value": "12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2",
      "enabled": true,
      "description": "The collection's ID."
    ]
  ]] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.getpostman.com/workspaces/1f0df51a-8658-4ee8-a2a1-d2567dfa09a9/global-variables")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```