Back to Collection Items
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oHttp = ObjCreate("Chilkat.Http")
Local $bSuccess
; Use this online tool to generate code from sample JSON: Generate Code to Create JSON
; The following JSON is sent in the request body.
; {
; "description": "Example description",
; "name": "MY_VARIABLE",
; "tags": [
; "team:front",
; "test:workflow-1"
; ],
; "value": {
; "secure": true,
; "value": "value"
; },
; "attributes": {
; "restricted_roles": [
; "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
; ]
; },
; "id": "anim irure id cupidatat",
; "parse_test_options": {
; "type": "http_body",
; "field": "content-type",
; "localVariableName": "LOCAL_VARIABLE",
; "parser": {
; "type": "regex",
; "value": ".*"
; }
; },
; "parse_test_public_id": "abc-def-123"
; }
$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.UpdateString("description","Example description")
$oJson.UpdateString("name","MY_VARIABLE")
$oJson.UpdateString("tags[0]","team:front")
$oJson.UpdateString("tags[1]","test:workflow-1")
$oJson.UpdateBool("value.secure",True)
$oJson.UpdateString("value.value","value")
$oJson.UpdateString("attributes.restricted_roles[0]","xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
$oJson.UpdateString("id","anim irure id cupidatat")
$oJson.UpdateString("parse_test_options.type","http_body")
$oJson.UpdateString("parse_test_options.field","content-type")
$oJson.UpdateString("parse_test_options.localVariableName","LOCAL_VARIABLE")
$oJson.UpdateString("parse_test_options.parser.type","regex")
$oJson.UpdateString("parse_test_options.parser.value",".*")
$oJson.UpdateString("parse_test_public_id","abc-def-123")
$oHttp.SetRequestHeader "Content-Type","application/json"
$oHttp.SetRequestHeader "Accept","application/json"
$oSbRequestBody = ObjCreate("Chilkat.StringBuilder")
$oJson.EmitSb($oSbRequestBody)
Local $oResp = $oHttp.PTextSb("PUT","https://api.app.ddog-gov.com/api/v1/synthetics/variables/:variable_id",$oSbRequestBody,"utf-8","application/json",False,False)
If ($oHttp.LastMethodSuccess = False) Then
ConsoleWrite($oHttp.LastErrorText & @CRLF)
Exit
EndIf
$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$oResp.GetBodySb($oSbResponseBody)
$oJResp = ObjCreate("Chilkat.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False
ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)
Local $iRespStatusCode = $oResp.StatusCode
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
ConsoleWrite("Response Header:" & @CRLF)
ConsoleWrite($oResp.Header & @CRLF)
ConsoleWrite("Failed." & @CRLF)
Exit
EndIf
; Sample JSON response:
; (Sample code for parsing the JSON response is shown below)
; {
; "description": "Example description",
; "name": "MY_VARIABLE",
; "tags": [
; "team:front",
; "test:workflow-1"
; ],
; "value": {
; "secure": true,
; "value": "value"
; },
; "attributes": {
; "restricted_roles": [
; "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
; ]
; },
; "id": "anim irure id cupidatat",
; "parse_test_options": {
; "type": "http_body",
; "field": "content-type",
; "localVariableName": "LOCAL_VARIABLE",
; "parser": {
; "type": "regex",
; "value": ".*"
; }
; },
; "parse_test_public_id": "abc-def-123"
; }
; Sample code for parsing the JSON response...
; Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
Local $strVal
Local $sDescription = $oJResp.StringOf("description")
Local $sName = $oJResp.StringOf("name")
Local $bSecure = $oJResp.BoolOf("value.secure")
Local $sValue = $oJResp.StringOf("value.value")
Local $sId = $oJResp.StringOf("id")
Local $sV_Type = $oJResp.StringOf("parse_test_options.type")
Local $sField = $oJResp.StringOf("parse_test_options.field")
Local $sLocalVariableName = $oJResp.StringOf("parse_test_options.localVariableName")
Local $sParserType = $oJResp.StringOf("parse_test_options.parser.type")
Local $sParserValue = $oJResp.StringOf("parse_test_options.parser.value")
Local $sParse_test_public_id = $oJResp.StringOf("parse_test_public_id")
Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("tags")
While $i < $iCount_i
$oJResp.I = $i
$strVal = $oJResp.StringOf("tags[i]")
$i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("attributes.restricted_roles")
While $i < $iCount_i
$oJResp.I = $i
$strVal = $oJResp.StringOf("attributes.restricted_roles[i]")
$i = $i + 1
Wend
Curl Command
curl -X PUT
-H "Content-Type: application/json"
-H "Accept: application/json"
-d '{
"description": "Example description",
"name": "MY_VARIABLE",
"tags": [
"team:front",
"test:workflow-1"
],
"value": {
"secure": true,
"value": "value"
},
"attributes": {
"restricted_roles": [
"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
]
},
"id": "anim irure id cupidatat",
"parse_test_options": {
"type": "http_body",
"field": "content-type",
"localVariableName": "LOCAL_VARIABLE",
"parser": {
"type": "regex",
"value": ".*"
}
},
"parse_test_public_id": "abc-def-123"
}'
https://api.app.ddog-gov.com/api/v1/synthetics/variables/:variable_id
Postman Collection Item JSON
{
"name": "Edit a global variable",
"request": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"description\": \"Example description\",\n \"name\": \"MY_VARIABLE\",\n \"tags\": [\n \"team:front\",\n \"test:workflow-1\"\n ],\n \"value\": {\n \"secure\": true,\n \"value\": \"value\"\n },\n \"attributes\": {\n \"restricted_roles\": [\n \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"\n ]\n },\n \"id\": \"anim irure id cupidatat\",\n \"parse_test_options\": {\n \"type\": \"http_body\",\n \"field\": \"content-type\",\n \"localVariableName\": \"LOCAL_VARIABLE\",\n \"parser\": {\n \"type\": \"regex\",\n \"value\": \".*\"\n }\n },\n \"parse_test_public_id\": \"abc-def-123\"\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/synthetics/variables/:variable_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"synthetics",
"variables",
":variable_id"
],
"variable": [
{
"key": "variable_id",
"value": "tempor Ut sed velit"
}
]
},
"description": "Edit a Synthetic global variable."
},
"response": [
{
"name": "OK",
"originalRequest": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"description\": \"Example description\",\n \"name\": \"MY_VARIABLE\",\n \"tags\": [\n \"team:front\",\n \"test:workflow-1\"\n ],\n \"value\": {\n \"secure\": true,\n \"value\": \"value\"\n },\n \"attributes\": {\n \"restricted_roles\": [\n \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"\n ]\n },\n \"id\": \"anim irure id cupidatat\",\n \"parse_test_options\": {\n \"type\": \"http_body\",\n \"field\": \"content-type\",\n \"localVariableName\": \"LOCAL_VARIABLE\",\n \"parser\": {\n \"type\": \"regex\",\n \"value\": \".*\"\n }\n },\n \"parse_test_public_id\": \"abc-def-123\"\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/synthetics/variables/:variable_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"synthetics",
"variables",
":variable_id"
],
"variable": [
{
"key": "variable_id"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"description\": \"Example description\",\n \"name\": \"MY_VARIABLE\",\n \"tags\": [\n \"team:front\",\n \"test:workflow-1\"\n ],\n \"value\": {\n \"secure\": true,\n \"value\": \"value\"\n },\n \"attributes\": {\n \"restricted_roles\": [\n \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"\n ]\n },\n \"id\": \"anim irure id cupidatat\",\n \"parse_test_options\": {\n \"type\": \"http_body\",\n \"field\": \"content-type\",\n \"localVariableName\": \"LOCAL_VARIABLE\",\n \"parser\": {\n \"type\": \"regex\",\n \"value\": \".*\"\n }\n },\n \"parse_test_public_id\": \"abc-def-123\"\n}"
},
{
"name": "Invalid request",
"originalRequest": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"description\": \"Example description\",\n \"name\": \"MY_VARIABLE\",\n \"tags\": [\n \"team:front\",\n \"test:workflow-1\"\n ],\n \"value\": {\n \"secure\": true,\n \"value\": \"value\"\n },\n \"attributes\": {\n \"restricted_roles\": [\n \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"\n ]\n },\n \"id\": \"anim irure id cupidatat\",\n \"parse_test_options\": {\n \"type\": \"http_body\",\n \"field\": \"content-type\",\n \"localVariableName\": \"LOCAL_VARIABLE\",\n \"parser\": {\n \"type\": \"regex\",\n \"value\": \".*\"\n }\n },\n \"parse_test_public_id\": \"abc-def-123\"\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/synthetics/variables/:variable_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"synthetics",
"variables",
":variable_id"
],
"variable": [
{
"key": "variable_id"
}
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"Bad Request\",\n \"Bad Request\"\n ]\n}"
},
{
"name": "Forbidden",
"originalRequest": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"description\": \"Example description\",\n \"name\": \"MY_VARIABLE\",\n \"tags\": [\n \"team:front\",\n \"test:workflow-1\"\n ],\n \"value\": {\n \"secure\": true,\n \"value\": \"value\"\n },\n \"attributes\": {\n \"restricted_roles\": [\n \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"\n ]\n },\n \"id\": \"anim irure id cupidatat\",\n \"parse_test_options\": {\n \"type\": \"http_body\",\n \"field\": \"content-type\",\n \"localVariableName\": \"LOCAL_VARIABLE\",\n \"parser\": {\n \"type\": \"regex\",\n \"value\": \".*\"\n }\n },\n \"parse_test_public_id\": \"abc-def-123\"\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/synthetics/variables/:variable_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"synthetics",
"variables",
":variable_id"
],
"variable": [
{
"key": "variable_id"
}
]
}
},
"status": "Forbidden",
"code": 403,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"Bad Request\",\n \"Bad Request\"\n ]\n}"
},
{
"name": "Too many requests",
"originalRequest": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "DD-API-KEY",
"value": "<API Key>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"description\": \"Example description\",\n \"name\": \"MY_VARIABLE\",\n \"tags\": [\n \"team:front\",\n \"test:workflow-1\"\n ],\n \"value\": {\n \"secure\": true,\n \"value\": \"value\"\n },\n \"attributes\": {\n \"restricted_roles\": [\n \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"\n ]\n },\n \"id\": \"anim irure id cupidatat\",\n \"parse_test_options\": {\n \"type\": \"http_body\",\n \"field\": \"content-type\",\n \"localVariableName\": \"LOCAL_VARIABLE\",\n \"parser\": {\n \"type\": \"regex\",\n \"value\": \".*\"\n }\n },\n \"parse_test_public_id\": \"abc-def-123\"\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/api/v1/synthetics/variables/:variable_id",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"v1",
"synthetics",
"variables",
":variable_id"
],
"variable": [
{
"key": "variable_id"
}
]
}
},
"status": "Too Many Requests",
"code": 429,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"errors\": [\n \"Bad Request\",\n \"Bad Request\"\n ]\n}"
}
]
}