简体   繁体   English

如何从外部 Web 表单调用 Salesforce REST API

[英]How to call Salesforce REST API from external web forms

I am a bit confused.我有点困惑。 The requirement is that we need to create a REST API in Salesforce(Apex class) that has one POST method.要求是我们需要在具有一个 POST 方法的 Salesforce(Apex 类)中创建一个 REST API。 Right now, I have been testing it with POSTMAN tool in 2 steps:现在,我一直在用 POSTMAN 工具分两步测试它:

  1. Making a POST request first with username, password, client_id, client_secret(that are coming from connected app in Salesforce), grant_type to receive access token.首先使用用户名、密码、client_id、client_secret(来自 Salesforce 中连接的应用程序)、grant_type 发出 POST 请求以接收访问令牌。
  2. Then I make another POST request in POSTMAN to create a lead in Salesforce, using the access token I received before and the body.然后我在 POSTMAN 中发出另一个 POST 请求以在 Salesforce 中创建一个潜在客户,使用我之前收到的访问令牌和正文。

However, the REST API that I have in Salesforce would be called from various different web forms.但是,我在 Salesforce 中拥有的 REST API 会从各种不同的 Web 表单中调用。 So once someone fills out the webform, on the backend it would call this REST API in Salesforce and submits lead request.因此,一旦有人填写了网络表单,它就会在后端调用 Salesforce 中的这个 REST API 并提交潜在客户请求。

I am wondering how would that happen since we can't use POSTMAN for that.我想知道这会如何发生,因为我们不能为此使用 POSTMAN。

Thanks谢谢

These "various different web forms" would have to send requests to Salesforce just like Postman does.这些“各种不同的 Web 表单”必须像 Postman 一样向 Salesforce 发送请求。 You'd need two POST calls (one for login, one to call the service you've created).您需要两次 POST 调用(一次用于登录,一次用于调用您创建的服务)。 It'll be bit out of your control, you provided the SF code and proven it works, now it's for these website developers to pick it up.它有点不受您的控制,您提供了 SF 代码并证明它有效,现在这些网站开发人员可以选择它。

What's exactly your question?你的问题是什么? There are tons of libraries to connect to SF from Java, Python, .NET, PHP... Or they could hand-craft these HTTP messages, just Google for "PHP HTTP POST" or something...有大量的库可以从 Java、Python、.NET、PHP 连接到 SF……或者他们可以手工制作这些 HTTP 消息,只需谷歌搜索“PHP HTTP POST”或其他东西……

Depending how much time they'll have they can:根据他们有多少时间,他们可以:

  • cache the session id (so they don't call login every time), try to reuse it, call login again only if session id is blank / got "session expired or invalid" error back缓存会话 ID(因此他们不会每次都调用登录),尝试重用它,仅当会话 ID 为空/返回“会话过期或无效”错误时才再次调用登录
  • try to batch it somehow (do they need to save these Leads to SF asap or in say hourly intervals is OK? How did YOU write the service, accepts 1 lead or list of records?尝试以某种方式对其进行批处理(他们是否需要尽快将这些潜在客户保存到 SF 或以每小时一次的间隔保存?您是如何编写服务的,接受 1 个潜在客户或记录列表?
  • be smart about storing the credentials to SF (some secure way, not hardcoded).聪明地将凭证存储到 SF(一些安全的方式,而不是硬编码)。 Ideally in a way that it's easy to use the integration against sandbox or production changing just 1 config file or environment variables or something like that理想情况下,很容易使用针对沙箱或生产的集成,只需更改 1 个配置文件或环境变量或类似的东西

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM