---
schema_version: "1"
id: 7e502be7ca286f7c96dd6a45366911768fbb5edfc654aecde477f58f7d7b7187
title: Use the Named Credential in a Callout
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/security/named-credentials/guides/nc-use-oauth-cred-in-callout.md
canonical_url: https://developer.salesforce.com/docs/platform/named-credentials/guide/nc-use-oauth-cred-in-callout.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 4a866f7e1f6fc362f83e85f22f74022570d6befc13ee9549acf317dcae22d4d2
products:
  - Named Credentials
  - Security
---
# Use the Named Credential in a Callout

With the credential defined, you can use it in a callout without managing authentication details in your code.

## Example: Making a Callout with a Named Principal

Often, the external system provides the same functionality to all users. Here, we make a callout that converts a small bit of text to Markdown. This call doesn’t return different results for different users in the org.

```apex
HTTP h = new http();
HTTPRequest hr = new HTTPRequest();
hr.setEndpoint('callout:githubAPI/markdown');
hr.setMethod('POST');
hr.setBody('{"text":"Hello **world**"}');
```

## Example: Making a Per-User Callout

When the external credential is configured with a per-user identity type, callouts automatically incorporate the context of the current user and pass their access token in the appropriate header. Here, the callout returns a list of GitHub Gists for the current user. Note that there’s no explicit handling of user context because that happens automatically.

```apex
HTTP h = new http();
HTTPRequest hr = new HTTPRequest();
hr.setEndpoint('callout:githubAPI/gists');
hr.setMethod('GET');
hr.setHeader('Accept', 'application/vnd.github+json');
```
