Chilkat Online Tools

SQL Server / Salesforce Platform APIs / Get Values for a Picklist Field

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    -- Adds the "Authorization: Bearer <access_token>" header.
    EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'

    DECLARE @sbResponseBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://domain.com/services/data/v{{version}}/ui-api/object-info/:SOBJECT_API_NAME/picklist-values/:RECORD_TYPE_ID/:FIELD_API_NAME', @sbResponseBody
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END

    DECLARE @jResp int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @http, 'LastStatus', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END

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

    -- {
    --   "controllerValues": {},
    --   "defaultValue": null,
    --   "eTag": "bee3e6401e143e18332a17639061c5ff",
    --   "url": "/services/data/v51.0/ui-api/object-info/Account/picklist-values/012000000000000AAA/Industry",
    --   "values": [
    --     {
    --       "attributes": null,
    --       "label": "Agriculture",
    --       "validFor": [
    --       ],
    --       "value": "Agriculture"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Apparel",
    --       "validFor": [
    --       ],
    --       "value": "Apparel"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Banking",
    --       "validFor": [
    --       ],
    --       "value": "Banking"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Biotechnology",
    --       "validFor": [
    --       ],
    --       "value": "Biotechnology"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Chemicals",
    --       "validFor": [
    --       ],
    --       "value": "Chemicals"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Communications",
    --       "validFor": [
    --       ],
    --       "value": "Communications"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Construction",
    --       "validFor": [
    --       ],
    --       "value": "Construction"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Consulting",
    --       "validFor": [
    --       ],
    --       "value": "Consulting"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Education",
    --       "validFor": [
    --       ],
    --       "value": "Education"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Electronics",
    --       "validFor": [
    --       ],
    --       "value": "Electronics"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Energy",
    --       "validFor": [
    --       ],
    --       "value": "Energy"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Engineering",
    --       "validFor": [
    --       ],
    --       "value": "Engineering"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Entertainment",
    --       "validFor": [
    --       ],
    --       "value": "Entertainment"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Environmental",
    --       "validFor": [
    --       ],
    --       "value": "Environmental"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Finance",
    --       "validFor": [
    --       ],
    --       "value": "Finance"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Food & Beverage",
    --       "validFor": [
    --       ],
    --       "value": "Food & Beverage"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Government",
    --       "validFor": [
    --       ],
    --       "value": "Government"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Healthcare",
    --       "validFor": [
    --       ],
    --       "value": "Healthcare"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Hospitality",
    --       "validFor": [
    --       ],
    --       "value": "Hospitality"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Insurance",
    --       "validFor": [
    --       ],
    --       "value": "Insurance"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Machinery",
    --       "validFor": [
    --       ],
    --       "value": "Machinery"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Manufacturing",
    --       "validFor": [
    --       ],
    --       "value": "Manufacturing"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Media",
    --       "validFor": [
    --       ],
    --       "value": "Media"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Not For Profit",
    --       "validFor": [
    --       ],
    --       "value": "Not For Profit"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Recreation",
    --       "validFor": [
    --       ],
    --       "value": "Recreation"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Retail",
    --       "validFor": [
    --       ],
    --       "value": "Retail"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Shipping",
    --       "validFor": [
    --       ],
    --       "value": "Shipping"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Technology",
    --       "validFor": [
    --       ],
    --       "value": "Technology"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Telecommunications",
    --       "validFor": [
    --       ],
    --       "value": "Telecommunications"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Transportation",
    --       "validFor": [
    --       ],
    --       "value": "Transportation"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Utilities",
    --       "validFor": [
    --       ],
    --       "value": "Utilities"
    --     },
    --     {
    --       "attributes": null,
    --       "label": "Other",
    --       "validFor": [
    --       ],
    --       "value": "Other"
    --     }
    --   ]
    -- }

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

    DECLARE @attributes nvarchar(4000)

    DECLARE @label nvarchar(4000)

    DECLARE @value nvarchar(4000)

    DECLARE @j int

    DECLARE @count_j int

    DECLARE @defaultValue nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @defaultValue OUT, 'defaultValue'
    DECLARE @eTag nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @eTag OUT, 'eTag'
    DECLARE @url nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @url OUT, 'url'
    DECLARE @i int
    SELECT @i = 0
    DECLARE @count_i int
    EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'values'
    WHILE @i < @count_i
      BEGIN
        EXEC sp_OASetProperty @jResp, 'I', @i
        EXEC sp_OAMethod @jResp, 'StringOf', @attributes OUT, 'values[i].attributes'
        EXEC sp_OAMethod @jResp, 'StringOf', @label OUT, 'values[i].label'
        EXEC sp_OAMethod @jResp, 'StringOf', @value OUT, 'values[i].value'
        SELECT @j = 0
        EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'values[i].validFor'
        WHILE @j < @count_j
          BEGIN
            EXEC sp_OASetProperty @jResp, 'J', @j
            SELECT @j = @j + 1
          END
        SELECT @i = @i + 1
      END

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

Curl Command

curl -X GET
	-H "Authorization: Bearer <access_token>"
https://domain.com/services/data/v{{version}}/ui-api/object-info/:SOBJECT_API_NAME/picklist-values/:RECORD_TYPE_ID/:FIELD_API_NAME

Postman Collection Item JSON

