<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Just Another Dang Blog</title>
	<atom:link href="https://www.lopau.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.lopau.com/</link>
	<description>Just another tech blog about Swift, Mulesoft, Salesforce, DevOps and web development</description>
	<lastBuildDate>Mon, 01 Sep 2025 01:53:16 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>
<site xmlns="com-wordpress:feed-additions:1">194620713</site>	<item>
		<title>How to Use the Salesforce DX MCP Server in VS Code</title>
		<link>https://www.lopau.com/how-to-use-the-salesforce-dx-mcp-server-in-vs-code/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-use-the-salesforce-dx-mcp-server-in-vs-code</link>
					<comments>https://www.lopau.com/how-to-use-the-salesforce-dx-mcp-server-in-vs-code/#respond</comments>
		
		<dc:creator><![CDATA[lopau]]></dc:creator>
		<pubDate>Mon, 01 Sep 2025 01:49:37 +0000</pubDate>
				<category><![CDATA[Salesforce]]></category>
		<guid isPermaLink="false">https://www.lopau.com/?p=4643</guid>

					<description><![CDATA[<p>If you’re a Salesforce developer exploring AI workflows, you’ve probably tried tools like GitHub Copilot, Claude, or Cursor. These AI agents are powerful, but they often lack context about your project. That’s where the Salesforce DX MCP Server comes in. In this guide, I’ll show you how to install and use the Salesforce DX MCP Server inside&#160;Visual Studio&#8230; <a class="more-link" href="https://www.lopau.com/how-to-use-the-salesforce-dx-mcp-server-in-vs-code/">Read More <span class="screen-reader-text">How to Use the Salesforce DX MCP Server in VS Code</span></a></p>
<p>The post <a href="https://www.lopau.com/how-to-use-the-salesforce-dx-mcp-server-in-vs-code/">How to Use the Salesforce DX MCP Server in VS Code</a> appeared first on <a href="https://www.lopau.com">Just Another Dang Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>If you’re a Salesforce developer exploring AI workflows, you’ve probably tried tools like <a href="https://www.lopau.com/how-to-use-github-copilot-with-swift-using-vscode/">GitHub Copilot</a>, Claude, or Cursor. These AI agents are powerful, but they often lack <strong>context about your project</strong>. That’s where the <strong>Salesforce DX MCP Server</strong> comes in.</p>



<p>In this guide, I’ll show you how to install and use the Salesforce DX MCP Server inside&nbsp;<strong>Visual Studio Code (VS Code)</strong>so you can give AI agents direct access to your Salesforce orgs.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">What is MCP?</h2>



<p>The&nbsp;<strong>Model Context Protocol (MCP)</strong>&nbsp;is an open-source project from Anthropic. It standardizes how applications provide&nbsp;<strong>context</strong>&nbsp;to large language models (LLMs).</p>



<p>Instead of your AI assistant “guessing” what’s in your Salesforce project, MCP gives it structured tools to securely access real project data.</p>



<p>With MCP, AI agents can:</p>



<ul class="wp-block-list">
<li>Query your Salesforce orgs</li>



<li>Deploy and retrieve metadata</li>



<li>Run unit tests</li>



<li>Assign permission sets</li>



<li>And much more</li>
</ul>



<p>This makes your AI assistant smarter, more accurate, and actually useful in your Salesforce workflow.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Installing MCP in VS Code</h2>



<p>There are two easy ways to install MCP in&nbsp;<strong>Visual Studio Code</strong>:</p>



<ol class="wp-block-list">
<li>Visit the official&nbsp;<a href="https://code.visualstudio.com/mcp?utm_source=chatgpt.com">MCP download page</a></li>



<li>Or install it directly inside the editor via the Command Palette</li>
</ol>



<p>MCP servers can run&nbsp;<strong>locally or remotely</strong>. In this tutorial, we’ll keep it simple and run the Salesforce DX MCP Server&nbsp;<strong>locally</strong> &#8211; source code available from github at <a href="https://github.com/salesforcecli/mcp">https://github.com/salesforcecli/mcp</a></p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Salesforce DX MCP Server Overview</h2>



<p>The&nbsp;<strong>Salesforce DX MCP Server</strong>&nbsp;is a specialized MCP implementation designed for Salesforce developers.</p>



<ul class="wp-block-list">
<li>It uses the same&nbsp;<strong>OAuth flow</strong>&nbsp;as the Salesforce CLI (SFDX), so setup is seamless if you already work with SFDX.</li>



<li>It’s currently available in&nbsp;<strong>beta</strong>, with new tools rolling out frequently.</li>
</ul>



<h3 class="wp-block-heading">Current Toolset (Beta)</h3>



<p>Here are the MCP commands you can try today:</p>



<ul class="wp-block-list">
<li><strong>Core</strong>:&nbsp;<code>sf-get-username</code></li>



<li><strong>Orgs</strong>:&nbsp;<code>sf-list-all-orgs</code></li>



<li><strong>Data</strong>:&nbsp;<code>sf-query-org</code></li>



<li><strong>Users</strong>:&nbsp;<code>sf-assign-permission-set</code></li>



<li><strong>Metadata</strong>:&nbsp;<code>sf-deploy-metadata</code>,&nbsp;<code>sf-retrieve-metadata</code></li>



<li><strong>Testing</strong>:&nbsp;<code>sf-testing-agents</code>,&nbsp;<code>sf-test-apex</code></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Step-by-Step Setup in VS Code</h2>



<p>Here’s how to get started with the Salesforce DX MCP Server:</p>



<p>Code snippet from Salesforce official Github repo &#8211; check for more information <a href="https://github.com/salesforcecli/mcp">https://github.com/salesforcecli/mcp</a></p>



<pre class="wp-block-code"><code>{
  "servers": {
    "Salesforce DX": {
      "type": "stdio",
      "command": "npx",
      "args": &#91;"-y", "@salesforce/mcp", "--orgs", "DEFAULT_TARGET_ORG", "--toolsets", "all"]
    }
  }
}</code></pre>



<ol class="wp-block-list">
<li><strong>Open VS Code</strong></li>



<li><strong>Create a new Salesforce DX (SFDX) project</strong></li>



<li>Authenticate your org</li>



<li>Then a<strong>dd the MCP Server</strong></li>



<li>Open the&nbsp;<strong>Command Palette</strong>&nbsp;(<code>CMD+Shift+P</code>&nbsp;on Mac or&nbsp;<code>CTRL+Shift+P</code>&nbsp;on Windows)</li>



<li>Use the MCP setup wizard or create a&nbsp;<code>mcp.json</code>&nbsp;file inside your&nbsp;<code>.vscode</code>&nbsp;folder</li>



<li>Paste the code above, save and hit Start on the context menu</li>



<li>If you’re on&nbsp;<strong>GitHub Copilot Enterprise</strong>, confirm with your admin that MCP is enabled (some enterprise setups restrict it)</li>



<li>Once running, open the AI chat and try commands like:
<ul class="wp-block-list">
<li>“How many users are admins?”</li>



<li>“How many orgs are authenticated?”</li>



<li>“Retrieve all Apex classes from this org”</li>



<li>“Run all unit tests”</li>
</ul>
</li>
</ol>



<p>That’s it — your AI assistant now has&nbsp;<strong>real Salesforce context</strong>.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Why Salesforce DX MCP Matters</h2>



<p>The Salesforce DX MCP Server makes it possible to combine&nbsp;<strong>Salesforce development</strong>&nbsp;with&nbsp;<strong>AI-powered productivity</strong>. Instead of manually checking metadata, running queries, or handling org management, you can let AI agents perform these tasks securely with full project awareness.</p>



<p>This is still early days — the toolset is in beta — but it’s clear that MCP will play a huge role in the future of&nbsp;<strong>Salesforce AI development</strong>.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Conclusion</h2>



<p>The&nbsp;<strong>Salesforce DX MCP Server</strong>&nbsp;is a game-changer for developers looking to bring AI into their Salesforce workflow. By running it in VS Code, you can give AI assistants direct, secure access to your org and metadata, making them far more useful than before.</p>



<p>For a full walkthrough, check out my video tutorial here:&nbsp;</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<div class="jetpack-video-wrapper"><iframe title="How to Get Started Using the Latest Salesforce DX MCP Server" width="900" height="506" src="https://www.youtube.com/embed/ixJtXAYCTi4?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
</div></figure>



<p>If you have a specific use case for MCP that you’d like me to try, drop a comment — I’ll be covering more advanced setups soon.</p>
<p>The post <a href="https://www.lopau.com/how-to-use-the-salesforce-dx-mcp-server-in-vs-code/">How to Use the Salesforce DX MCP Server in VS Code</a> appeared first on <a href="https://www.lopau.com">Just Another Dang Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lopau.com/how-to-use-the-salesforce-dx-mcp-server-in-vs-code/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4643</post-id>	</item>
		<item>
		<title>Getting Started with Salesforce Agentforce: What I Learned</title>
		<link>https://www.lopau.com/getting-started-with-salesforce-agentforce-what-i-learned/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=getting-started-with-salesforce-agentforce-what-i-learned</link>
					<comments>https://www.lopau.com/getting-started-with-salesforce-agentforce-what-i-learned/#respond</comments>
		
		<dc:creator><![CDATA[lopau]]></dc:creator>
		<pubDate>Fri, 01 Aug 2025 04:00:51 +0000</pubDate>
				<category><![CDATA[Salesforce]]></category>
		<guid isPermaLink="false">https://www.lopau.com/?p=4630</guid>

					<description><![CDATA[<p>When Salesforce introduced&#160;Agentforce&#160;in September 2024 at Dreamforce, it marked a pivotal shift from traditional “copilots” to&#160;autonomous AI agents&#160;embedded across its ecosystem (Salesforce Developers. Since then, Salesforce Help alone has seen Agentforce handle over&#160;1 million support requests, freeing up human teams to focus on more complex issues (Salesforce). What Is Agentforce? At its core, Agentforce is&#8230; <a class="more-link" href="https://www.lopau.com/getting-started-with-salesforce-agentforce-what-i-learned/">Read More <span class="screen-reader-text">Getting Started with Salesforce Agentforce: What I Learned</span></a></p>
<p>The post <a href="https://www.lopau.com/getting-started-with-salesforce-agentforce-what-i-learned/">Getting Started with Salesforce Agentforce: What I Learned</a> appeared first on <a href="https://www.lopau.com">Just Another Dang Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p>When Salesforce introduced&nbsp;<strong>Agentforce</strong>&nbsp;in September 2024 at Dreamforce, it marked a pivotal shift from traditional “copilots” to&nbsp;<strong>autonomous AI agents</strong>&nbsp;embedded across its ecosystem (<a href="https://developer.salesforce.com/blogs/2025/05/write-better-agent-instructions-with-agentforce-ai-assist?utm_source=chatgpt.com">Salesforce Developers</a>. Since then, Salesforce Help alone has seen Agentforce handle over&nbsp;<strong>1 million support requests</strong>, freeing up human teams to focus on more complex issues (<a href="https://www.salesforce.com/blog/support-requests-agentforce/?utm_source=chatgpt.com">Salesforce</a>).</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">What Is Agentforce?</h2>



<p>At its core, Agentforce is Salesforce’s next-generation AI platform that enables the creation of&nbsp;<strong>autonomous agents </strong>capable of understanding intent, planning multi-step tasks, and executing actions—either independently or with light human oversight.</p>



<p>This isn’t just another chatbot—it’s a tool that reasons and connects with your Salesforce data (via Data?Cloud), workflows, and external systems to drive real outcomes.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Key Capabilities — Simplified</h2>



<h3 class="wp-block-heading">1.&nbsp;<strong>Autonomous Agents</strong></h3>



<p>Agents can drive tasks like lead qualification, case triaging, email drafting, or meeting scheduling—with or without human prompts.</p>



<h3 class="wp-block-heading">2. <strong>Low code Agent Builder</strong></h3>



<p>You don’t need to code to start. Use out-of-the-box templates, customize topics and actions, or connect flows, Apex or external services to empower your agent.</p>



<h3 class="wp-block-heading">3.&nbsp;<strong>Integrated with Salesforce Ecosystem</strong></h3>



<p>Agentforce works across Sales Cloud, Service Cloud, Marketing Cloud, Slack, MuleSoft, and connects to Data Cloud for rich, contextual data access and reasoning.</p>



<h3 class="wp-block-heading">4.&nbsp;<strong>Secure &amp; Trustworthy</strong></h3>



<p>Powered by Salesforce’s&nbsp;<strong>Einstein Trust Layer</strong>, agents operate within existing security models and don’t store sensitive data—they act carefully and compliantly.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Real Results at Scale</h2>



<p>On Salesforce.com, Agentforce has powered&nbsp;<strong>100K+ conversations</strong>, influenced roughly&nbsp;<strong>30K sales leads</strong>, and is now surfacing relevant conversion prompts during chats — guiding users to demos or trials at the right moments.</p>



<p>Internally, on Salesforce Help, the AI resolved routine support cases—over one million of them—allowing customer support engineers to focus on complex issues and strategic customer engagement.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Tips for Building Your First Agent</h2>



<p>Salesforce’s customer success teams recommend:</p>



<p><strong>Tip 1: Start with customer pain points</strong>, not AI features. Define the tedious or repetitive questions users ask, then build agents to address those.</p>



<p><strong>Tip 2: Build using topics, actions &amp; instructions.</strong>&nbsp;These drive agent behavior, guiding how it reasons and what tasks it performs.</p>



<p>Use&nbsp;<strong>AI Assist</strong>&nbsp;in the Agent Builder to help craft clearer instructions and topic definitions—especially helpful if outputs feel off or inconsistent.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">My Step-by-Step Starter Approach</h2>



<h3 class="wp-block-heading"><strong>Pre?requisite: Assign Agentforce Permission Sets to Admins</strong></h3>



<p>Before you enable Agentforce, make sure the System Administrator (or any user managing agents) has the necessary permission set licenses and permission sets:</p>



<ul class="wp-block-list">
<li>Assign the&nbsp;<strong>Einstein Agent</strong>&nbsp;license to the admin user, which is required to allow assignment of Agentforce permission sets.</li>



<li>In Setup > <strong>Permission Sets</strong>, assign the <strong>“Agentforce Default Admin”</strong> permission set and the <strong>“Prompt Template User”</strong> permission set to the admin or agent-building user.</li>
</ul>



<ol class="wp-block-list">
<li><strong>Enable Agentforce</strong>&nbsp;in Setup (Enable Einstein and Agentforce toggles) (<a href="https://developer.salesforce.com/agentforce-workshop/agents/1-get-started?utm_source=chatgpt.com">Salesforce Developers</a>)</li>



<li>Open Agent Builder and create a starter topic (e.g., “Lead Qualification”) and attach actions like drafting emails or querying records (<a href="https://developer.salesforce.com/agentforce-workshop/agents/1-get-started?utm_source=chatgpt.com">Salesforce Developers</a>)</li>



<li>Use AI Assist to refine instructions</li>



<li>Test your agent in the conversation preview or via sidebar interaction in Salesforce</li>



<li>Launch and monitor – check analytics and fine-tune topics or triggers over time</li>
</ol>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Final Thoughts</h2>



<p>Getting started with Agentforce can feel intimidating, but its low-code interface, integrated reasoning engine, and secure design make it accessible for admins, sales teams, and businesses alike.</p>



<p>It’s not just another chatbot—it’s a smarter way to automate routine workflows, scale your team’s bandwidth, and deliver faster, more intelligent experiences.</p>



<p></p>
<p>The post <a href="https://www.lopau.com/getting-started-with-salesforce-agentforce-what-i-learned/">Getting Started with Salesforce Agentforce: What I Learned</a> appeared first on <a href="https://www.lopau.com">Just Another Dang Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lopau.com/getting-started-with-salesforce-agentforce-what-i-learned/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4630</post-id>	</item>
		<item>
		<title>How to Fix Salesforce Bulk API Error &#8211; ClientInputError : LineEnding is invalid on user data. Current LineEnding setting is LF</title>
		<link>https://www.lopau.com/how-to-fix-salesforce-bulk-api-error-clientinputerror-lineending-is-invalid-on-user-data-current-lineending-setting-is-lf/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-fix-salesforce-bulk-api-error-clientinputerror-lineending-is-invalid-on-user-data-current-lineending-setting-is-lf</link>
					<comments>https://www.lopau.com/how-to-fix-salesforce-bulk-api-error-clientinputerror-lineending-is-invalid-on-user-data-current-lineending-setting-is-lf/#respond</comments>
		
		<dc:creator><![CDATA[lopau]]></dc:creator>
		<pubDate>Tue, 15 Jul 2025 03:36:38 +0000</pubDate>
				<category><![CDATA[Salesforce]]></category>
		<guid isPermaLink="false">https://www.lopau.com/?p=4617</guid>

					<description><![CDATA[<p>When using Salesforce Bulk API using the sf CLI or through REST, you might get this error when uploading a csv file. This is usually caused by line-ending format on the raw csv file. On my Mac machine this should be LF and CRLF on Windows. To fix this you can use a text editor&#8230; <a class="more-link" href="https://www.lopau.com/how-to-fix-salesforce-bulk-api-error-clientinputerror-lineending-is-invalid-on-user-data-current-lineending-setting-is-lf/">Read More <span class="screen-reader-text">How to Fix Salesforce Bulk API Error &#8211; ClientInputError : LineEnding is invalid on user data. Current LineEnding setting is LF</span></a></p>
<p>The post <a href="https://www.lopau.com/how-to-fix-salesforce-bulk-api-error-clientinputerror-lineending-is-invalid-on-user-data-current-lineending-setting-is-lf/">How to Fix Salesforce Bulk API Error &#8211; ClientInputError : LineEnding is invalid on user data. Current LineEnding setting is LF</a> appeared first on <a href="https://www.lopau.com">Just Another Dang Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>When using Salesforce Bulk API using the sf CLI or through REST, you might get this error when uploading a csv file.</p>



<figure class="wp-block-image size-large"><img data-recalc-dims="1" fetchpriority="high" decoding="async" width="900" height="87" src="https://i0.wp.com/www.lopau.com/wp-content/uploads/2025/07/How-to-Fix-Salesforce-Bulk-API-Error-1024x99.png?resize=900%2C87&#038;ssl=1" alt="" class="wp-image-4618" srcset="https://i0.wp.com/www.lopau.com/wp-content/uploads/2025/07/How-to-Fix-Salesforce-Bulk-API-Error.png?resize=1024%2C99&amp;ssl=1 1024w, https://i0.wp.com/www.lopau.com/wp-content/uploads/2025/07/How-to-Fix-Salesforce-Bulk-API-Error.png?resize=300%2C29&amp;ssl=1 300w, https://i0.wp.com/www.lopau.com/wp-content/uploads/2025/07/How-to-Fix-Salesforce-Bulk-API-Error.png?resize=768%2C74&amp;ssl=1 768w, https://i0.wp.com/www.lopau.com/wp-content/uploads/2025/07/How-to-Fix-Salesforce-Bulk-API-Error.png?resize=1536%2C149&amp;ssl=1 1536w, https://i0.wp.com/www.lopau.com/wp-content/uploads/2025/07/How-to-Fix-Salesforce-Bulk-API-Error.png?resize=1000%2C97&amp;ssl=1 1000w, https://i0.wp.com/www.lopau.com/wp-content/uploads/2025/07/How-to-Fix-Salesforce-Bulk-API-Error.png?w=2003&amp;ssl=1 2003w, https://i0.wp.com/www.lopau.com/wp-content/uploads/2025/07/How-to-Fix-Salesforce-Bulk-API-Error.png?w=1800&amp;ssl=1 1800w" sizes="(max-width: 900px) 100vw, 900px" /></figure>



<p>This is usually caused by line-ending format on the raw csv file. On my Mac machine this should be LF and CRLF on Windows. To fix this you can use a text editor tool like VS Code or Sublime Text.</p>



<p>VS Code, open the .csv file and open the Command Pallete menu (Command+Shift+P keys for Mac), search for &#8220;Change End of Line Sequence&#8221; and set it to LF or CRLF for windows and save. That&#8217;s it, when uploaded to Salesforce it should detect the right line-ending.</p>



<p>If your using sf data tree, upload your file from the cli.</p>



<pre class="wp-block-code"><code>sf data upsert bulk --sobject Supply_Service__c --file con-update.csv --external-id GT_Consumer_Number__c</code></pre>
<p>The post <a href="https://www.lopau.com/how-to-fix-salesforce-bulk-api-error-clientinputerror-lineending-is-invalid-on-user-data-current-lineending-setting-is-lf/">How to Fix Salesforce Bulk API Error &#8211; ClientInputError : LineEnding is invalid on user data. Current LineEnding setting is LF</a> appeared first on <a href="https://www.lopau.com">Just Another Dang Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lopau.com/how-to-fix-salesforce-bulk-api-error-clientinputerror-lineending-is-invalid-on-user-data-current-lineending-setting-is-lf/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4617</post-id>	</item>
		<item>
		<title>How to Integrate Google APIs with a Next.js App (OAuth 2.0 Guide)</title>
		<link>https://www.lopau.com/how-to-integrate-google-apis-with-a-next-js-app-oauth-2-0-guide/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-integrate-google-apis-with-a-next-js-app-oauth-2-0-guide</link>
					<comments>https://www.lopau.com/how-to-integrate-google-apis-with-a-next-js-app-oauth-2-0-guide/#respond</comments>
		
		<dc:creator><![CDATA[lopau]]></dc:creator>
		<pubDate>Sun, 06 Oct 2024 20:40:18 +0000</pubDate>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[NextJS]]></category>
		<category><![CDATA[Web Development]]></category>
		<guid isPermaLink="false">https://www.lopau.com/?p=4595</guid>

					<description><![CDATA[<p>In this post, we’ll dive into integrating Google APIs with a Next.js app. We’ll walk through how to: Ready? Let’s get started! Step 1: Set Up Google Cloud Console Head over to&#160;console.cloud.google.com.Create a&#160;New Project.Under&#160;API &#38; Services: Next,&#160;Create Credentials: Step 2: Install Dependencies Step 3: Set Up Your .env File These values are required to authenticate users via&#8230; <a class="more-link" href="https://www.lopau.com/how-to-integrate-google-apis-with-a-next-js-app-oauth-2-0-guide/">Read More <span class="screen-reader-text">How to Integrate Google APIs with a Next.js App (OAuth 2.0 Guide)</span></a></p>
<p>The post <a href="https://www.lopau.com/how-to-integrate-google-apis-with-a-next-js-app-oauth-2-0-guide/">How to Integrate Google APIs with a Next.js App (OAuth 2.0 Guide)</a> appeared first on <a href="https://www.lopau.com">Just Another Dang Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In this post, we’ll dive into integrating Google APIs with a Next.js app. We’ll walk through how to:</p>



<ul class="wp-block-list">
<li>Use the official Google API client library for authentication and API calls.</li>



<li>Understand OAuth 2.0 authentication.</li>



<li>Set up Google Cloud Console for API access, credentials, and OAuth consent.</li>



<li>Build a Next.js app from login to authorization using cookies.</li>



<li>Finally, we’ll make a Google Drive API call to list the first 10 documents in your Google Drive.</li>
</ul>



<p>Ready? Let’s get started!</p>



<h2 class="wp-block-heading">Step 1: Set Up Google Cloud Console</h2>



<p>Head over to&nbsp;<a href="https://console.cloud.google.com/">console.cloud.google.com</a>.Create a&nbsp;<strong>New Project</strong>.Under&nbsp;<strong>API &amp; Services</strong>:</p>



<ul class="wp-block-list">
<li>Click on <strong>Enable APIs and Services</strong>.</li>



<li>Enable the <strong>Google Drive API</strong>.</li>
</ul>



<p>Next,&nbsp;<strong>Create Credentials</strong>:</p>



<ul class="wp-block-list">
<li>Select <strong>User Data</strong> as the type.</li>



<li>Choose <strong>OAuth Client ID</strong>.</li>



<li>Set <strong>Web Application</strong> as the app type.</li>



<li>In <strong>Authorized JavaScript Origins</strong>, add:
<ul class="wp-block-list">
<li><code>http://localhost:3000</code></li>



<li><code>http://localhost</code></li>
</ul>
</li>



<li>For <strong>Authorized Redirect URIs</strong>, add:
<ul class="wp-block-list">
<li><code>http://localhost:3000</code></li>



<li><code>http://localhost:3000/api/oauth2/callback</code></li>
</ul>
</li>
</ul>



<h2 class="wp-block-heading">Step 2: Install Dependencies</h2>



<pre class="wp-block-code"><code>npm install googleapis
npx shadcn@latest init -d
npx shadcn@latest add button</code></pre>



<h2 class="wp-block-heading">Step 3: Set Up Your <code>.env</code> File</h2>



<pre class="wp-block-code"><code>GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-client-secret
GOOGLE_REDIRECT_URI=http://localhost:3000/api/oauth2/callback
</code></pre>



<p>These values are required to authenticate users via Google OAuth.</p>



<h2 class="wp-block-heading">Step 4: Building the OAuth2 Flow</h2>



<p><strong>Create a global <code>oauth2client</code> utility</strong> that’s accessible throughout your app:</p>



<pre class="wp-block-code"><code>import { google } from 'googleapis';
const oauth2Client = new google.auth.OAuth2(
  process.env.GOOGLE_CLIENT_ID,
  process.env.GOOGLE_CLIENT_SECRET,
  process.env.GOOGLE_REDIRECT_URI
);</code></pre>



<p>Create a login button on your Page.tsx and get the authorizationURL by passing the access_type and scope</p>



<p>/app/Page.tsx</p>



<pre class="wp-block-code"><code>import { Button } from "@/components/ui/button";
import oauth2Client from "./utils/google-auth";
import Link from "next/link";

export default function Home() {
  const SCOPE = &#91;"https://www.googleapis.com/auth/drive.metadata.readonly"];

  const authorizationURL = oauth2Client.generateAuthUrl({
    access_type: "offline",
    scope: SCOPE,
  });

  return (
    &lt;div className="grid grid-rows-&#91;20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20 font-&#91;family-name:var(--font-geist-sans)]">
      &lt;Link href={authorizationURL}>
        &lt;Button>Login To Google&lt;/Button>
      &lt;/Link>
    &lt;/div>
  );
}
</code></pre>



<h2 class="wp-block-heading">Step 5: Handle the Callback</h2>



<p>Next, let’s handle that callback and exchange the authorization code for an access token.</p>



<ul class="wp-block-list">
<li><strong>Create the API route</strong> for your OAuth2 callback: /app/api/oauth2/callback/route.ts</li>



<li><strong>Save the access token in a cookie</strong> so it can be used for subsequent API calls.</li>



<li>Redirect to the dashboard </li>
</ul>



<pre class="wp-block-code"><code>import { NextResponse } from 'next/server';
import { cookies } from 'next/headers';
import oauth2Client from '@/app/utils/google-auth';

export async function GET(req: Request) {
    const { searchParams } = new URL(req.url);
    const code = searchParams.get('code');
    const error = searchParams.get('error');

    if (error) {
        return NextResponse.json({ error: 'Google OAuth Error: ' + error });
      }
    
    if (!code) {
        return NextResponse.json({ error: 'Authorization code not found' });
    }

    try {
        const { tokens } = await oauth2Client.getToken(code);
        cookies().set({
            name: 'google_access_token',
            value: tokens.access_token || '',  // the access token
            httpOnly: true,  // for security, the cookie is accessible only by the server
            secure: process.env.NODE_ENV === 'production',  // send cookie over HTTPS only in production
            path: '/',  // cookie is available on every route
            maxAge: 60 * 60 * 24 * 7,  // 1 week
        });

        return NextResponse.redirect(new URL("/dashboard", req.url));
    } catch (error) {

        return NextResponse.json({ error: 'Google OAuth Error failed to exchange code: ' + error });
    }
}</code></pre>



<h2 class="wp-block-heading">Step 6: Call Google APIs (Google Drive Example)</h2>



<p>Now that the user is authenticated, we can use the OAuth2 client to make API calls. For example, let’s fetch the first 10 documents from Google Drive:</p>



<ul class="wp-block-list">
<li><strong>Call the Google Drive API</strong>: /app/dashboard/Page.tsx</li>
</ul>



<pre class="wp-block-code"><code>import oauth2Client from "../utils/google-auth";
import { cookies } from "next/headers";
import { google } from "googleapis";

export default async function Page() {
  const cookieStore = cookies();
  const accessToken = cookieStore.get("google_access_token")?.value;
  oauth2Client.setCredentials({ access_token: accessToken });
  let files;

  const drive = google.drive("v3");

  try {
    const result = await drive.files.list({
      auth: oauth2Client,
      pageSize: 10,
      fields: "nextPageToken, files(id, name)",
    });
    files = result.data.files;
  } catch (error) {
    console.log(error);
    return (
      &lt;div className="justify-center w-full flex text-center pt-10 flex-col items-center">
        Something went wrong! Please login again!
      &lt;/div>
    );
  }

  return (
    &lt;div className="justify-center w-full flex text-center pt-10 flex-col items-center">
      &lt;h1 className="text-lg font-bold">Google Drive Files&lt;/h1>
      &lt;ul>
        {files?.map((file) => (
          &lt;li key={file.id}>{file.name}&lt;/li>
        ))}
      &lt;/ul>
    &lt;/div>
  );
}</code></pre>



<p>This code lists the first 10 files in your Google Drive, provided the OAuth2 client has valid credentials.</p>



<h2 class="wp-block-heading">Conclusion</h2>



<p>To wrap it up, here’s what we covered:</p>



<ol class="wp-block-list">
<li><strong>Setting up a Google Cloud project</strong> and enabling the Drive API.</li>



<li><strong>Implementing OAuth2</strong> in your Next.js app, including the login flow and handling callbacks.</li>



<li><strong>Storing the access token in cookies</strong> to maintain the session.</li>



<li><strong>Calling Google APIs</strong>, like Google Drive, using the authenticated OAuth2 client.</li>
</ol>



<p>Now you have a fully functional app that integrates with Google APIs, allowing you to explore other Google services in a similar fashion. Enjoy building!</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<div class="jetpack-video-wrapper"><iframe title="How To Integrate with Google APIs from a Nextjs App Backend" width="900" height="506" src="https://www.youtube.com/embed/j8sfDvFjPMQ?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
</div></figure>
<p>The post <a href="https://www.lopau.com/how-to-integrate-google-apis-with-a-next-js-app-oauth-2-0-guide/">How to Integrate Google APIs with a Next.js App (OAuth 2.0 Guide)</a> appeared first on <a href="https://www.lopau.com">Just Another Dang Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lopau.com/how-to-integrate-google-apis-with-a-next-js-app-oauth-2-0-guide/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4595</post-id>	</item>
		<item>
		<title>How to Integrate Salesforce with a Next.js App Using jsforce</title>
		<link>https://www.lopau.com/how-to-integrate-salesforce-with-a-next-js-app-using-jsforce/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-integrate-salesforce-with-a-next-js-app-using-jsforce</link>
					<comments>https://www.lopau.com/how-to-integrate-salesforce-with-a-next-js-app-using-jsforce/#comments</comments>
		
		<dc:creator><![CDATA[lopau]]></dc:creator>
		<pubDate>Thu, 26 Sep 2024 23:59:23 +0000</pubDate>
				<category><![CDATA[Salesforce]]></category>
		<guid isPermaLink="false">https://www.lopau.com/?p=4590</guid>

					<description><![CDATA[<p>In this post, we’re going to walk through the process of integrating Salesforce with a Next.js application using the jsforce library. This is especially useful if you need to access Salesforce data from a Next.js app, whether for displaying information or for backend operations. What is jsforce? jsforce (formerly known as Node-Salesforce) is a powerful&#8230; <a class="more-link" href="https://www.lopau.com/how-to-integrate-salesforce-with-a-next-js-app-using-jsforce/">Read More <span class="screen-reader-text">How to Integrate Salesforce with a Next.js App Using jsforce</span></a></p>
<p>The post <a href="https://www.lopau.com/how-to-integrate-salesforce-with-a-next-js-app-using-jsforce/">How to Integrate Salesforce with a Next.js App Using jsforce</a> appeared first on <a href="https://www.lopau.com">Just Another Dang Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In this post, we’re going to walk through the process of integrating Salesforce with a Next.js application using the <code>jsforce</code> library. This is especially useful if you need to access Salesforce data from a Next.js app, whether for displaying information or for backend operations.</p>



<h3 class="wp-block-heading">What is jsforce?</h3>



<p><code>jsforce</code> (formerly known as Node-Salesforce) is a powerful JavaScript library that allows you to interact with Salesforce&#8217;s API. It works both in the browser and with Node.js, making it versatile for various scenarios. When combined with Next.js, a full-stack React framework, you can create a seamless integration between Salesforce and your app’s frontend or backend.</p>



<p>In this tutorial, we’ll cover:</p>



<ol class="wp-block-list">
<li><strong>Building a Basic Next.js App to Fetch Salesforce Accounts</strong>: We’ll retrieve a list of accounts from your Salesforce organization using the Salesforce REST API.</li>



<li><strong>Exploring jsforce Authentication</strong>: We&#8217;ll walk through different authentication methods, from basic to more secure OAuth2 flows, and troubleshoot common issues.</li>
</ol>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h3 class="wp-block-heading">Step 1: Setting Up a Basic Next.js App</h3>



<p>First, let&#8217;s create a simple Next.js app to get the accounts from your Salesforce organization. We&#8217;ll be using the <code>jsforce</code> library to handle the API communication. Here&#8217;s how to get started:</p>



<ol class="wp-block-list">
<li>Initialize a Next.js project: 
<ul class="wp-block-list">
<li><code>npx create-next-app@latest salesforce-nextjs </code></li>



<li><code>cd salesforce-nextjs </code></li>



<li><code>npm install jsforce</code></li>
</ul>
</li>



<li>create a new file called .env.local on the root project</li>



<li>Create different pages and api routes to show different methods how Next.js connects to Salesforce using <code>jsforce</code> and retrieves the account data.</li>
</ol>



<pre class="wp-block-code"><code>//.env.local sample file
USERNAME=
PASSWORD=
CLIENT_ID=
CLIENT_SECRET=
REDIRECT_URI=

//sample pages
app/username-password/page.tsx
app/username-password-flow/page.tsx
app/webserver-flow/page.tsx
app/dashboard/page.tsx

//sample api routes
api/oauth2/auth/route.ts
api/oauth2/callback/route.ts

</code></pre>



<h3 class="wp-block-heading">Step 2: Understanding jsforce Authentication Methods</h3>



<p>There are multiple ways to authenticate with Salesforce using jsforce, ranging from less secure to more secure approaches:</p>



<h4 class="wp-block-heading"><strong>Username-Password SOAP API Login</strong></h4>



<p>This method is simple but less secure. It involves providing your Salesforce username and password along with a security token to authenticate. While useful for quick testing, it is not recommended for production use.</p>



<pre class="wp-block-code"><code>import jsforce from "jsforce";

export default async function Page() {
  const conn = new jsforce.Connection({
    // you can change loginUrl to connect to sandbox or prerelease env.
    // loginUrl : 'https://test.salesforce.com'
  });

  await conn.login(process.env.USERNAME!, process.env.PASSWORD!);

  const result = await conn.query("SELECT Id, Name FROM Account LIMIT 15");

  return (
    &lt;div&gt;
      Username Password Page
      &lt;ul className="list-disc list-inside"&gt;
        {result.records.map((record) =&gt; (
          &lt;li key={record.Id}&gt;{record.Name}&lt;/li&gt;
        ))}
      &lt;/ul&gt;
    &lt;/div&gt;
  );
}
</code></pre>



<h4 class="wp-block-heading"><strong>OAuth2 Authentication</strong></h4>



<p>For production applications, OAuth2 is the more secure and preferred way to authenticate. It provides various flows based on your specific use case.</p>



<ol class="wp-block-list">
<li><strong>OAuth2 Username-Password Flow</strong>: This flow allows you to log in using the user’s Salesforce credentials, but it is less secure because it requires storing the username and password.</li>



<li><strong>OAuth2 Web Server Flow</strong>: This is a more secure option where you redirect the user to Salesforce to log in. Once authenticated, Salesforce redirects the user back to your app with a session token, which you can use to access the API.</li>
</ol>



<pre class="wp-block-code"><code>//username-password flow/page.tsx
import jsforce from "jsforce";

export default async function Page() {
  const conn = new jsforce.Connection({
    oauth2: {
      // you can change loginUrl to connect to sandbox or prerelease env.
      // loginUrl : 'https://test.salesforce.com',
      clientId: process.env.CLIENT_ID,
      clientSecret: process.env.CLIENT_SECRET,
      redirectUri: process.env.REDIRECT_URI,
    },
  });

  await conn.login(process.env.USERNAME!, process.env.PASSWORD!);

  const result = await conn.query("SELECT Id, Name FROM Account LIMIT 15");

  return (
    &lt;div>
      Username Password Page
      &lt;ul className="list-disc list-inside">
        {result.records.map((record) => (
          &lt;li key={record.Id}>{record.Name}&lt;/li>
        ))}
      &lt;/ul>
    &lt;/div>
  );
}

//webserver-flow/page.tsx
"use client";
import React from "react";

export default function Page() {
  const handleLogin = () => {
    window.location.href = "/api/oauth2/auth";
  };
  return (
    &lt;div>
      &lt;button onClick={handleLogin}>Login to Salesforce&lt;/button>
    &lt;/div>
  );
}

//api/oauth2/auth/route.ts
import { OAuth2 } from 'jsforce';
import { NextResponse } from 'next/server';

const oauth2 = new OAuth2({
    // you can change loginUrl to connect to sandbox or prerelease env.
    // loginUrl : 'https://test.salesforce.com',
    clientId: process.env.CLIENT_ID,
      clientSecret: process.env.CLIENT_SECRET,
      redirectUri: process.env.REDIRECT_URI,
  });

  export async function GET() {
    const authUrl = oauth2.getAuthorizationUrl({scope: 'api id web'})

    return NextResponse.redirect(authUrl);
  }


</code></pre>



<ul class="wp-block-list">
<li>You need to create a &#8220;Connected App&#8221; in Salesforce to set up this flow.</li>



<li>Once the user is authenticated, save the session ID in a cookie. Your app can then read this session ID from the cookie and use it to make API requests to Salesforce.</li>
</ul>



<h3 class="wp-block-heading">Step 3: Setting Up a Connected App in Salesforce</h3>



<ol class="wp-block-list">
<li>Log in to Salesforce.</li>



<li>Go to <strong>Setup</strong> and search for &#8220;App Manager.&#8221;</li>



<li>Click <strong>New Connected App</strong> and fill in the required fields, such as callback URL, OAuth scopes, etc.</li>



<li>Ensure you enable OAuth settings and specify the correct callback URL (e.g., <code>https://yourapp.com/api/callback</code>).</li>
</ol>



<h3 class="wp-block-heading">Handling OAuth2 Web Server Flow in Next.js</h3>



<p>Here’s how to handle the callback from Salesforce and manage session cookies in Next.js:</p>



<pre class="wp-block-code"><code>//app/api/oauth2/callback/route.ts
import {OAuth2, Connection} from 'jsforce';
import { NextResponse } from 'next/server';
import { cookies } from 'next/headers';

const oauth2 = new OAuth2({
    clientId: process.env.CLIENT_ID,
    clientSecret: process.env.CLIENT_SECRET,
    redirectUri: process.env.REDIRECT_URI,
  });

  export async function GET(req: Request) {
    const { searchParams } = new URL(req.url);
    const code = searchParams.get('code');
    const error = searchParams.get('error');

    if (error) {
      return NextResponse.json({ error: 'Salesforce Oauth Error:' + error});
    }

    if (!code) {
      return NextResponse.json({ error: 'No Authorization code found'});
    }

    try {
        const conn = new Connection({ oauth2 });
        

        await conn.authorize(code);

        // Set the access token in an HTTP-only, secure cookie
        cookies().set({
        name: 'salesforce_access_token',
        value: conn.accessToken || '',  // the access token
        httpOnly: true,  // for security, the cookie is accessible only by the server
        secure: process.env.NODE_ENV === 'production',  // send cookie over HTTPS only in production
        path: '/',  // cookie is available on every route
        maxAge: 60 * 60 * 24 * 7,  // 1 week
     });
      
          // Optionally, you can store the instance URL in a cookie if needed
          cookies().set({
              name: 'salesforce_instance_url',
              value: conn.instanceUrl || '',
              httpOnly: true,
              secure: process.env.NODE_ENV === 'production',
              path: '/',
              maxAge: 60 * 60 * 24 * 7,  // 1 week
          });

        return NextResponse.redirect(new URL('/dashboard', req.url));
    } catch(err) {
        return NextResponse.json({ error: 'Salesforce Oauth Error:' + err});
    }
  }

//app/dashboard/page.tsx
import jsforce from "jsforce";
import { cookies } from "next/headers";

export default async function page() {
  const cookieStore = cookies();
  const accessToken = cookieStore.get("salesforce_access_token")?.value;
  const instanceUrl = cookieStore.get("salesforce_instance_url")?.value;
  let result;
  try {
    const conn = new jsforce.Connection({
      instanceUrl: instanceUrl,
      accessToken: accessToken,
    });

    result = await conn.query("SELECT Id, Name FROM Account LIMIT 15");
  } catch (err) {
    console.log(err);
    return &lt;div>Failed to fetch data from Salesforce&lt;/div>;
  }
  return (
    &lt;div>
      Web server flow
      &lt;ul className="list-disc list-inside">
        {result.records.map((record) => (
          &lt;li key={record.Id}>{record.Name}&lt;/li>
        ))}
      &lt;/ul>
    &lt;/div>
  );
}</code></pre>



<p>In this code, after Salesforce authenticates the user, the session token is stored in a cookie for future API calls.</p>



<h3 class="wp-block-heading">Troubleshooting Common Issues</h3>



<p>While integrating Salesforce with a Next.js app, you might run into some common authentication issues:</p>



<ul class="wp-block-list">
<li><strong>Invalid Grant or Authentication Failure</strong>: <code>"error": "Failed to authorize with Salesforce: invalid_grant: authentication failure"</code> Solution: Ensure that your Salesforce security settings (e.g., IP restrictions) are relaxed for testing purposes.</li>



<li><strong>OAuth Approval Error</strong>:<br><code>json "error": "OAUTH_APPROVAL_ERROR_GENERIC"</code><br>Solution: Double-check your OAuth scopes and make sure the app has the correct permissions in Salesforce.</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h3 class="wp-block-heading">Wrapping Up</h3>



<p>Integrating Salesforce with a Next.js app using <code>jsforce</code> can unlock powerful possibilities for accessing and managing Salesforce data in your web applications. While the authentication setup may seem complex at first, the OAuth2 web server flow ensures a secure and scalable integration for real-world applications.</p>



<p>For a deeper dive into Salesforce authentication or if you&#8217;re encountering further issues, check out my previous post on <a href="#">using Salesforce with Postman</a>.</p>



<p>Watch the video</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<div class="jetpack-video-wrapper"><iframe loading="lazy" title="How to Integrate Salesforce with a NextJS app" width="900" height="506" src="https://www.youtube.com/embed/gRqmJTWsJK8?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
</div></figure>



<p>Feel free to leave a comment or reach out if you have any questions. Happy coding!</p>
<p>The post <a href="https://www.lopau.com/how-to-integrate-salesforce-with-a-next-js-app-using-jsforce/">How to Integrate Salesforce with a Next.js App Using jsforce</a> appeared first on <a href="https://www.lopau.com">Just Another Dang Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lopau.com/how-to-integrate-salesforce-with-a-next-js-app-using-jsforce/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4590</post-id>	</item>
		<item>
		<title>Step-by-Step Guide: Integrating Salesforce with Postman Using OAuth 2.0 and Connected Apps</title>
		<link>https://www.lopau.com/step-by-step-guide-integrating-salesforce-with-postman-using-oauth-2-0-and-connected-apps/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=step-by-step-guide-integrating-salesforce-with-postman-using-oauth-2-0-and-connected-apps</link>
					<comments>https://www.lopau.com/step-by-step-guide-integrating-salesforce-with-postman-using-oauth-2-0-and-connected-apps/#respond</comments>
		
		<dc:creator><![CDATA[lopau]]></dc:creator>
		<pubDate>Mon, 16 Sep 2024 08:46:31 +0000</pubDate>
				<category><![CDATA[Salesforce Integration Architecture Designer]]></category>
		<guid isPermaLink="false">https://www.lopau.com/?p=4587</guid>

					<description><![CDATA[<p>How to Use Postman to Integrate with Salesforce Using a Connected App In this blog post, we will walk through how to integrate Salesforce with Postman using a connected app. Salesforce provides a secure way for third-party applications to access its resources through a REST API. To achieve this, you need to authorize the app&#8230; <a class="more-link" href="https://www.lopau.com/step-by-step-guide-integrating-salesforce-with-postman-using-oauth-2-0-and-connected-apps/">Read More <span class="screen-reader-text">Step-by-Step Guide: Integrating Salesforce with Postman Using OAuth 2.0 and Connected Apps</span></a></p>
<p>The post <a href="https://www.lopau.com/step-by-step-guide-integrating-salesforce-with-postman-using-oauth-2-0-and-connected-apps/">Step-by-Step Guide: Integrating Salesforce with Postman Using OAuth 2.0 and Connected Apps</a> appeared first on <a href="https://www.lopau.com">Just Another Dang Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h3 class="wp-block-heading">How to Use Postman to Integrate with Salesforce Using a Connected App</h3>



<p>In this blog post, we will walk through how to integrate Salesforce with Postman using a connected app. Salesforce provides a secure way for third-party applications to access its resources through a REST API. To achieve this, you need to authorize the app using OAuth 2.0 authorization flows. We&#8217;ll cover different flows like Authorization Code with PKCE, Username-Password, Client Credentials, and Web Server Flow, as well as how to troubleshoot some common errors along the way.</p>



<h4 class="wp-block-heading">Prerequisites</h4>



<p>Before we dive into the details, ensure the following:</p>



<ul class="wp-block-list">
<li>You have <a href="https://www.postman.com">Postman</a> installed.</li>



<li>You have access to a Salesforce organization (either a sandbox or developer edition).</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h4 class="wp-block-heading">Overview</h4>



<p>When building a web application that needs to access Salesforce resources, the client app must be authorized to do so securely. This is typically done using OAuth 2.0 and a connected app. Here’s how the general flow works:</p>



<ol class="wp-block-list">
<li><strong>Authorization Requirement:</strong> The client application (e.g., your web app) wants to access Salesforce resources like data or services.</li>



<li><strong>Authorization Process:</strong> In order to access these resources, the client needs authorization.</li>



<li><strong>Authentication Server Role:</strong> Salesforce delegates the responsibility of authenticating and authorizing the client to its Authorization Server.</li>



<li><strong>Token Usage:</strong>
<ul class="wp-block-list">
<li>Once successfully authenticated, the client app receives an access token.</li>



<li>The app can use this access token to access Salesforce resources.</li>



<li>Additionally, the client can request a new access token using a refresh token, if needed.</li>
</ul>
</li>
</ol>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h4 class="wp-block-heading">Step-by-Step Guide</h4>



<h5 class="wp-block-heading">1. <strong>Setting Up a Connected App</strong></h5>



<p>To begin, we need to create a connected app in Salesforce. This is essential for any external application to securely integrate with Salesforce using OAuth 2.0. The connected app provides the client ID, secret, and the necessary configuration to authenticate.</p>



<h5 class="wp-block-heading">2. <strong>Using OAuth 2.0 Flows in Postman</strong></h5>



<p>Once the connected app is set up, we will use Postman to try out different OAuth 2.0 authorization flows. These flows provide various ways to authenticate and authorize access. Let’s walk through the key flows:</p>



<ul class="wp-block-list">
<li><strong>Authorization Code Flow</strong><br>This is a standard OAuth 2.0 flow for web apps. It requires user interaction for granting access. In Postman, you’ll exchange an authorization code for an access token.</li>



<li><strong>Authorization Code with PKCE</strong><br>PKCE (Proof Key for Code Exchange) is an extension to OAuth 2.0 that adds an extra layer of security by using a dynamically generated secret. This is often used in public clients (like mobile apps). You’ll need a <strong>callback URL</strong> in Salesforce to complete this flow.</li>



<li><strong>Username-Password Flow</strong><br>This flow is used in scenarios where you trust the client app with the user&#8217;s credentials. It&#8217;s considered less secure and is only recommended for trusted applications.</li>



<li><strong>Client Credentials Flow</strong><br>This flow is ideal for machine-to-machine authentication where there’s no user involvement. It uses only the client ID and secret.</li>



<li><strong>Web Server Flow</strong><br>This flow allows your application to obtain an access token through the back-end server rather than exposing it to the front-end.</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h4 class="wp-block-heading">Troubleshooting Common Errors</h4>



<p>When working with OAuth flows, you may encounter errors. Here’s one common error and how to troubleshoot it:</p>



<pre class="wp-block-code"><code>Error: invalid_grant, Description: request not supported on this domain</code></pre>



<p><strong>Solution:</strong><br>This error typically means that the domain you are using in Postman or Salesforce isn’t correctly set up for OAuth. Ensure the <strong>callback URL</strong> matches what is configured in your Salesforce connected app, and check whether the domain supports OAuth requests.</p>



<p>Watch full breakdown in this video</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<div class="jetpack-video-wrapper"><iframe loading="lazy" title="How To Use Postman To Integrate to Salesforce with a Connected App" width="900" height="506" src="https://www.youtube.com/embed/sb_QrtXJ4P0?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
</div></figure>



<h4 class="wp-block-heading">Conclusion</h4>



<p>Using Postman to integrate with Salesforce can streamline your API development process. With a properly configured connected app and an understanding of different OAuth 2.0 flows, you’ll be able to authenticate and access Salesforce resources securely. Always make sure to use the right flow based on your application’s needs and handle errors gracefully.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p>That’s it for this tutorial! I hope you now have a solid understanding of how to set up and use Postman with Salesforce through a connected app. If you run into any challenges or have more questions, feel free to drop a comment below.</p>
<p>The post <a href="https://www.lopau.com/step-by-step-guide-integrating-salesforce-with-postman-using-oauth-2-0-and-connected-apps/">Step-by-Step Guide: Integrating Salesforce with Postman Using OAuth 2.0 and Connected Apps</a> appeared first on <a href="https://www.lopau.com">Just Another Dang Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lopau.com/step-by-step-guide-integrating-salesforce-with-postman-using-oauth-2-0-and-connected-apps/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4587</post-id>	</item>
		<item>
		<title>How to install the latest @salesforce/cli with node20 using Homebrew.</title>
		<link>https://www.lopau.com/how-to-install-the-latest-salesforce-cli-with-node20-using-homebrew/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-install-the-latest-salesforce-cli-with-node20-using-homebrew</link>
					<comments>https://www.lopau.com/how-to-install-the-latest-salesforce-cli-with-node20-using-homebrew/#respond</comments>
		
		<dc:creator><![CDATA[lopau]]></dc:creator>
		<pubDate>Sun, 21 Jan 2024 22:58:38 +0000</pubDate>
				<category><![CDATA[DevOps]]></category>
		<guid isPermaLink="false">https://www.lopau.com/?p=4576</guid>

					<description><![CDATA[<p>If you are running on a Mac with homebrew and have node installed, the chances are when you try to install the latest @salesforce/cli it would show that installation was successful. However, any commands you run like sf version will throw this annoying warning. Update: This issue seems to have been fixed with node-v21.6.0 and&#8230; <a class="more-link" href="https://www.lopau.com/how-to-install-the-latest-salesforce-cli-with-node20-using-homebrew/">Read More <span class="screen-reader-text">How to install the latest @salesforce/cli with node20 using Homebrew.</span></a></p>
<p>The post <a href="https://www.lopau.com/how-to-install-the-latest-salesforce-cli-with-node20-using-homebrew/">How to install the latest @salesforce/cli with node20 using Homebrew.</a> appeared first on <a href="https://www.lopau.com">Just Another Dang Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>If you are running on a Mac with homebrew and have node installed, the chances are when you try to install the latest @salesforce/cli it would show that installation was successful. However, any commands you run like sf version will throw this annoying warning.</p>



<pre class="wp-block-code"><code>pauloorquillo@Paulos-MBP VersionControl % sf version
(node:34452) &#91;DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
@salesforce/cli/2.24.4 darwin-arm64 node-v21.5.0
</code></pre>



<p>Update: This issue seems to have been fixed with node-v21.6.0 and higher. Make sure you update to the latest node version. If you are still having the issue check the solution below.</p>



<p>You can ignore the warning if you want. But to fix this you would need to downgrade your node version installed via homebrew.  Open up the terminal and do the following commands and reading through my comments.</p>



<pre class="wp-block-code"><code>#uninstall the salesforce cli for a clean install later
npm uninstall @salesforce/cli --global

#list all apps to make sure you have node installed
brew list

#uninstall that version of node
brew uninstall node

#install older version of node
brew install node@20

#update the link in homebrew to look into this latest version
brew link —overwrite node@20 

#check node version
node -v

#finally install the salesforce cli again
npm install @salesforce/cli --global

#check that no warnings are thrown by running this command
sf version</code></pre>



<p>There you go, hope you like this tip and found it useful.</p>
<p>The post <a href="https://www.lopau.com/how-to-install-the-latest-salesforce-cli-with-node20-using-homebrew/">How to install the latest @salesforce/cli with node20 using Homebrew.</a> appeared first on <a href="https://www.lopau.com">Just Another Dang Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lopau.com/how-to-install-the-latest-salesforce-cli-with-node20-using-homebrew/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4576</post-id>	</item>
	</channel>
</rss>
