Chilkat Online Tools

Swift / Salesforce Platform APIs / User Info

Back to Collection Items

func chilkatTest() {
    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    let http = CkoHttp()
    var success: Bool

    http.SetRequestHeader("Content-Type", value: "application/json")

    let sbResponseBody = CkoStringBuilder()
    success = http.QuickGetSb("https://login.salesforce.com{{site}}/services/oauth2/userinfo", sbContent: sbResponseBody)
    if success == false {
        print("\(http.LastErrorText)")
        return
    }

    let jResp = CkoJsonObject()
    jResp.LoadSb(sbResponseBody)
    jResp.EmitCompact = false

    print("Response Body:")
    print("\(jResp.Emit())")

    var respStatusCode: Int = http.LastStatus.intValue
    print("Response Status Code = \(respStatusCode)")
    if respStatusCode >= 400 {
        print("Response Header:")
        print("\(http.LastHeader)")
        print("Failed.")
        return
    }

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

    // {
    //   "sub": "https://login.salesforce.com/id/00D.../005...",
    //   "user_id": "005...",
    //   "organization_id": "00D...",
    //   "preferred_username": "<username>",
    //   "nickname": "<nickname>",
    //   "name": "<name>",
    //   "email": "<email>",
    //   "email_verified": true,
    //   "given_name": "<name>",
    //   "family_name": "<name>",
    //   "zoneinfo": "Europe/Paris",
    //   "photos": {
    //     "picture": "https://<file_domain>/profilephoto/005/F",
    //     "thumbnail": "https://<file_domain>/profilephoto/005/T"
    //   },
    //   "profile": "https://<my_domain>/005",
    //   "picture": "https://<file_domain>/profilephoto/005/F",
    //   "address": {
    //     "country": "FR"
    //   },
    //   "is_salesforce_integration_user": false,
    //   "urls": {
    //     "enterprise": "https://<my_domain>/services/Soap/c/{version}/00D...",
    //     "metadata": "https://<my_domain>/services/Soap/m/{version}/00D...",
    //     "partner": "https://<my_domain>/services/Soap/u/{version}/00D...",
    //     "rest": "https://<my_domain>/services/data/v{version}/",
    //     "sobjects": "https://<my_domain>/services/data/v{version}/sobjects/",
    //     "search": "https://<my_domain>/services/data/v{version}/search/",
    //     "query": "https://<my_domain>/services/data/v{version}/query/",
    //     "recent": "https://<my_domain>/services/data/v{version}/recent/",
    //     "tooling_soap": "https://<my_domain>/services/Soap/T/{version}/00D...",
    //     "tooling_rest": "https://<my_domain>/services/data/v{version}/tooling/",
    //     "profile": "https://<my_domain>/0052o00000DOJ1PAAX",
    //     "feeds": "https://<my_domain>/services/data/v{version}/chatter/feeds",
    //     "groups": "https://<my_domain>/services/data/v{version}/chatter/groups",
    //     "users": "https://<my_domain>/services/data/v{version}/chatter/users",
    //     "feed_items": "https://<my_domain>/services/data/v{version}/chatter/feed-items",
    //     "feed_elements": "https://<my_domain>/services/data/v{version}/chatter/feed-elements",
    //     "custom_domain": "https://<my_domain>"
    //   },
    //   "active": true,
    //   "user_type": "STANDARD",
    //   "language": "en_US",
    //   "locale": "fr_FR_EURO",
    //   "utcOffset": 3600000,
    //   "updated_at": "<datetime>",
    //   "is_app_installed": true
    // }

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

    var v_sub: String? = jResp.StringOf("sub")
    var user_id: String? = jResp.StringOf("user_id")
    var organization_id: String? = jResp.StringOf("organization_id")
    var preferred_username: String? = jResp.StringOf("preferred_username")
    var nickname: String? = jResp.StringOf("nickname")
    var name: String? = jResp.StringOf("name")
    var email: String? = jResp.StringOf("email")
    var email_verified: Bool = jResp.BoolOf("email_verified")
    var given_name: String? = jResp.StringOf("given_name")
    var family_name: String? = jResp.StringOf("family_name")
    var zoneinfo: String? = jResp.StringOf("zoneinfo")
    var Picture: String? = jResp.StringOf("photos.picture")
    var Thumbnail: String? = jResp.StringOf("photos.thumbnail")
    var profile: String? = jResp.StringOf("profile")
    var picture: String? = jResp.StringOf("picture")
    var Country: String? = jResp.StringOf("address.country")
    var is_salesforce_integration_user: Bool = jResp.BoolOf("is_salesforce_integration_user")
    var Enterprise: String? = jResp.StringOf("urls.enterprise")
    var Metadata: String? = jResp.StringOf("urls.metadata")
    var Partner: String? = jResp.StringOf("urls.partner")
    var v_Rest: String? = jResp.StringOf("urls.rest")
    var Sobjects: String? = jResp.StringOf("urls.sobjects")
    var Search: String? = jResp.StringOf("urls.search")
    var Query: String? = jResp.StringOf("urls.query")
    var Recent: String? = jResp.StringOf("urls.recent")
    var Tooling_soap: String? = jResp.StringOf("urls.tooling_soap")
    var Tooling_rest: String? = jResp.StringOf("urls.tooling_rest")
    var Profile: String? = jResp.StringOf("urls.profile")
    var Feeds: String? = jResp.StringOf("urls.feeds")
    var Groups: String? = jResp.StringOf("urls.groups")
    var Users: String? = jResp.StringOf("urls.users")
    var Feed_items: String? = jResp.StringOf("urls.feed_items")
    var Feed_elements: String? = jResp.StringOf("urls.feed_elements")
    var Custom_domain: String? = jResp.StringOf("urls.custom_domain")
    var active: Bool = jResp.BoolOf("active")
    var user_type: String? = jResp.StringOf("user_type")
    var language: String? = jResp.StringOf("language")
    var locale: String? = jResp.StringOf("locale")
    var utcOffset: Int = jResp.IntOf("utcOffset").intValue
    var updated_at: String? = jResp.StringOf("updated_at")
    var is_app_installed: Bool = jResp.BoolOf("is_app_installed")

}