{
  "name": "Get Values for a Picklist Field",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{_endpoint}}/services/data/v{{version}}/ui-api/object-info/:SOBJECT_API_NAME/picklist-values/:RECORD_TYPE_ID/:FIELD_API_NAME",
      "host": [
        "{{_endpoint}}"
      ],
      "path": [
        "services",
        "data",
        "v{{version}}",
        "ui-api",
        "object-info",
        ":SOBJECT_API_NAME",
        "picklist-values",
        ":RECORD_TYPE_ID",
        ":FIELD_API_NAME"
      ],
      "variable": [
        {
          "key": "SOBJECT_API_NAME",
          "value": "Account",
          "description": "Object API Name"
        },
        {
          "key": "RECORD_TYPE_ID",
          "value": "012000000000000AAA",
          "description": "Record type Id. Use `012000000000000AAA` as default when there are no custom record types."
        },
        {
          "key": "FIELD_API_NAME",
          "value": "Industry",
          "description": "Field API Name (optional)"
        }
      ]
    },
    "description": "Get metadata about a specific object. The response includes metadata describing fields, child relationships, record type, and theme."
  },
  "response": [
    {
      "name": "Get Values for a Picklist Field",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{_endpoint}}/services/data/v{{version}}/ui-api/object-info/:SOBJECT_API_NAME/picklist-values/:RECORD_TYPE_ID/:FIELD_API_NAME",
          "host": [
            "{{_endpoint}}"
          ],
          "path": [
            "services",
            "data",
            "v{{version}}",
            "ui-api",
            "object-info",
            ":SOBJECT_API_NAME",
            "picklist-values",
            ":RECORD_TYPE_ID",
            ":FIELD_API_NAME"
          ],
          "variable": [
            {
              "key": "SOBJECT_API_NAME",
              "value": "Account",
              "description": "Object API Name"
            },
            {
              "key": "RECORD_TYPE_ID",
              "value": "012000000000000AAA",
              "description": "Record type Id. Use `012000000000000AAA` as default when there are no custom record types."
            },
            {
              "key": "FIELD_API_NAME",
              "value": "Industry",
              "description": "Field API Name"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Tue, 04 May 2021 09:32:34 GMT"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=31536002; includeSubDomains"
        },
        {
          "key": "X-Robots-Tag",
          "value": "none"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache,must-revalidate,max-age=0,no-store,private"
        },
        {
          "key": "ETag",
          "value": "\"bee3e6401e143e18332a17639061c5ff--gzip\""
        },
        {
          "key": "Content-Type",
          "value": "application/json;charset=UTF-8"
        },
        {
          "key": "Vary",
          "value": "Accept-Encoding"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"controllerValues\": {},\n    \"defaultValue\": null,\n    \"eTag\": \"bee3e6401e143e18332a17639061c5ff\",\n    \"url\": \"/services/data/v51.0/ui-api/object-info/Account/picklist-values/012000000000000AAA/Industry\",\n    \"values\": [\n        {\n            \"attributes\": null,\n            \"label\": \"Agriculture\",\n            \"validFor\": [],\n            \"value\": \"Agriculture\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Apparel\",\n            \"validFor\": [],\n            \"value\": \"Apparel\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Banking\",\n            \"validFor\": [],\n            \"value\": \"Banking\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Biotechnology\",\n            \"validFor\": [],\n            \"value\": \"Biotechnology\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Chemicals\",\n            \"validFor\": [],\n            \"value\": \"Chemicals\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Communications\",\n            \"validFor\": [],\n            \"value\": \"Communications\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Construction\",\n            \"validFor\": [],\n            \"value\": \"Construction\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Consulting\",\n            \"validFor\": [],\n            \"value\": \"Consulting\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Education\",\n            \"validFor\": [],\n            \"value\": \"Education\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Electronics\",\n            \"validFor\": [],\n            \"value\": \"Electronics\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Energy\",\n            \"validFor\": [],\n            \"value\": \"Energy\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Engineering\",\n            \"validFor\": [],\n            \"value\": \"Engineering\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Entertainment\",\n            \"validFor\": [],\n            \"value\": \"Entertainment\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Environmental\",\n            \"validFor\": [],\n            \"value\": \"Environmental\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Finance\",\n            \"validFor\": [],\n            \"value\": \"Finance\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Food &amp; Beverage\",\n            \"validFor\": [],\n            \"value\": \"Food &amp; Beverage\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Government\",\n            \"validFor\": [],\n            \"value\": \"Government\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Healthcare\",\n            \"validFor\": [],\n            \"value\": \"Healthcare\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Hospitality\",\n            \"validFor\": [],\n            \"value\": \"Hospitality\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Insurance\",\n            \"validFor\": [],\n            \"value\": \"Insurance\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Machinery\",\n            \"validFor\": [],\n            \"value\": \"Machinery\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Manufacturing\",\n            \"validFor\": [],\n            \"value\": \"Manufacturing\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Media\",\n            \"validFor\": [],\n            \"value\": \"Media\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Not For Profit\",\n            \"validFor\": [],\n            \"value\": \"Not For Profit\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Recreation\",\n            \"validFor\": [],\n            \"value\": \"Recreation\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Retail\",\n            \"validFor\": [],\n            \"value\": \"Retail\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Shipping\",\n            \"validFor\": [],\n            \"value\": \"Shipping\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Technology\",\n            \"validFor\": [],\n            \"value\": \"Technology\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Telecommunications\",\n            \"validFor\": [],\n            \"value\": \"Telecommunications\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Transportation\",\n            \"validFor\": [],\n            \"value\": \"Transportation\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Utilities\",\n            \"validFor\": [],\n            \"value\": \"Utilities\"\n        },\n        {\n            \"attributes\": null,\n            \"label\": \"Other\",\n            \"validFor\": [],\n            \"value\": \"Other\"\n        }\n    ]\n}"
    }
  ]
}