简体   繁体   中英

Having a problem getting a salesforce access token. I've got a post man call that works fun, but it's not working in code

Having a problem getting a salesforce access token. Getting the access token works fine in postman, but what I'm trying to do it in C# i'm getting an error.

I've tried to doing the equivlent to what I was doing in postman but I'm not sure if getting this right.

var client = new HttpClient();
string baseAddress = @"https://test.salesforce.com/services/oauth2/token";

string grant_type = "authorization_code";
string client_id = "client_id here";
string client_secret = "client_secret here";
string auth_url = "https://test.salesforce.com/services/oauth2/authorize";
string callback_url = "https://app.getpostman.com/oauth2/callback";
string redirect_uri = "https://app.getpostman.com/oauth2/callback";

var form = new Dictionary<string, string>
{
    {"grant_type", grant_type},
    {"client_id", client_id},
    {"client_secret", client_secret},
    {"auth_url", auth_url},
    {"callback_url", callback_url},
    {"redirect_uri", redirect_uri}
};

HttpResponseMessage tokenResponse =  client.PostAsync(baseAddress, new FormUrlEncodedContent(form)).GetAwaiter().GetResult();
var jsonContent =  tokenResponse.Content.ReadAsStringAsync().GetAwaiter().GetResult();

This is the error I'm getting:

{ "error": "invalid_grant", "error_description":"invalid authorization code" }

The authorization code grant type (flow) in oAuth is a 2-step process:

  1. Obtain authorization code (endpoint in Salesforce: /services/oauth2/authorize )
  2. Exchange authorization code for access token (endpoint in Salesforce: /services/oauth2/token )

You seem to be doing step 2 without step 1. If you did perform step 1, you would have the authorization code...which must be included in step 2 as code parameter.

See Salesforce docs for examples and more details

You missed this additional paramerter called code

{ "grant_type", grant_type }, { "Code", authorizationcode }, { "client_id", client_id }, { "client_secret", client_secret }, { "auth_url", auth_url }, { "callback_url", callback_url }, { "redirect_uri", redirect_uri }

Display Items with value in a List passed as JSON to an Azure Logic App Ask Question Asked 11 months ago Active 11 months ago Viewed 195 times 0 I have some code that collects information off of a page. The use on the page can select items from a dropdown and add them as requirements. Let's say someone needs a notebook, some pencils and maybe some chairs (the idea is the list of items they can add is generated dynamically from another service so the list can be expanded/contracted so I do not know what the list might contain or how long it is). I save this inside a List where the object has an ItemName (string) and an ItemQuantity (int) property. public class IndividualItem { public string ItemName { get; set; } public int ItemQuantity { get; set; } public IndividualItem() { } public IndividualItem(string itemName, int itemQuantity) { ItemName = itemName; ItemQuantity = itemQuantity; } } This gets parsed to JSON and sent to an Azure Logic App and an email needs to be sent using this information. The JSON that arrives in the logic app looks like this: Item Requirements: [ {"ItemName":"Pencil","ItemQuantity":13}, {"ItemName":"Xacto Knife","ItemQuantity":10}, {"ItemName":"Colored Pencils","ItemQuantity":44} ] Now the problem comes when adding this information into an email. In an Azure Logic App I know I can access the information passed in dynamically. So I can access the 'To' field for example to populate where the email is supposed to go. I can access 'Subject' and 'Footer' or whatever other section I need. However, when accessing my 'MeetingItems' list and add it in, the text displays the square brackets and so on (the actual JSON string). My question is, how could I clean the contents of the string list to remove this and add custom formatting. So transform the list that looks like above [{""....}] into maybe an unordered list with each item one underneath another: Pencil: 13 Xacto Knife: 10 ... An example of the complete JSON string that is sent is below. This needs to populate a Send Email action and I know I can access the fields through the dynamic naming convention (so From in one field or whatever). But doing the same and calling ItemList will leave the [{...}] formatting in the text. I know you can do a For Each to access individual items, but then how do you tie this to the Send email action? And if you nest the send email action, you will obviously call that once for each item in the list. { "From": "NO REPLY", "To": "target@email.com", "CC": "cc@email.com", "Subject": "Email Subject", "EmailBody": { "Introduction": "This email has been issued to inform you of an order", "OrderDetails": { "OrderName": "Refill", "OrderDate": "24/09/2020, 09:00", "ExpectedDeliveryDate": "29/09/2020, 09:00", "Location": "Address", "ConfirmationRequired": "Yes", "ShippingDetails": "Yes", "ItemList": [ { "ItemName": "Pencil", "ItemQuantity": 13 }, { "ItemName": "Xacto Knife", "ItemQuantity": 10 }, { "ItemName": "Colored Pencils", "ItemQuantity": 44 } ] }, "Footer": "Please email sender for additional details" } } ----> I have a "partial" solution by editing the input into the list to hold a formatted string that gets passed on. However, I would like to keep this open to see if there is another way besides hardcoding a string that I send across. { "From": "NO REPLY", "To": "target@email.com", "CC": "cc@email.com", "Subject": "Email Subject", "EmailBody": { "Introduction": "This email has been issued to inform you of an order", "OrderDetails": { "OrderName": "Refill", "OrderDate": "24/09/2020, 09:00", "ExpectedDeliveryDate": "29/09/2020, 09:00", "Location": "Address", "ConfirmationRequired": "Yes", "ShippingDetails": "Yes", "ItemList": "<ul><li><b>Pencil</b> - 13</li><li><b>Xacto Knife</b> - 10</li><li><b>Colored Pencils</b> - 44</li></ul>" }, "Footer": "Please email sender for additional details" } } c# azure azure-logic-apps Share Improve this question Follow edited Sep 15 '20 at 11:59 pSYoniK asked Sep 15 '20 at 8:14 pSYoniKpSYoniK 3111 silver badge1010 bronze badges 3 Is the Item Requirements: [{"ItemName":"Pencil"... you have mentioned above is the complete json string or is snippet of the json string? – Satya V Sep 15 '20 at 11:23 @sathya_vijayakumar-MSFT --- I just edited my post and provided more information for clarity. The issue is with the ItemList property. I have circumvented the issue at the moment, by overriding ToString and creating a formatted string that I send across, so that's solved(ish) but I am still curious if there is a better way. – pSYoniK Sep 15 '20 at 12:00 Thanks for including more information in the question. I've went forward and answered question. Hope it helps. – Satya V Sep 15 '20 at 13:05 Add a comment  |  1 Answer 1 Active Oldest Votes 0 I assume that you are doing a PARSE JSON operation to convert the above string back to JSON. I understand that once it has been parse, you are still with the ItemList is left with the below format : Now, to achieve your requirement to include as list in the email you can create HTML Table with this ItemList output obtained from the from the Parse JSON step. Below is the Output : If you don't want the headers, you choose the custom in the column section Create HTML Table step. Choose the values. You can include the output of the HTML table to the body of the email. Mail Output : Share Improve this answer Follow answered Sep 15 '20 at 13:01 Satya VSatya V 2,98811 gold badge33 silver badges77 bronze badges 1 Thank you for that. The table heading seems off compared to where the body of the result gets placed on my end, but I think that should be straightforward. – pSYoniK Sep 15 '20 at 13:54 Add a comment  |  Your Answer Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question. Provide details and share your research! But avoid … Asking for help, clarification, or responding to other answers. Making statements based on opinion; back them up with references or personal experience. To learn more, see our tips on writing great answers. Draft saved Draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Submit Post as a guest Name Email Required, but never shown Post as a guest Name Email Required, but never shown Post Your Answer Discard By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy Not the answer you're looking for? Browse other questions tagged c# azure azure-logic-apps or ask your own question. The Overflow Blog The full data set for the 2021 Developer Survey now available! Podcast 371: Exploring the magic of instant python refactoring with Sourcery Featured on Meta Review queue workflows - Final release Please welcome Valued Associates: #958 - V2Blast & #959 - SpencerG Related 513 How to use LINQ to select object with minimum or maximum property value 7 Parsing JSON in Azure Logic App 1 Unwanted string with Json inserted from Azure Queue for Logic App 0 Azure logic app with Condition 1 Azure Logic App List Blob what is List_Blob metadata field value 0 Azure Logic App output structure into json format 2 Azure Logic App, parse JSON, but possible null 0 Use JSON returned by Azure Logic App HTTP connector 0 Retrieve json property value in Azure Logic App 1 Azure Logic App SubscriptionNotFound error Hot Network Questions is `yes | rm -r` safer than `rm -rf` Is there a price point beyond which it no longer makes sense to buy an apartment or house? Could an Earth-like world use airships as heavy cargo haulers? A simple Java integer hash set Should I use 16th notes or triplets in swing rhythm? Is there any class+subclass combination which can use divination spells but doesn't rely on magic for combat? What is the best culinary practice surrounding the water used to soak beans, pulses and rice? How is "I am to be" or "we are to be" expressed in French? Why does chess.com consider this promotion a blunder? Is my investment safe if the broker/bank I'm using goes into insolvency? Could celestial objects be used in cryptography? How can you tell an AI apart from a human over the phone but not in person? Is there a case against having an IRA? How can I display two different time zones at the very top where there is only one now? Comparing GAMESS, OpenMOLCAS and Psi4 How many iterations to reach the sequence? Distinct Subset Sums: Extending A276661 Will a 7-speed chain work on a 2x10 speed drivetrain? Why am I getting a "Too many DML statements: 1" in a non-cacheable Apex method? Is it normal to see a bit of rust under the hood? Why Are Traditional Martial Arts Apparently So Reluctant to Evolve? After "Statistics" by Freedman, Pisani, and Purves what book is good for ANOVA? "The LaTeX Companion", 3rd Edition Food is still undercooked on cast iron more hot questions Question feed Subscribe to RSS Question feed To subscribe to this RSS feed, copy and paste this URL into your RSS reader. lang-cs Stack Overflow Questions Jobs Developer Jobs Directory Salary Calculator Help Mobile Products Teams Talent Advertising Enterprise Company About Press Work Here Legal Privacy Policy Terms of Service Contact Us Cookie Settings Cookie Policy Stack Exchange Network Technology Life / Arts Culture / Recreation Science Other Stack Overflow Server Fault Super User Web Applications Ask Ubuntu Webmasters Game Development TeX - LaTeX Software Engineering Unix & Linux Ask Different (Apple) WordPress Development Geographic Information Systems Electrical Engineering Android Enthusiasts Information Security Database Administrators Drupal Answers SharePoint User Experience Mathematica Salesforce ExpressionEngine® Answers Stack Overflow em Português Blender Network Engineering Cryptography Code Review Magento Software Recommendations Signal Processing Emacs Raspberry Pi Stack Overflow на русском Code Golf Stack Overflow en español Ethereum Data Science Arduino Bitcoin Software Quality Assurance & Testing Sound Design Windows Phone more (29) Photography Science Fiction & Fantasy Graphic Design Movies & TV Music: Practice & Theory Worldbuilding Video Production Seasoned Advice (cooking) Home Improvement Personal Finance & Money Academia Law Physical Fitness Gardening & Landscaping Parenting more (10) English Language & Usage Skeptics Mi Yodeya (Judaism) Travel Christianity English Language Learners Japanese Language Chinese Language French Language German Language Biblical Hermeneutics History Spanish Language Islam Русский язык Russian Language Arqade (gaming) Bicycles Role-playing Games Anime & Manga Puzzling Motor Vehicle Maintenance & Repair Board & Card Games Bricks Homebrewing Martial Arts The Great Outdoors Poker Chess Sports more (16) MathOverflow Mathematics Cross Validated (stats) Theoretical Computer Science Physics Chemistry Biology Computer Science Philosophy Linguistics Psychology & Neuroscience Computational Science more (10) Meta Stack Exchange Stack Apps API Data Blog Facebook Twitter LinkedIn Instagram site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.9.1.40116 Stack Overflow works best with JavaScript enabled Your privacy By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. Accept all cookies Customize settings  

