discord.py Extracting information from api with query parameters - api

I'm quite new to the aspect of using API with discord.py and I seem to be having issues when it comes to extracting data with query parameters.
My code is as follows:
#command(name="characterID", aliases=["cid"])
async def character_info(self, ctx, characterID):
URL="https://c2s1.op-framework.com/op-framework/character.json"
async with request("GET", URL, headers={}, params=characterID) as response:
if response.status == 200:
data = await response.json()
substring = data["data"]
await ctx.send(f"The CID {characterID} has the following info:\n{substring}")
My goal here is to extract information from a certain character ID but upon running my command I end up with substring = []. I've been reading the documentation and I can't seem to understand what I'm doing wrong. If someone could enlighten me in the right direction it would be much appreciated.
I am provided with the following documentation:
/character.json - > Returns information about a certain character.
Query parameters:
FIELD: characterId TYPE:integer DESCRIPTION: The character id you need information about.
The expected output for substring should be something like this:
[
{
"steamIdentifier": "steam:11000010d322da9",
"firstName": "Kye",
"lastName": "Clancy",
"fullName": "Kye Clancy"
}
]
If my problem is unclear or needs further details as to what I have tried so far feel free to let me know and thank you.

Related

Karate match error: match failed: EQUALS $ | data types don't match (OTHER:MAP)

I have a scenario that reads a json field from a file and compares it to another json field. When I do the match, it says the field from the file is type "other". Sorry for the screen shots, but I think the print statements are helpful.
This is the file, I am not sure if I can provide an example without using the file because when I set the field in the scenario, it works differently, the value of address is then a string in the match statement. It must have something to do with the data returned from the read row? This is what the data looks like that comes back from the read row:
{
"address": "{"street":"123 Main Street", "city":"Queens", "state":"NY"}"
}
Scenario: test error for stack overflow
* def testAddress = db.readRow("select address from json_issue where person = 'Carole'")
* print testAddress.address
* def jsonAddressMatch =
"""
{
"street":"123 Main Street",
"city": "Queens",
"state": "NY"
}
"""
* print jsonAddressMatch
* match testAddress.address == jsonAddressMatch
This is the first test's results
I tried to see if I could convert it to json thinking it was not being interpreted as json. I added these two lines, but the value is a string so it still is not the correct type.
* json addressObject = testAddress.address
* match addressObject.value == jsonAddressMatch
This is the second test's results using "json" to convert
The db.readRow() is clearly returning something that's NOT a Java Map or List, so if you fix that you are on your way.
Refer the docs: https://github.com/karatelabs/karate#type-conversion
The result of * print testAddress.address clearly shows that it is NOT something Karate could auto-convert to JSON, else the output would have been indented correctly.
Now, in a pinch if you know that the toString() of whatever is being returned gives you valid JSON, you can do this:
* def testAddress = karate.fromString(testAddress)

Return inserted id with TypeORM & NestJS raw query: await connection.manager.query(`INSERT INTO

I'm looking to return the id or better yet, all information that was inserted, using a raw query with TypeORM and NestJS. Example as follows:
await connection.manager.query(`INSERT INTO...`)
When assigning the query to a constant and console logging it below, it does not yield any helpful information:
OkPacket {
fieldCount: 0,
affectedRows: 1,
insertId: 0,
serverStatus: 2,
warningCount: 1,
message: '',
protocol41: true,
changedRows: 0
}
As you can see, it returns no pertinent information, the insertId above is obviously incorrect, and it returns this every time, regardless of the actual parameters of the query.
I know with more typical TypeORM queries you can use .return(['name_of_column_you_want_returned']).execute()
and it will return the relevant information just fine. Is there any way to do this with a raw query? Thank you!
tl;dr You're getting the raw mariadb driver response (OkPacket) from the INSERT command, and you'd need a new SELECT query to see the data.
You're using the TypeORM EntityManager, and the docs don't mention a return value. Looking at the source code for query, the return type is any. Since it's a raw query, it probably returns an object based on the type of database you're using rather than having a standard format.
In this case, you're using MariaDb, which returned an OkPacket. Here's the documentation:
https://mariadb.com/kb/en/ok_packet/

Boosting individual elasticsearch indices to have preference in results

I am trying to boost certain indices in my elastic search query. Right now, my query is looking like this.
var query = {
"query": {
"query_string": {
"fields": ["FirstName", "LastName"],
"query": "Hank Hill",
"default_operator": "AND"
}
}
};
var boosted_indices = {
"index_A" : 1.0,
"index_B" : 1.0,
"index_C" : 10.0
};
if (boosted_indices) {
query["indices_boost"] = boosted_indices;
}
// stringify and send query in an http.get request
I know that my query without boosting any indices works as I expect. However, I am still getting a lot of results from "index_A" in my query results, rather than the heavily boosted index_C. I know that there should be a similar number of matching results in A and C, so the issue must be that I am not boosting the query correctly.
Did I set up my query JSON incorrectly? On the tutorial I linked, it did not give much context.
One other thing I noticed.. the "_score" field for the returned documents... all of them are set to null. Might this have something to do with my documents not being boosted according to the index they came from?
I hope you are not using the sort parameter in query. This could be the reason that _score is null and you are not getting expected results.
Does this help?

m.request: use URL which contains colons

I have a m.request call like this:
mCmdName = "cn:cmd:list:deselectAll";
m.request({
method : "POST",
url : "/testing/cmd/" + mCmdName,
data: data
});
Now m.request calls
xhrOptions.url = parameterizeUrl(xhrOptions.url, xhrOptions.data);
and tries to replace all ':[name]' parts with data[name] which results in 'undefined' as data doesn't contain any of the keys. Data is just the data object of the XHR request.
Is there a way to prohibit this default behavior?
Thanks, Stefan
PS: I'm asking here and not in mithril mailing list because I can't post there for incomprehensible reasons. Maybe somebody can give me a hint on this.
Have you tried
encodeURIComponent("cn:cmd:list:deselectAll")
which gives you
cn%3Acmd%3Alist%3AdeselectAll
If necessary you can decode on the server.

How to practice with Xpath Match Assertion in SoapUI?

I have tested Contains Assertion without any issues but I don't know how to validate the webservices using Xpath Match Assertion in SoapUI.
Can you please tell me how to workout 'Xpath Match' Assertion in SoapUI?
I'm using JSON requests.
Updated: Please find the attachments
1) My JSON Response
2) Assertion Error message
Please tell me how to validate the identifier and please provide the correct XPath expression and Expected Results
Thanks in advance!
In XPath expression field you need to insert your XPath expression =)
And in expected result field you need to insert expected result of applying your XPath expression to response of your request.
For example, if response contains something like this:
[
{
"id": "112",
"username": "user1",
},
{
"id": "233",
"username": "user2",
}
]
and you want to verify, that response contains a user with id = 112,
you need to add in XPath expression //id[text() = '112'] and in expected result - 112
In Soap UI pro you can use graphic wizard for creating XPath Match Assertion.
About XPath basics you can read here: http://www.w3schools.com/xpath/