If your hardcoding key into custom header, principal becomes redundant since it's meant to refered using merge field syntax in custom header value to hide secrets.
Thanks for noticing it. Yes I agree, I missed it in video but added it in the blog post for the same. www.salesforcebolt.com/2023/07/weather-apis-integration-named.html
Precise and to the point. Wonderful tutorial to exercise LWC and Integration topics at the same time. Just an observation: If we don't give anything in input and press the button we still get 'Sunny' climate. I verified this a lot of times. To fix this, I rephrased the apex method as follows and now it gives error when nothing is given in input and still weather is searched: public static string getWeather(String city){ if (city != null) { Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint('callout:WeatherAPI/current.json?q='+city); request.setMethod('GET'); HttpResponse response = http.send(request); if (response.getStatusCode() == 200) { return response.getBody(); } }
return ''; EDIT 2: I also fixed searching weather for cities where there are two words...for eg: "New York" or "Los Angeles" which does not work with current code. I used regex for this in Javascript. I added a property 'encodedInputText' in the JS file and also tweaked the buttonClick function as below: buttonClick(event){ //REGEX for considering the spaces given in the input and spaces in City Name const input = this.template.querySelector("lightning-input").value; const regex = / {2,}/g; const correctedInput = input.replaceAll(regex, " ").trim(); this.encodedInputText = encodeURI(correctedInput); getWeather({city : this.encodedInputText}) .then((response)=>{ console.log("in then"); //parse received JSON let parsedData = JSON.parse(response); >>>> Rest is same >>>>>
Appreciate you work helpful for me , i have request one video about lightning datatable. in datatable how to apply type attribute so the values comes as same sized button irrespect of length looking forward for that videos
Hi, Great stuff! If possible can you create or suggest series on salesforce integration? Videos on youtube are little confusing and don't implement end to end. Most of the videos just demo using postman.
@Salesforce Bolt I just tried this in my org. It gives an error if the city has two words. For New York, Abu Dhabi are giving error. Single word cities are fine.
Hi @Salesforce Bolt, Thanks a million for sharing useful Content. Iam encountering an error "API Key is disabled ", Could u pls guide me How to resolve it.
@@SalesforceBolt so i have to use https end point to generate token which i will use as bearer authorization for subsequent callout of api’s. Now i am configuring named credential with external credential but then it keeps giving me 503 error, later on it was brought up that the cert i have in named credential should be client cert. So how do i use that now? The api team gave the cert but how do i use for my named credential? I know i have to import it under certifications but do i need to make changes in my apex code too for using that cert?
The error was rectified by changing the code as below.... String encodedCity = EncodingUtil.urlEncode(city, 'UTF-8'); req.setEndPoint('callout:WeatherAPI/current.json?q='+encodedCity);
Error: System.NullPointerException: Attempt to de-reference a null object Error: Class.Weather.getWeather: line 28, column 1 AnonymousBlock: line 1, column 1 AnonymousBlock: line 1, column 1 59.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO Execute Anonymous: Weather.getWeather('London'); Why is this error coming?
Hi@@SalesforceBolt! Previously it worked for me... I fetched data also... But today I tried again but it is showing me ------ response: {"error":{"code":1002,"message":"API key is invalid or not provided."}}
@@SalesforceBolt It wasn't expired... My bad I used other name in Custom Headers... Later it worked... But could you try using OpenWeatherMap API and NewsAPI with External Named Credentials? I was integrating these but it was not working... Finally I did using Custom Metadata but how to do with External Credentials, I'm still desperate to know...
Awesome content for Integration learners...
Thankyou
Glad you like it!
Just Awesome content 👍👍
Thanks for the visit
The best channel for sfdc newbies!!
Thanks Adwit, glad you like it.
Helpful
Thanks
Glad you like it,
Thanks for the good video. Please share video a beginner how to start working in integration
Sure I will add itin queue.
If your hardcoding key into custom header, principal becomes redundant since it's meant to refered using merge field syntax in custom header value to hide secrets.
Thanks for noticing it. Yes I agree, I missed it in video but added it in the blog post for the same.
www.salesforcebolt.com/2023/07/weather-apis-integration-named.html
Great 👍 Thanks
Very informative. Can you please also a make a complete video on Named credentials with OAuth 2.0. It's really confusing 😟
Yes it is confusing, I am planning a separate video as well!
@@SalesforceBoltis the video out?
@@SalesforceBolt Is the video out now???
Precise and to the point. Wonderful tutorial to exercise LWC and Integration topics at the same time.
Just an observation: If we don't give anything in input and press the button we still get 'Sunny' climate. I verified this a lot of times.
To fix this, I rephrased the apex method as follows and now it gives error when nothing is given in input and still weather is searched:
public static string getWeather(String city){
if (city != null) {
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('callout:WeatherAPI/current.json?q='+city);
request.setMethod('GET');
HttpResponse response = http.send(request);
if (response.getStatusCode() == 200) {
return response.getBody();
}
}
return '';
EDIT 2: I also fixed searching weather for cities where there are two words...for eg: "New York" or "Los Angeles" which does not work with current code. I used regex for this in Javascript.
I added a property 'encodedInputText' in the JS file and also tweaked the buttonClick function as below:
buttonClick(event){
//REGEX for considering the spaces given in the input and spaces in City Name
const input = this.template.querySelector("lightning-input").value;
const regex = / {2,}/g;
const correctedInput = input.replaceAll(regex, " ").trim();
this.encodedInputText = encodeURI(correctedInput);
getWeather({city : this.encodedInputText})
.then((response)=>{
console.log("in then");
//parse received JSON
let parsedData = JSON.parse(response); >>>> Rest is same >>>>>
Thanks, glad you like it!
Hi Kapil, the video is very informative. Could you please let us know how the same can be re authorized using OAuth 2.0 instead of custom.
Appreciate you work helpful for me , i have request one video about lightning datatable. in datatable how to apply type attribute so the values comes as same sized button irrespect of length looking forward for that videos
Sure, I will add it in the queue.
Hi,
Great stuff!
If possible can you create or suggest series on salesforce integration? Videos on youtube are little confusing and don't implement end to end. Most of the videos just demo using postman.
Sure I will add it in the queue!
@Salesforce Bolt I just tried this in my org. It gives an error if the city has two words. For New York, Abu Dhabi are giving error. Single word cities are fine.
i subcribed today, to search any datacloud integgration, is it possible?
Thanks for the subscribe. Data Cloud integrations will be coming soon.
Hi @Salesforce Bolt, Thanks a million for sharing useful Content. Iam encountering an error "API Key is disabled ", Could u pls guide me How to resolve it.
Hi are you still having the same issue?
@@SalesforceBolt @Shaik_Abdul_01 it could be because the API key would have expired. Its only valid for few weeks i guess..
i dont know why, but my icon doesn't load...but if i open the image in a new tab, i can see it.
Is it coming from the same URL that you must have added in your named credentials?
Opencage API is not working using Named Credential and External Credential
What's the error in the console?
How do certification works here?
Can you please elaborate your questions?
@@SalesforceBolt so i have to use https end point to generate token which i will use as bearer authorization for subsequent callout of api’s. Now i am configuring named credential with external credential but then it keeps giving me 503 error, later on it was brought up that the cert i have in named credential should be client cert. So how do i use that now? The api team gave the cert but how do i use for my named credential? I know i have to import it under certifications but do i need to make changes in my apex code too for using that cert?
The error was rectified by changing the code as below....
String encodedCity = EncodingUtil.urlEncode(city, 'UTF-8');
req.setEndPoint('callout:WeatherAPI/current.json?q='+encodedCity);
Error: System.NullPointerException: Attempt to de-reference a null object
Error: Class.Weather.getWeather: line 28, column 1
AnonymousBlock: line 1, column 1
AnonymousBlock: line 1, column 1
59.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO
Execute Anonymous: Weather.getWeather('London');
Why is this error coming?
Have you copied the exact code from code snippet?
Hi@@SalesforceBolt! Previously it worked for me... I fetched data also... But today I tried again but it is showing me ------ response: {"error":{"code":1002,"message":"API key is invalid or not provided."}}
@@anupambasak2000 please check the key if it got expired.
@@SalesforceBolt It wasn't expired... My bad I used other name in Custom Headers... Later it worked... But could you try using OpenWeatherMap API and NewsAPI with External Named Credentials? I was integrating these but it was not working... Finally I did using Custom Metadata but how to do with External Credentials, I'm still desperate to know...