3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Postmanのまとめに戻る

いつもは開発者環境に接続して色々と遊んでいるのですが、違う環境に接続した後に元の開発者環境に接続すると何故かエラーになります。エラーコードは401です。特別に何かを触ったような記憶はない。

[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]

グーグルさんで検索してみると同じ症状の質問/回答があります。

ベストアンサーのリンクを読むと

I actually fixed this after banging my head on it forever. You need to go into the settings tab and turn on the Follow Authorization Header setting.

確かに私の設定ではFollow Authorization headerはoffになっていました。

image.png

ここをonにすると機能します。
しかし、この設定は何だろう?

Retain authorization header when a redirect happens to a different hostname.
別のホスト名へのリダイレクトが発生した場合でも、認証ヘッダーを保持します

リダイレクト? う~ん、そう言えばコンソールを見ていると不思議なことに302のリダイレクトが発生していますね。

image.png

変数の_endpoint に 

https://brave-koala-c0o5lf-dev-ed.trailblaze.lightning.force.com 

を設定していますが、以下にリダイレクトされています。

https://brave-koala-c0o5lf-dev-ed.trailblaze.my.salesforce.com

試しに先程のFollow Authorization headerをoffにして_endpointにリダイレクト先を設定すると問題なく機能します。やはりリダイレクトが問題だったようです。

私の認識ではlightning.force.com は変わらないだったのですが....

image.png

追記;上記のURLとは別に以下の設定があるみたいです。

image.png

インスタンスURLをみたらmy.salesforce.comになっていますね。こっちを_endpointにセットしたほうがよさそう。

image.png

そういえば、先程の記事の別の回答にもあったな。

I'm here in 2021 and for me the solution was not 'Follow Authorization Header', but the access token had a different instance_url than expected. Use this instance_url value in _endpoint and you are fine.

追記

見落としていました...

In the _endpoint row, CURRENT VALUE column, paste the instance_url value that you copied in step 9.

Quick Start: Connect Postman to Salesforce

INVALID_SESSION_ID

The INVALID_SESSION_ID error when using Postman on Salesforce Platform API can occur due to various reasons, including session expiration, IP restrictions, or incorrect session handling. Here are some potential solutions to address this issue:

  1. Refresh the OAuth Access Token: The OAuth access token might have expired, causing the session to become invalid. Try refreshing the access token using the refresh token obtained during the initial authentication process.

  2. Verify IP Restrictions: Salesforce might have restrictions on IPs that can access the API. If you're using a different IP address than when you initially authenticated, you might need to add your IP to the allowed list in Salesforce security settings.

  3. Check Session Handling: Ensure that Postman is handling the session correctly. This might involve setting the appropriate headers and maintaining the session ID throughout your API calls.

  4. Use a Different API Endpoint: Try using a different API endpoint that doesn't involve redirects. Redirects can sometimes interfere with Postman's session handling.

  5. Clear Postman Cache: Sometimes, cached data in Postman can interfere with API calls. Try clearing Postman's cache and cookies to eliminate any potential conflicts.

  6. Validate Connected App Settings: Double-check the settings of your connected app in Salesforce. Make sure the app has the necessary permissions to access the API endpoints you're using.

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?