I am trying to call the getTransaction method from Solana netwrok using Web3.js but I am not getting any output. Can anyone help?
Code
const { signature } = await window.solana.signAndSendTransaction(transaction);
await connection.confirmTransaction(signature);
await connection.getTransaction(signature, (error, tx)=>{
console.log("Details", txn);
})
Related
How to pass Filter Json Object as query parameter in Dio GET request call for this API in flutter.
I am using below code for passing query parameter but it is not working properly
Future<GetPropertyListResponseModel> getPropertyList(
GetPropertyListRequestModel queryParam) {
final params = <String, dynamic>{
'Filters': {"offset":0,"limit":50,"UnparsedAddress":"t"},
};
var dioCall = dioClient.get(ApiConstants.GET_PROPERTY_LIST, queryParameters:params);
try {
return callApiWithErrorParser(dioCall)
.then((response) => GetPropertyListResponseModel.fromJson(response.data));
} catch (e) {
rethrow;
}
In Order to get success response the GET URL should be like below
https://cribzzz-api.apps.openxcell.dev/property?Filters=%7B%22offset%22%3A0%2C%22limit%22%3A50%2C%22UnparsedAddress%22%3A%22t%22%7D
But when I use the above code the URL becomes as below
https://cribzzz-api.apps.openxcell.dev/property?Filters%5Boffset%5D=0&Filters%5Blimit%5D=50&Filters%5BUnparsedAddress%5D=t
I am trying to write one Twilio function. Inside the Twilio function, I have one external API call with parameters for one of my API. API will return the result and that result I am passing using "Say" tag.
I have one Twilio Autopilot Bot in which I have one task added. On execution of that task it will call "Action URL" which is the Twilio function URL.
But somehow this full flow is not working. I think my external API call using AXIOS is not proper. Can you help me to call external API with parameters from the Twilio function? For my Twilio function check following code
Thanks in advance
exports.handler = function(context, event, callback) {
const responseData = await axios.post(`API_PATH/GetMessageData`,'Minute':'3000','MessageType':'2,3'});
const resultData = responseData.data;
let response = {};
response.actions = [];
response.actions.push({"say":"hello sam" + resultData})
callback(null,response)
};
You are calling axios using await, but you have not declared the function to be an async function.
You should also ensure to catch any potential API or connectivity errors when making external requests. That will also show if there's an error in calling your API.
exports.handler = async function(context, event, callback) {
try {
const responseData = await axios.post(`API_PATH/GetMessageData`,'Minute':'3000','MessageType':'2,3'});
const resultData = responseData.data;
let response = {};
response.actions = [];
response.actions.push({"say":"hello sam" + resultData})
callback(null,response)
} catch(error) {
console.error(error)
let response = {};
response.actions = [];
response.actions.push({"say":"There was a problem with the bot, please try again."});
callback(null, response);
}
};
Edit
You also added that your result looks like this:
{
"Message": {
"Text": "Data retrieved successfully"
},
"MessageList": [
{ "ContactNo": "+91xxxxxxxx", "Message": "test message", },
{ "ContactNo": "+91xxxxxxxx", "Message": "test message 2", }
]
}
I'm not sure exactly which of those messages are what you want to send back to the user. Perhaps you want to send both of the Messages inside the MessageList object? You could do that like so (just showing the part of the code inside the try):
const responseData = await axios.post(`API_PATH/GetMessageData`,'Minute':'3000','MessageType':'2,3'});
const resultData = responseData.data;
let response = {};
response.actions = [];
resultData.MessageList.forEach((message) => {
response.actions.push({"say": message.Message });
}
callback(null,response)
This loops through the MessageList and adds a new say action to the response with each message.
I'd like to use express and mongo DB to find a document based off of a URL.
My Schema includes
bandUrl: {
type: String
}
This is my Rout inside of the Express server.
// Get Single Band By bandUrl
router.get('/bandUrl/:url', (req, res) => {
quoteGenerator.find({bandUrl: req.params.url}).then(gen => res.json(gen))
})
I set one of the documents to have bandUrl as 'http://localhost:3000/'.
I tested the route using something other than a URL - just using a string works fine... I'd really like to use the URL though. Is there a way to do this?
Here is my fake/test route form the application..
const getFakeInfo = async () => {
try {
const response = await fetch(`/api/autoquotegenerators/bandUrl/http://localhost:3000/"`, {
method: 'GET',
})
const responseData = await response.json()
console.log(responseData)
} catch (error) {
console.log(error)
}
}
I am thinking the extra slashes in the URL are whats causing the issue.
Thanks for your help!
What you want to you use is encodeURIComponent(). This function escapes all URI specific characters, so they get interpreted properly. Your request code should look something like this:
const response = await fetch(`/api/autoquotegenerators/bandUrl/${encodeURIComponent("http://localhost:3000/")}`, {
method: 'GET',
})
If you want to learn more about this function, you can have a look over here.
I am trying to write a simple test in flutter using MockClient, but I can't seem to get it to work.
Here is the code I am trying to test:
getItemById(int id) async {
final response = await client.get("$_host/item/$id.json");
final decodedJson = json.decode(response.body);
return Item.fromJson(decodedJson);
}
Here is the test code:
test("Test getting item by id", () async {
final newsApi = NewsAPI();
newsApi.client = MockClient((request) async {
final jsonMap = {'id': 123};
Response(json.encode(jsonMap), 200);
});
final item = await newsApi.getItemById(123);
print("Items: ${item.toString()}"); //<-- dosen't print anything.
expect(item.id , 123);
});
When I run the test, it fails with the following message:
NoSuchMethodError: The getter 'bodyBytes' was called on null.
Receiver: null
Tried calling: bodyBytes
I am guessing the issue here is that nothing is returned from the MockClient when I make the call to the getItemById method, but I am not sure why.
I had the same exact issue. You have to return the Response
return Response(json.encode(jsonMap), 200);
Mock expects test function to be EXACTLY as you real function (including OPTIONAL parameters and so on). If both does not match it returns NULL and that is what is happening with your code. Double check to see where your test function is different of original function.
I am using Redux and trying to make a call to Facebook API with their JS SDK. I've only ever used promises with Redux and so since the method FB.getLoginStatus just returns a simple JS object, I'm not sure how to ensure that the payload doesn't return undefined.
With redux-promise, you add it to the applyMiddleware(ReduxPromise)... and then it ensures nothing is returned until the promise resolves. But I don't know how to do that here.
I've also used async/await functions with React Native without an issue, but I tried using them here and for some reason the code still returns the payload, before the asynchronous request (await ...) is finished. So I tried working with redux-await, but couldn't get it to work.
export function getLoginStatus() {
var res = FB.getLoginStatus(function(res) {
console.log(res);
});
console.log("res ", res);
return {
type: GET_LOGIN_STATUS,
payload: res
}
}
Hm, things can get a little tricky as I've not used redux-promise. And I can't tell exactly what else you have tried. But this would be my first shot:
async function _getLoginStatus() {
var payload = new Promise( (resolve, fail) => {
FB.getLoginStatus((res)=>resolve(res));
});
return {
type: GET_LOGIN_STATUS,
payload: payload
}
}
// Last time I exported an async function I needed this HYMMV
export let getLoginStatus = _getLoginStatus;
And then elsewhere in the code:
import {getLoginStatus} from 'whatever.js';
var payloadResult = await getLoginStatus();