You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在SAP CPI中通过简易HTTP适配器实现先GET取Token再POST JSON到S4HANA

Alright, let's walk through how to pull this off in SAP CPI using the Simple HTTP Adapter—getting that auth token via GET, then reusing it for your JSON POST to S/4HANA. Here's the step-by-step breakdown:

Step 1: Set up the GET Request to Fetch Your Auth Token

First, add a Simple HTTP Receiver Adapter to your iFlow to call the token endpoint:

  • In the Connection tab:
    • Plug in your token service URL (e.g., https://your-s4hana-domain.com/oauth2/token)
    • Set the HTTP method to GET
    • Configure authentication matching what your token service requires (most often Basic Auth, so enter the client ID and secret here)
  • In the Processing tab:
    • Ensure the response handling is set to accept JSON (since token responses are almost always JSON-formatted)
Step 2: Extract and Store the Token in CPI Exchange Properties

Right after the GET request, add a Content Modifier to pull the token out of the response and save it for later use:

  • Switch to the Message Properties tab:
    • Create a new property (name it something like authToken for clarity)
    • For the value, use JSONPath to target the token field in the response. If your token comes back as {"access_token": "your-token-here"}, use $.access_token
    • Set the scope to Exchange—this makes the token accessible across all steps in your iFlow
Step 3: Configure the POST Request to S/4HANA with the Token

Now add a second Simple HTTP Receiver Adapter for your S/4HANA service call:

  • In the Connection tab:
    • Enter your S/4HANA service endpoint (e.g., https://your-s4hana-domain.com/sap/opu/odata/sap/API_MATERIAL_SRV/A_Material)
    • Set the HTTP method to POST
    • Skip the adapter-level authentication here—we'll use the token we fetched instead
  • In the Processing tab:
    • Set the Request Body format to JSON (this ensures your payload is sent as JSON instead of XML)
    • Head to the Headers section:
      • Add a new header named Authorization
      • Set its value to Bearer ${property.authToken}—this injects the stored token into the header using CPI's property placeholder syntax
Pro Tips to Avoid Headaches
  • Test your token GET request first in Postman or curl to confirm it returns a valid JSON response with the expected token field (usually access_token). This saves you troubleshooting time in CPI later.
  • If your token has an expiration, add a Cache component to store the token temporarily. This avoids hitting the token service on every iFlow run, which is more efficient and avoids rate limits.
  • Double-check that your POST JSON payload matches the schema expected by your S/4HANA service. You can either pass the incoming JSON directly (if it's already correct) or use a Message Mapping to convert it if needed.
  • Use the CPI Message Monitor to debug: check the message logs to verify the token was extracted correctly and that the Authorization header is present in the POST request.

内容的提问来源于stack exchange,提问作者Codrin Strîmbei

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:04:20