【Salesforce】UNSUPPORTED_MEDIA_TYPE
SalesforceのREST APIを利用して、自分で作成した処理にPOSTを投げました。
その際に返ってきたJSONです。
{
"errorCode":"UNSUPPORTED_MEDIA_TYPE",
"message":"Content-Type header specified in HTTP request is not supported: application/x-www-form-urlencoded"
}
エラーが発生していますね。
内容を見ると分かるように、サポートされていないContent-Typeということです。
HTTPRequestの内容はこんな感じです。
見て分かるように、HTTPヘッダで「Content-Type」を指定していませんね。
req = new HttpRequest();
req.setMethod('POST');
req.setEndpoint('{EndPoint}');
req.setHeader('Authorization', 'OAuth {Access Token}');
req.setBody('{JSON}');
Http http = new Http();
HTTPResponse res = http.send(req);
実際に送信したかったのはJSON文字列なのですが、「Content-Type」を指定していませんでした。
ちゃんと指定してあげないといけませんね。
req = new HttpRequest();
req.setMethod('POST');
req.setEndpoint('{EndPoint}');
req.setHeader('Authorization', 'OAuth {Access Token}');
req.setHeader('Content-Type', 'application/json');
req.setBody('{JSON}');
Http http = new Http();
HTTPResponse res = http.send(req);
サポートされているのはJSONとXMLですね。
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_rest_resources.htm
頭の中にパーサーが欲しいです。
No comments.