Curl Command

curl -X GET
	-H "Content-Type: application/json"
https://login.salesforce.com{{site}}/services/oauth2/userinfo

Postman Collection Item JSON

{
  "name": "User Info",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{url}}{{site}}/services/oauth2/userinfo",
      "host": [
        "{{url}}{{site}}"
      ],
      "path": [
        "services",
        "oauth2",
        "userinfo"
      ]
    }
  },
  "response": [
    {
      "name": "Successful User Info",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{url}}{{site}}/services/oauth2/userinfo",
          "host": [
            "{{url}}{{site}}"
          ],
          "path": [
            "services",
            "oauth2",
            "userinfo"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Date",
          "value": "Thu, 16 Nov 2023 15:35:50 GMT"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=63072000; includeSubDomains"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "X-Robots-Tag",
          "value": "none"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache,must-revalidate,max-age=0,no-store,private"
        },
        {
          "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    \"sub\": \"https://login.salesforce.com/id/00D.../005...\",\n    \"user_id\": \"005...\",\n    \"organization_id\": \"00D...\",\n    \"preferred_username\": \"<username>\",\n    \"nickname\": \"<nickname>\",\n    \"name\": \"<name>\",\n    \"email\": \"<email>\",\n    \"email_verified\": true,\n    \"given_name\": \"<name>\",\n    \"family_name\": \"<name>\",\n    \"zoneinfo\": \"Europe/Paris\",\n    \"photos\": {\n        \"picture\": \"https://<file_domain>/profilephoto/005/F\",\n        \"thumbnail\": \"https://<file_domain>/profilephoto/005/T\"\n    },\n    \"profile\": \"https://<my_domain>/005\",\n    \"picture\": \"https://<file_domain>/profilephoto/005/F\",\n    \"address\": {\n        \"country\": \"FR\"\n    },\n    \"is_salesforce_integration_user\": false,\n    \"urls\": {\n        \"enterprise\": \"https://<my_domain>/services/Soap/c/{version}/00D...\",\n        \"metadata\": \"https://<my_domain>/services/Soap/m/{version}/00D...\",\n        \"partner\": \"https://<my_domain>/services/Soap/u/{version}/00D...\",\n        \"rest\": \"https://<my_domain>/services/data/v{version}/\",\n        \"sobjects\": \"https://<my_domain>/services/data/v{version}/sobjects/\",\n        \"search\": \"https://<my_domain>/services/data/v{version}/search/\",\n        \"query\": \"https://<my_domain>/services/data/v{version}/query/\",\n        \"recent\": \"https://<my_domain>/services/data/v{version}/recent/\",\n        \"tooling_soap\": \"https://<my_domain>/services/Soap/T/{version}/00D...\",\n        \"tooling_rest\": \"https://<my_domain>/services/data/v{version}/tooling/\",\n        \"profile\": \"https://<my_domain>/0052o00000DOJ1PAAX\",\n        \"feeds\": \"https://<my_domain>/services/data/v{version}/chatter/feeds\",\n        \"groups\": \"https://<my_domain>/services/data/v{version}/chatter/groups\",\n        \"users\": \"https://<my_domain>/services/data/v{version}/chatter/users\",\n        \"feed_items\": \"https://<my_domain>/services/data/v{version}/chatter/feed-items\",\n        \"feed_elements\": \"https://<my_domain>/services/data/v{version}/chatter/feed-elements\",\n        \"custom_domain\": \"https://<my_domain>\"\n    },\n    \"active\": true,\n    \"user_type\": \"STANDARD\",\n    \"language\": \"en_US\",\n    \"locale\": \"fr_FR_EURO\",\n    \"utcOffset\": 3600000,\n    \"updated_at\": \"<datetime>\",\n    \"is_app_installed\": true\n}"
    }
  ]
}