Chilkat Online Tools

VB.NET / Orchestrator / Assets - Create

Back to Collection Items

' This example assumes the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.

Dim http As New Chilkat.Http
Dim success As Boolean

' Use this online tool to generate code from sample JSON: Generate Code to Create JSON

' The following JSON is sent in the request body.

' {
'   "Name": "Caesar",
'   "ValueScope": "Global",
'   "ValueType": "Text",
'   "StringValue": "Et tu Asset 2"
' }

Dim json As New Chilkat.JsonObject
json.UpdateString("Name","Caesar")
json.UpdateString("ValueScope","Global")
json.UpdateString("ValueType","Text")
json.UpdateString("StringValue","Et tu Asset 2")

http.SetRequestHeader("Content-Type","application/json")
' Adds the "Authorization: Bearer <access_token>" header.
http.AuthToken = "<access_token>"
http.SetRequestHeader("X-UIPATH-OrganizationUnitId","{{folderId}}")
http.SetRequestHeader("X-UIPATH-TenantName","{{tenantName}}")

Dim resp As Chilkat.HttpResponse = http.PostJson3("https://domain.com/odata/Assets","application/json",json)
If (http.LastMethodSuccess = False) Then
    Debug.WriteLine(http.LastErrorText)
    Exit Sub
End If


Dim sbResponseBody As New Chilkat.StringBuilder
resp.GetBodySb(sbResponseBody)

Dim jResp As New Chilkat.JsonObject
jResp.LoadSb(sbResponseBody)
jResp.EmitCompact = False

Debug.WriteLine("Response Body:")
Debug.WriteLine(jResp.Emit())

Dim respStatusCode As Integer = resp.StatusCode
Debug.WriteLine("Response Status Code = " & respStatusCode)
If (respStatusCode >= 400) Then
    Debug.WriteLine("Response Header:")
    Debug.WriteLine(resp.Header)
    Debug.WriteLine("Failed.")

    Exit Sub
End If



' Sample JSON response:
' (Sample code for parsing the JSON response is shown below)

' {
'   "@odata.context": "https://platform.uipath.com/odata/$metadata#Assets/$entity",
'   "Name": "Caesar",
'   "CanBeDeleted": true,
'   "ValueScope": "Global",
'   "ValueType": "Text",
'   "Value": "Et tu Asset 2",
'   "StringValue": "Et tu Asset 2",
'   "BoolValue": false,
'   "IntValue": 0,
'   "CredentialUsername": "",
'   "CredentialPassword": "",
'   "Id": 38355,
'   "KeyValueList": [
'   ]
' }

' Sample code for parsing the JSON response...
' Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code




Dim odata_context As String = jResp.StringOf("""@odata.context""")
Dim Name As String = jResp.StringOf("Name")
Dim CanBeDeleted As Boolean = jResp.BoolOf("CanBeDeleted")
Dim ValueScope As String = jResp.StringOf("ValueScope")
Dim ValueType As String = jResp.StringOf("ValueType")
Dim Value As String = jResp.StringOf("Value")
Dim StringValue As String = jResp.StringOf("StringValue")
Dim BoolValue As Boolean = jResp.BoolOf("BoolValue")
Dim IntValue As Integer = jResp.IntOf("IntValue")
Dim CredentialUsername As String = jResp.StringOf("CredentialUsername")
Dim CredentialPassword As String = jResp.StringOf("CredentialPassword")
Dim Id As Integer = jResp.IntOf("Id")
Dim i As Integer = 0
Dim count_i As Integer = jResp.SizeOfArray("KeyValueList")
While i < count_i
    jResp.I = i
    i = i + 1
End While

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-H "X-UIPATH-TenantName: {{tenantName}}"
	-H "X-UIPATH-OrganizationUnitId: {{folderId}}"
	-d '{
	"Name": "Caesar",
	"ValueScope": "Global",
	"ValueType": "Text",
	"StringValue": "Et tu Asset 2"
}'
https://domain.com/odata/Assets

Postman Collection Item JSON

{
  "name": "Assets - Create",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json",
        "type": "text"
      },
      {
        "key": "X-UIPATH-TenantName",
        "value": "{{tenantName}}",
        "type": "text"
      },
      {
        "key": "X-UIPATH-OrganizationUnitId",
        "value": "{{folderId}}",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n\t\"Name\": \"Caesar\",\n\t\"ValueScope\": \"Global\",\n\t\"ValueType\": \"Text\",\n\t\"StringValue\": \"Et tu Asset 2\"\n}"
    },
    "url": {
      "raw": "{{url}}/odata/Assets",
      "host": [
        "{{url}}"
      ],
      "path": [
        "odata",
        "Assets"
      ]
    },
    "description": "Create a new Asset\n\nValueScope: Global or PerRobot\n\nValueType: Text, Bool, Integer, or Credential"
  },
  "response": [
    {
      "name": "Assets - Create",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json",
            "disabled": false
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n\t\"Name\": \"Caesar\",\n\t\"ValueScope\": \"Global\",\n\t\"ValueType\": \"Text\",\n\t\"StringValue\": \"Et tu Asset 2\"\n}"
        },
        "url": {
          "raw": "{{url}}/odata/Assets",
          "host": [
            "{{url}}"
          ],
          "path": [
            "odata",
            "Assets"
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "CF-RAY",
          "value": "43b31169d9d6bf07-FRA",
          "name": "CF-RAY",
          "description": "Custom header"
        },
        {
          "key": "Cache-Control",
          "value": "no-store, must-revalidate, no-cache, max-age=0",
          "name": "Cache-Control",
          "description": "Tells all caching mechanisms from server to client whether they may cache this object. It is measured in seconds"
        },
        {
          "key": "Connection",
          "value": "keep-alive",
          "name": "Connection",
          "description": "Options that are desired for the connection"
        },
        {
          "key": "Content-Length",
          "value": "319",
          "name": "Content-Length",
          "description": "The length of the response body in octets (8-bit bytes)"
        },
        {
          "key": "Content-Type",
          "value": "application/json; odata.metadata=minimal",
          "name": "Content-Type",
          "description": "The mime type of this content"
        },
        {
          "key": "Date",
          "value": "Mon, 16 Jul 2018 08:23:40 GMT",
          "name": "Date",
          "description": "The date and time that the message was sent"
        },
        {
          "key": "Expect-CT",
          "value": "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"",
          "name": "Expect-CT",
          "description": "Custom header"
        },
        {
          "key": "Location",
          "value": "https://platform.uipath.com/odata/Assets(38355)",
          "name": "Location",
          "description": "Used in redirection, or when a new resource has been created."
        },
        {
          "key": "OData-Version",
          "value": "4.0",
          "name": "OData-Version",
          "description": "Custom header"
        },
        {
          "key": "Server",
          "value": "cloudflare",
          "name": "Server",
          "description": "A name for the server"
        },
        {
          "key": "Set-Cookie",
          "value": "; SameSite=lax",
          "name": "Set-Cookie",
          "description": "an HTTP cookie"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=31536000; includeSubDomains",
          "name": "Strict-Transport-Security",
          "description": "A HSTS Policy informing the HTTP client how long to cache the HTTPS only policy and whether this applies to subdomains."
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff",
          "name": "X-Content-Type-Options",
          "description": "The only defined value, \"nosniff\", prevents Internet Explorer from MIME-sniffing a response away from the declared content-type"
        },
        {
          "key": "X-Frame-Options",
          "value": "DENY",
          "name": "X-Frame-Options",
          "description": "Clickjacking protection: \"deny\" - no rendering within a frame, \"sameorigin\" - no rendering if origin mismatch"
        },
        {
          "key": "api-supported-versions",
          "value": "5.0",
          "name": "api-supported-versions",
          "description": "Custom header"
        }
      ],
      "cookie": [
        {
          "expires": "Wed Dec 19 2018 11:35:02 GMT-0600 (Central Standard Time)",
          "httpOnly": true,
          "domain": "uipath.com",
          "path": "/",
          "secure": true,
          "value": "d3b89a558feb68050f4b847c971f595771513704902",
          "key": "__cfduid"
        },
        {
          "expires": "Mon Jan 18 2038 21:14:07 GMT-0600 (Central Standard Time)",
          "httpOnly": false,
          "domain": "platform.uipath.com",
          "path": "/odata/QueueProcessingRecords",
          "secure": false,
          "value": "",
          "key": ""
        },
        {
          "expires": "Mon Jan 18 2038 21:14:07 GMT-0600 (Central Standard Time)",
          "httpOnly": false,
          "domain": "platform.uipath.com",
          "path": "/api/RobotsService",
          "secure": false,
          "value": "",
          "key": ""
        },
        {
          "expires": "Mon Jan 18 2038 21:14:07 GMT-0600 (Central Standard Time)",
          "httpOnly": false,
          "domain": "platform.uipath.com",
          "path": "/odata/Processes",
          "secure": false,
          "value": "",
          "key": ""
        },
        {
          "expires": "Mon Jan 18 2038 21:14:07 GMT-0600 (Central Standard Time)",
          "httpOnly": false,
          "domain": "platform.uipath.com",
          "path": "/odata/Settings",
          "secure": false,
          "value": "",
          "key": ""
        },
        {
          "expires": "Mon Jan 18 2038 21:14:07 GMT-0600 (Central Standard Time)",
          "httpOnly": false,
          "domain": "platform.uipath.com",
          "path": "/odata/Robots",
          "secure": false,
          "value": "",
          "key": ""
        },
        {
          "expires": "Mon Jan 18 2038 21:14:07 GMT-0600 (Central Standard Time)",
          "httpOnly": false,
          "domain": "platform.uipath.com",
          "path": "/odata/Queues",
          "secure": false,
          "value": "",
          "key": ""
        },
        {
          "expires": "Mon Jan 18 2038 21:14:07 GMT-0600 (Central Standard Time)",
          "httpOnly": false,
          "domain": "platform.uipath.com",
          "path": "/odata/Assets",
          "secure": false,
          "value": "",
          "key": ""
        },
        {
          "expires": "Mon Jan 18 2038 21:14:07 GMT-0600 (Central Standard Time)",
          "httpOnly": false,
          "domain": "platform.uipath.com",
          "path": "/api/Account",
          "secure": false,
          "value": "",
          "key": ""
        },
        {
          "expires": "Mon Jan 18 2038 21:14:07 GMT-0600 (Central Standard Time)",
          "httpOnly": false,
          "domain": "platform.uipath.com",
          "path": "/odata/Users",
          "secure": false,
          "value": "",
          "key": ""
        },
        {
          "expires": "Mon Jan 18 2038 21:14:07 GMT-0600 (Central Standard Time)",
          "httpOnly": false,
          "domain": "platform.uipath.com",
          "path": "/odata/Jobs",
          "secure": false,
          "value": "",
          "key": ""
        },
        {
          "expires": "Mon Jan 18 2038 21:14:07 GMT-0600 (Central Standard Time)",
          "httpOnly": false,
          "domain": "platform.uipath.com",
          "path": "/api/Logs",
          "secure": false,
          "value": "",
          "key": ""
        },
        {
          "expires": "Mon Jan 18 2038 21:14:07 GMT-0600 (Central Standard Time)",
          "httpOnly": false,
          "domain": "platform.uipath.com",
          "path": "/Account",
          "secure": false,
          "value": "",
          "key": ""
        },
        {
          "expires": "Mon Jan 18 2038 21:14:07 GMT-0600 (Central Standard Time)",
          "httpOnly": false,
          "domain": "platform.uipath.com",
          "path": "/odata",
          "secure": false,
          "value": "",
          "key": ""
        },
        {
          "expires": "Mon Jan 18 2038 21:14:07 GMT-0600 (Central Standard Time)",
          "httpOnly": false,
          "domain": "platform.uipath.com",
          "path": "/api",
          "secure": false,
          "value": "",
          "key": ""
        },
        {
          "expires": "Mon Jan 18 2038 21:14:07 GMT-0600 (Central Standard Time)",
          "httpOnly": false,
          "domain": "platform.uipath.com",
          "path": "/",
          "secure": false,
          "value": "",
          "key": ""
        },
        {
          "expires": "Mon Jan 18 2038 21:14:07 GMT-0600 (Central Standard Time)",
          "httpOnly": false,
          "domain": "platform.uipath.com",
          "path": "/",
          "secure": false,
          "value": "GC-osp2U-YDhoXTOqXnUp3DaN1cN_siVCaNVue_jljOcqJLYHQrRk5msz52KHL8XauydRYx_3JyjLtLDpItypCPdEL20jFnxlF2g-f86Qk41",
          "key": "__RequestVerificationToken"
        }
      ],
      "body": "{\n    \"@odata.context\": \"https://platform.uipath.com/odata/$metadata#Assets/$entity\",\n    \"Name\": \"Caesar\",\n    \"CanBeDeleted\": true,\n    \"ValueScope\": \"Global\",\n    \"ValueType\": \"Text\",\n    \"Value\": \"Et tu Asset 2\",\n    \"StringValue\": \"Et tu Asset 2\",\n    \"BoolValue\": false,\n    \"IntValue\": 0,\n    \"CredentialUsername\": \"\",\n    \"CredentialPassword\": \"\",\n    \"Id\": 38355,\n    \"KeyValueList\": []\n}"
    }
  ]
}