Search code examples
salesforcedataweavemulesoftanypoint-studiomule4

Unable to fetch payload.access_token value after hitting salesforce using http connector. how to extract access_token value?


I am hitting salesforce which is giving me application/x-www-form-urlencoded JSON which looks like this

{"access_token":"00D5j0008yLhA!ARwAQBufl2Y6S1Tu3AU5zUWBCb442Nj2JqwWFOkm3AFL16CQZleLO.mnZwlDFttOMEnldbt_WqJBzhLrh1mgI1XEIvAN8sAM","instance_url":"https://cloudceitude-13a-dev-ed.my.salesforce.com","id":"https://login.salesforce.com/id/00D5j00000LhAEAU/0055j000004TZbAAAW","token_type":"Bearer","issued_at":"1668188564383","signature":"LQbWIODP8pqE+wD1yjgbVUBxMDI6YV1HjENZUeK/eoY="}

but when I am trying to access value of access_token using payload.access_token it is giving me error

enter image description here

I have tried by transforming into JSON using Transform connector using

%dw 2.0
output application/json
​---
payload

still after I tried to access my token it shows same error

enter image description here

and also while debugging map function is not working while working on Payload in DataWeave but instead when I use MapObject It reflect this:

key=%7B%22access_token%22%3A%2200D5j000008yLhA%21ARwAQIN5UGZWtk8Ucu8MUNgbnHAKleeqAk2M73Afy9iRKNEKRppu4C7Drfi0hg8q5t8C.PYX7RsMMXQPsjxmpVB1Ev_pU.2p%22%2C%22instance_url%22%3A%22https%3A%2F%2Fcloudcertitude-13a-dev-ed.my.salesforce.com%22%2C%22id%22%3A%22https%3A%2F%2Flogin.salesforce.com%2Fid%2F00D5j000008yLhAEAU%2F0055j000004TZbAAAW%22%2C%22token_type%22%3A%22Bearer%22%2C%22issued_at%22%3A%221668330168420%22%2C%22signature%22%3A%22kkDnnUe9pZfiqiuEjRi02az0lwpAlmwmv3cMRmF9nRU

Solution

  • I'll make an educated guess that the application or the server are somehow forcing the media type of the response to be application/x-www-form-urlencoded when it really is a JSON. The request for a token should be application/x-www-form-urlencoded, the response should be a JSON (application/json). If the server is returning it you should check with the administrators of that server. However if the application is overriding the content type of the response you should fix it.