暂无
暂无

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question Getting information with Token. OAuth Problem getting LinkedIn access token How do I update my cookie, having got a new access_token? When I run application by installer, I am getting error as “Bad method token. ” DocumentDB pagination token. keep getting “wrong” one Not getting refresh token from Salesforce I keep getting a "scriptcs" error in my C# code for Unity. Nothing I've seen on the internet is working How do I call a method on a static class if I've only got the classes string name? Display Items with value in a List passed as JSON to an Azure Logic App Ask Question Asked 11 months ago Active 11 months ago Viewed 195 times 0 I have some code that collects information off of a page. The use on the page can select items from a dropdown and add them as requirements. Let's say someone needs a notebook, some pencils and maybe some chairs (the idea is the list of items they can add is generated dynamically from another service so the list can be expanded/contracted so I do not know what the list might contain or how long it is). I save this inside a List where the object has an ItemName (string) and an ItemQuantity (int) property. public class IndividualItem { public string ItemName { get; set; } public int ItemQuantity { get; set; } public IndividualItem() { } public IndividualItem(string itemName, int itemQuantity) { ItemName = itemName; ItemQuantity = itemQuantity; } } This gets parsed to JSON and sent to an Azure Logic App and an email needs to be sent using this information. The JSON that arrives in the logic app looks like this: Item Requirements: [ {"ItemName":"Pencil","ItemQuantity":13}, {"ItemName":"Xacto Knife","ItemQuantity":10}, {"ItemName":"Colored Pencils","ItemQuantity":44} ] Now the problem comes when adding this information into an email. In an Azure Logic App I know I can access the information passed in dynamically. So I can access the 'To' field for example to populate where the email is supposed to go. I can access 'Subject' and 'Footer' or whatever other section I need. However, when accessing my 'MeetingItems' list and add it in, the text displays the square brackets and so on (the actual JSON string). My question is, how could I clean the contents of the string list to remove this and add custom formatting. So transform the list that looks like above [{""....}] into maybe an unordered list with each item one underneath another: Pencil: 13 Xacto Knife: 10 ... An example of the complete JSON string that is sent is below. This needs to populate a Send Email action and I know I can access the fields through the dynamic naming convention (so From in one field or whatever). But doing the same and calling ItemList will leave the [{...}] formatting in the text. I know you can do a For Each to access individual items, but then how do you tie this to the Send email action? And if you nest the send email action, you will obviously call that once for each item in the list. { "From": "NO REPLY", "To": "target@email.com", "CC": "cc@email.com", "Subject": "Email Subject", "EmailBody": { "Introduction": "This email has been issued to inform you of an order", "OrderDetails": { "OrderName": "Refill", "OrderDate": "24/09/2020, 09:00", "ExpectedDeliveryDate": "29/09/2020, 09:00", "Location": "Address", "ConfirmationRequired": "Yes", "ShippingDetails": "Yes", "ItemList": [ { "ItemName": "Pencil", "ItemQuantity": 13 }, { "ItemName": "Xacto Knife", "ItemQuantity": 10 }, { "ItemName": "Colored Pencils", "ItemQuantity": 44 } ] }, "Footer": "Please email sender for additional details" } } ----> I have a "partial" solution by editing the input into the list to hold a formatted string that gets passed on. However, I would like to keep this open to see if there is another way besides hardcoding a string that I send across. { "From": "NO REPLY", "To": "target@email.com", "CC": "cc@email.com", "Subject": "Email Subject", "EmailBody": { "Introduction": "This email has been issued to inform you of an order", "OrderDetails": { "OrderName": "Refill", "OrderDate": "24/09/2020, 09:00", "ExpectedDeliveryDate": "29/09/2020, 09:00", "Location": "Address", "ConfirmationRequired": "Yes", "ShippingDetails": "Yes", "ItemList": "<ul><li><b>Pencil</b> - 13</li><li><b>Xacto Knife</b> - 10</li><li><b>Colored Pencils</b> - 44</li></ul>" }, "Footer": "Please email sender for additional details" } } c# azure azure-logic-apps Share Improve this question Follow edited Sep 15 '20 at 11:59 pSYoniK asked Sep 15 '20 at 8:14 pSYoniKpSYoniK 3111 silver badge1010 bronze badges 3 Is the Item Requirements: [{"ItemName":"Pencil"... you have mentioned above is the complete json string or is snippet of the json string? – Satya V Sep 15 '20 at 11:23 @sathya_vijayakumar-MSFT --- I just edited my post and provided more information for clarity. The issue is with the ItemList property. I have circumvented the issue at the moment, by overriding ToString and creating a formatted string that I send across, so that's solved(ish) but I am still curious if there is a better way. – pSYoniK Sep 15 '20 at 12:00 Thanks for including more information in the question. I've went forward and answered question. Hope it helps. – Satya V Sep 15 '20 at 13:05 Add a comment  |  1 Answer 1 Active Oldest Votes 0 I assume that you are doing a PARSE JSON operation to convert the above string back to JSON. I understand that once it has been parse, you are still with the ItemList is left with the below format : Now, to achieve your requirement to include as list in the email you can create HTML Table with this ItemList output obtained from the from the Parse JSON step. Below is the Output : If you don't want the headers, you choose the custom in the column section Create HTML Table step. Choose the values. You can include the output of the HTML table to the body of the email. Mail Output : Share Improve this answer Follow answered Sep 15 '20 at 13:01 Satya VSatya V 2,98811 gold badge33 silver badges77 bronze badges 1 Thank you for that. The table heading seems off compared to where the body of the result gets placed on my end, but I think that should be straightforward. – pSYoniK Sep 15 '20 at 13:54 Add a comment  |  Your Answer Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question. Provide details and share your research! But avoid … Asking for help, clarification, or responding to other answers. Making statements based on opinion; back them up with references or personal experience. To learn more, see our tips on writing great answers. Draft saved Draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Submit Post as a guest Name Email Required, but never shown Post as a guest Name Email Required, but never shown Post Your Answer Discard By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy Not the answer you're looking for? Browse other questions tagged c# azure azure-logic-apps or ask your own question. The Overflow Blog The full data set for the 2021 Developer Survey now available! Podcast 371: Exploring the magic of instant python refactoring with Sourcery Featured on Meta Review queue workflows - Final release Please welcome Valued Associates: #958 - V2Blast & #959 - SpencerG Related 513 How to use LINQ to select object with minimum or maximum property value 7 Parsing JSON in Azure Logic App 1 Unwanted string with Json inserted from Azure Queue for Logic App 0 Azure logic app with Condition 1 Azure Logic App List Blob what is List_Blob metadata field value 0 Azure Logic App output structure into json format 2 Azure Logic App, parse JSON, but possible null 0 Use JSON returned by Azure Logic App HTTP connector 0 Retrieve json property value in Azure Logic App 1 Azure Logic App SubscriptionNotFound error Hot Network Questions is `yes | rm -r` safer than `rm -rf` Is there a price point beyond which it no longer makes sense to buy an apartment or house? Could an Earth-like world use airships as heavy cargo haulers? A simple Java integer hash set Should I use 16th notes or triplets in swing rhythm? Is there any class+subclass combination which can use divination spells but doesn't rely on magic for combat? What is the best culinary practice surrounding the water used to soak beans, pulses and rice? How is "I am to be" or "we are to be" expressed in French? Why does chess.com consider this promotion a blunder? Is my investment safe if the broker/bank I'm using goes into insolvency? Could celestial objects be used in cryptography? How can you tell an AI apart from a human over the phone but not in person? Is there a case against having an IRA? How can I display two different time zones at the very top where there is only one now? Comparing GAMESS, OpenMOLCAS and Psi4 How many iterations to reach the sequence? Distinct Subset Sums: Extending A276661 Will a 7-speed chain work on a 2x10 speed drivetrain? Why am I getting a "Too many DML statements: 1" in a non-cacheable Apex method? Is it normal to see a bit of rust under the hood? Why Are Traditional Martial Arts Apparently So Reluctant to Evolve? After "Statistics" by Freedman, Pisani, and Purves what book is good for ANOVA? "The LaTeX Companion", 3rd Edition Food is still undercooked on cast iron more hot questions Question feed Subscribe to RSS Question feed To subscribe to this RSS feed, copy and paste this URL into your RSS reader. lang-cs Stack Overflow Questions Jobs Developer Jobs Directory Salary Calculator Help Mobile Products Teams Talent Advertising Enterprise Company About Press Work Here Legal Privacy Policy Terms of Service Contact Us Cookie Settings Cookie Policy Stack Exchange Network Technology Life / Arts Culture / Recreation Science Other Stack Overflow Server Fault Super User Web Applications Ask Ubuntu Webmasters Game Development TeX - LaTeX Software Engineering Unix & Linux Ask Different (Apple) WordPress Development Geographic Information Systems Electrical Engineering Android Enthusiasts Information Security Database Administrators Drupal Answers SharePoint User Experience Mathematica Salesforce ExpressionEngine® Answers Stack Overflow em Português Blender Network Engineering Cryptography Code Review Magento Software Recommendations Signal Processing Emacs Raspberry Pi Stack Overflow на русском Code Golf Stack Overflow en español Ethereum Data Science Arduino Bitcoin Software Quality Assurance & Testing Sound Design Windows Phone more (29) Photography Science Fiction & Fantasy Graphic Design Movies & TV Music: Practice & Theory Worldbuilding Video Production Seasoned Advice (cooking) Home Improvement Personal Finance & Money Academia Law Physical Fitness Gardening & Landscaping Parenting more (10) English Language & Usage Skeptics Mi Yodeya (Judaism) Travel Christianity English Language Learners Japanese Language Chinese Language French Language German Language Biblical Hermeneutics History Spanish Language Islam Русский язык Russian Language Arqade (gaming) Bicycles Role-playing Games Anime & Manga Puzzling Motor Vehicle Maintenance & Repair Board & Card Games Bricks Homebrewing Martial Arts The Great Outdoors Poker Chess Sports more (16) MathOverflow Mathematics Cross Validated (stats) Theoretical Computer Science Physics Chemistry Biology Computer Science Philosophy Linguistics Psychology & Neuroscience Computational Science more (10) Meta Stack Exchange Stack Apps API Data Blog Facebook Twitter LinkedIn Instagram site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.9.1.40116 Stack Overflow works best with JavaScript enabled Your privacy By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. Accept all cookies Customize settings   How do I post to Facebook user's friend's wall with publish_stream but NOT offline_access using an application access token
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM