I am trying to access the Title data found in the image below via rest. Nothing allows me to get it. I have tried:
data.d.results[0].Title
Perhaps it's an issue with backlash before double quotes. Tested with:
let data = {d: { results: [ { Title: "\"hello\"", } ] }}
console.log(data.d.results[0].Title);
Worked fine. Can't provide answer without more context
Related
I have a list of objects and I need to iterate over the list and add a certain property (string) from the object to a map of <string, boolean>. Here is my code:
this.selectedPeople.forEach(element => {
this.checkedPeople.set(element.name, true);
}
The purpose of this is to set checkboxes to be checked for certain people (if they are in the selectedPeople list) using [checked] in Angular. For some reason, I get this error when trying to build the project:
Property 'name' does not exist on type 'string'
I tried to change element.name to just element and that provides errors during compilation but when I look at the frontend, none of the checkboxes are checked (as you would expect since the key in the map is not a string as required). I have done similar things with other lists and they seem to be working fine, so why is this an issue here?
Edit1: I have seen some other solutions on here but they do not seem to be relevant to my case or have not worked.
Edit2: This is not the actual code as it is company code so I have tried to recreate the issue using a different scenario so as not to run into any confidentiality issues. To elaborate further, the selectedPeople array would be something like this:
[
{
"name":"Paul",
"age":24,
"sport":"Football"
},
{
"name":"Tom",
"age":22,
"sport":"Tennis"
}
]
Edit3: For further clarification, here is what my checkedPeople map looks like:
0: {"Paul" => false}
1: {"Jennifer" => false}
2: {"Georgia" => false}
3: {"Tom" => false}
And I am trying to change the value to true for each person who is in the selectedPeople array.
I tried using element['name'] instead of element.name and that seemed to do the trick. I do not quite understand why this works (especially given that element.name is used elsewhere and works fine) so if anyone has any idea, feel free to comment.
Without seeing your project setup, I'm betting that typescript thinks that element can be a string or an object... something like this:
type SelectedPeople = Array<string | { name: string }>
In such as case, you will need to make sure the item is not a string before accessing the name property:
this.selectedPeople.foreach(element => {
if(typeof element === 'string') {
this.checkedPeople.set(element, true);
} else {
this.checkedPeople.set(element.name, true);
}
}
Yes, you can either try what Ryan is suggesting above, or alternatively you can add a safe check before setting each element like so:
this.selectedPeople.forEach(element => {
If (element && element.Name){
this.checkedPeople.set(element.name, true);
}
}
I'm getting the following message
UnhandledPromiseRejectionWarning: MissingParameter: The request must contain the parameter DeleteMessageBatchRequestEntry.1.Id.
I think I'm following the documentation to a T at AWS-SDK/SQS
I'm using this code
var params = {
Entries: _.map(_.uniqWith(data.Messages,d=>d.MessageId),d=>({
Id: d.MessageId,
ReceiptHandle: d.ReceiptHandle
})),
QueueUrl: xx.QueueUrl
};
await sqs.deleteMessageBatch(params).promise();
This is what params looks like at the time of sending; looks just like the docs if you ask me...
{
Entries: [
{
Id: "83ba1e18-someid",
ReceiptHandle: "AQEB79CDI1Q+blablabla"
}
]
QueueUrl: "https://sqs.us-west-2.amazonaws.com/somequeeuurl"
}
My system:
aws-sdk: "^2.354.0",
MacOS - current
node 8.12.0
UnhandledPromiseRejectionWarning: MissingParameter: The request must contain the parameter DeleteMessageBatchRequestEntry.1.Id.
I just spent a long time looking at this error and debugging my code. What I finally figured out is that it seems to be trying to say that there needs to be at least one DeleteMessageBatchRequestEntry element in the request – there can't be 0. When I refactored our code and added a check to make sure that we wouldn't make a request if there were no entries in the list, this problem went away.
Is it possible that you are actually sending the following in certain situations?
{
Entries: []
QueueUrl: "https://sqs.us-west-2.amazonaws.com/somequeeuurl"
}
I'm trying to batch upload photos and I keep getting a response back from Postman saying "Batch parameter must be a JSON Array" Does anyone see what is wrong with this because it looks like valid json to me. I've been rattling with this for a few hours making minor tweaks trying to get it to upload to no avail. I also have tried encoding the url.
https://graph.facebook.com/v2.11?batch=[{"method":"POST", "relative_url":"https://graph.facebook.com/v2.11/{pageid}/photos?access_token={access-token}", "body":"link_url":"https://{link-to-image}/wmphotos/999995/6d5cc4169bbf4e7dbe31f3739e025412/a572c29dff_640.jpg"}]&access_token={access-token}
Looking at your code, it seems that the JSON object in your batch array is actually malformed. body:link_url:link should be body: {link_url:link}
Bad:
[
{
"method":"POST",
"relative_url":"foo",
"body":"link_url":"link"
}
]
Good:
[
{
"method":"POST",
"relative_url":"foo",
"body":{"link_url":"link"}
}
]
Here is what I am using in Python 3:
payload={"query": """query
{
organization(login: "MY-ORG-ID") {
samlIdentityProvider {
externalIdentities(first: 10) {
edges {
node {
user {login}
samlIdentity {nameId}
scimIdentity {username}
}
}
}
}
}
}"""
}
URL = 'https://api.github.com/graphql'
HEADERS = {'accept': 'application/vnd.github.v4.idl', 'authorization': 'bearer MY-GITHUB-TOKEN'}
response = requests.post(url=URL, json=payload, headers=HEADERS)
It just works fine.
However, I am trying to use this query in POSTMAN tool but have no clue how to do this. I tried to remove 3-double quotes """ """, I get Unexpected 'q' error. When I use double quotes instead of 3-double quotes and login: \"MY-ORG-ID\", I get "message": "Problems parsing JSON" error.
There's no problem with headers and URL. I just gave them here for completeness.
If you're trying to enter the query into body of your post request in the postman app, a quick workaround to achieve multiple lines is to use a placeholder in the form of an environment variable in your body and enter the query in your pre-request script:
In your body:
{
"query":{{query}}
}
In your pre-request script:
pm.environment.set("query", JSON.stringify(
`
query {
organization(login: "MY-ORG-ID") {
samlIdentityProvider {
externalIdentities(first: 10) {
edges {
node {
user {login}
samlIdentity {nameId}
scimIdentity {username}
}
}
}
}
}
}
`
));
Note that ` in the above code is a backtick, not a single quote!
It's not the best solution ever, but the only one that worked for me so far in Postman to avoid entering more complex queries/mutations in a single line.
Hope this helps.
Postman has a "graphql" type of request body. It means you can write your query without quotes (see screenshot attached). Also, it is useful when you are assigning variables to query/mutation.
P.S. you might need to update your postman to get a "graphql" type of body payload.
Apparently you can't, therefore you need to turn your multiline string into a single string.
Quickest way to do this is to paste it in a web browser search bar for a format change, then copy and paste from the web browser search bar back into postman.
Triple quotes in Python denote a multi-line string right? So try double quotes, and login: \"MY-ORG-ID\" and placing the entire query in a single line?
{
"query":"query{organization(login: \"MY-ORG-ID\") {samlIdentityProvider {externalIdentities(first: 10) {edges {node {user {login}samlIdentity {nameId}scimIdentity {username}}}}}}}"
}
I'm having trouble with parsing my Json, when i place the url in the browser i get this as a return {"token": "7xv6r32eay5n376", "secret": "589bc72ix7mowua"} So all i want to do is get that string and parse out the token and secret and display the values in a notify to confirm i'm getting the correct information. Can anyone see what i'm doing wrong?
rule first_rule {
select when pageview ".*" setting ()
pre{
json=http:get(/* I place my URL here */);
content = json.pick("$..content");
token=content.decode();
tok=token.pick("$..token");
sec=token.pick("$..secret");
message="Token: "+tok+" "+"Secret: "+sec;
}
notify("Values: ",message);
}
}
so i fixed my KRL problem, I guess when using http:get(); you must use double quotes "" not single '' in the get().