Cannot get list of entries: The resource could not be found (Contentful) - contentful

I am trying to retrieve a list of entries based on category_type but I'm getting the exception below:
I/flutter ( 8486): Cannot get list of entries. Finished with error: {
I/flutter ( 8486): "sys": {
I/flutter ( 8486): "type": "Error",
I/flutter ( 8486): "id": "NotFound"
I/flutter ( 8486): },
I/flutter ( 8486): "message": "The resource could not be found.",
I/flutter ( 8486): "requestId": "883045ce-dcc2-4187-ab1d-28c57ad18756"
I/flutter ( 8486): }
I/flutter ( 8486): null
This is the calling code:
Future<List<Category>> getCategories() async {
try {
final entries = await _contentfulClient.getEntries<Category>(
params: {
'content_type': 'category',
'skip': '0',
'limit': '100',
'order': 'sys.createdAt',
},
);
return entries.items.asList();
} catch(exception){
print(exception.message);
}
}
The content_type name is correct and there is no mistake in the spelling.
I tried a different code to get information about the space I'm trying to access and that works just fine:
Future<Space> getCurrentSpaceDetails() async {
try {
return await _contentfulClient.getSpaceDetails(
spaceid: Secrets.CONTENTFUL_SPACE_ID);
} on ContentfulError catch (error) {
throw ContentfulError(message: error.message);
}
}
with the output:
I/flutter ( 8486): Space {
I/flutter ( 8486): sys=SystemFields {
I/flutter ( 8486): id=5k4zwxslsof9,
I/flutter ( 8486): type=Space,
I/flutter ( 8486): },
I/flutter ( 8486): locales=[Locale {
I/flutter ( 8486): code=en-US,
I/flutter ( 8486): name=English (United States),
I/flutter ( 8486): isDefault=true,
I/flutter ( 8486): }],
I/flutter ( 8486): name=afro-quiz,
I/flutter ( 8486): }
So I don't think this has anything to do with the installation.
I am using the contentful_dart 0.0.5 dependency

So what I finally did was go to the content delivery API references for java:
https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/content-type/query-entries/console/java
where i followed the example to query entries by content type
I modified the url below to fit my use case:
/spaces/{space_id}/environments/{environment_id}/entries?access_token={access_token}&content_type={content_type}
Final result:
Future getAllCategories(String spaceId,
String accessToken, String contentTypeId) async {
try {
final response = await _contentfulClient.client.get(
'https://$_baseUrl/spaces/$spaceId/environments/$_baseEnvironment
/entries?access_token=$accessToken&content_type=$contentTypeId');
return response.body;
} catch (exception) {
print(exception.message);
}
}
This finally worked for me.

Related

Google docs API: Width type must be provided when updating column width

I'm using the google docs API and trying to set the width of a table column using batchUpdate that includes this request:
{
'updateTableColumnProperties': {
'tableStartLocation': {
'index': my_table_index
},
'columnIndices': [my_column_index],
'tableColumnProperties': {
'widthType': "FIXED_WIDTH",
'width': {
'magnitude': my_width,
'unit': 'PT'
}
},
'fields': 'width'
}
}
But I'm getting an error back:
{
"error": {
"code": 400,
"message": "Invalid requests[4].updateTableColumnProperties: Width type must be provided when updating column width.",
"status": "INVALID_ARGUMENT"
}
}
This is confusing. I think I am specifying the widthType. Suggestions welcome.
The solution here is to specify widthType in fields:
BEFORE
'fields': 'width'
AFTER
'fields': 'width,widthType'
Here's the complete request:
{
'updateTableColumnProperties': {
'tableStartLocation': {
'index': my_table_index
},
'columnIndices': [my_column_index],
'tableColumnProperties': {
'widthType': "FIXED_WIDTH",
'width': {
'magnitude': my_width,
'unit': 'PT'
}
},
'fields': 'width,widthType'
}
}

Bad Request for an omitted field in GQL

I'm getting "Bad request" response with message "roleId must be a string" when running a mutation. I don't know why since the "roleId" field is optional.
Schema
input CustomerUpdateInput {
name: String
roleId: String
}
updateCustomer(customerId: String!, customer: CustomerUpdateInput!): Customer!
Mutation (ERROR)
mutation updateCustomer{
updateCustomer(customerId:"62c6d6ba303c734ef44ea4ed",
customer: {name:"Pablo"}
),
{id, name }
}
Mutation (WITHOUT ERROR)
mutation updateCustomer{
updateCustomer(customerId:"62c6d6ba303c734ef44ea4ed",
customer: {
name:"Pablo",
roleId:"62c6d64f303c734ef44ea4d8"
}
),
{id, name }
}
Error
{
"errors": [
{
"message": "Bad Request Exception",
"extensions": {
"code": "BAD_USER_INPUT",
"response": {
"statusCode": 400,
"message": [
"roleId must be a string"
],
"error": "Bad Request"
}
}
}
],
"data": null
}

400 Error in Terraform code when trying to loop a widget field multiple times

I have the following code which I am trying to implement for multiple widgets in a single cloud watch dashboard
` locals {
instances = csvdecode(file("${path.module}/sample.csv"))
}
resource "aws_cloudwatch_dashboard" "main" {
dashboard_name = "my-dashboard"
dashboard_body = jsonencode(
{
"widgets": [
for inst in range(length(local.instances)):[
// i want to repeat the below section as the length of instances variable but getting an error
{
"type":"metric",
"x":0,
"y":0,
"width":12,
"height":6,
"properties":{
"metrics":[ // trying to implement multiple widget in a single dashboard
enter code here
[
"AWS/EC2",
"CPUUtilization",
"InstanceId",
"${local.instances[inst].instance_id}"
]
],
"period":300,
"stat":"Average",
"region":"ap-south-1",
"title":"EC2 Instance CPU",
"annotations": {
"horizontal": [
{
"label": "Untitled annotation",
"value": 1.01
}]
} }
}
]]
})
} `
I am getting this error below error:
Error: Putting dashboard failed: InvalidParameterInput: The dashboard body is invalid, there are 4 validation errors:
[
{
"dataPath": "/widgets/0",
"message": "Should be object"
},
{
"dataPath": "/widgets/1",
"message": "Should be object"
},
{
"dataPath": "/widgets/2",
"message": "Should be object"
},
{
"dataPath": "/widgets/3",
"message": "Should be object"
}
]
status code: 400, request id: 706ac87c-a796-11e9-8983-65d87c7656b4
The code generates like below,
{
"widgets": [
[ // <--- It seems to be wrong.
{
"height": 6,
...
widgets has lists in a list. So modify like below,
jsonencode(
{
"widgets" : [ //removed [
for inst in range(length(local.instances)) :
{
...
"annotations" : {
"horizontal" : [
{
"label" : "Untitled annotation",
"value" : 1.01
}]
}
}
}
] // and removed ]
})
Remove nested list.

Why is the Op.not operator no longer working in Sequelize 4.41.0?

I recently upgraded many of the packages in my project, and since I did, the following query now fails:
query['where'] = { [Op.and]: [
sequelize.where(Database.getInstance().getConnection().col('id'), '!=', jsonObject['id'] ),
sequelize.where(Database.getInstance().getConnection().col('username'), jsonObject['username'])
]};
console.log('Check if username is unique...');
console.log(query);
It results in:
Unhandled rejection Error: Invalid value Where {
attribute: Col { col: 'id' },
comparator: '=',
logic: { [Symbol(not)]: 1563 } }
attribute: Col { col: 'id' },
I also tried:
query['where'] = { [Op.and]: [
sequelize.where(Database.getInstance().getConnection().col('id'), '!=', jsonObject['id'] ),
sequelize.where(Database.getInstance().getConnection().col('username'), jsonObject['username'])
]};
While following the docs, but it still resulted in an error:
Unhandled rejection Error: Invalid value Where { attribute: Col { col: 'id' }, comparator: '!=', logic: 1563 }

Loopback - how to obtain custom generated errors, as list of messages in response using validateAsync?

Here is my code to validate a model.
const loopback = require('loopback');
const {connectors, getDsnFormRules} = require('../../common/dsn');
const validator = require('indicative');
function validateConnectionPar(err, done) {
Promise.resolve().then(() => validator.validateAll(this, rules)
.then(result => done())
.catch(error => {
err(new Error(JSON.stringify(error)));
done();
});
}
module.exports = (Dsn) => {
Dsn.validateAsync('dsn', validateConnectionPar, {message: 'connection par are invalid'});
};
I am using indicative library to do validations. Object to be validated has structure like :
rules: {
'connector': 'required|string',
'dsnParams.host': 'required|string',
'dsnParams.port': 'required|integer|range:0,65536',
'dsnParams.username': 'required|string',
'dsnParams.password': 'required|string',
}
If there is some error, I get a response like :
{
"error": {
"statusCode": 422,
"name": "ValidationError",
"message": "The `dsn` instance is not valid. Details: `dsn` is invalid (value: undefined).",
"details": {
"context": "dsn",
"codes": {
"dsn": [
"custom.Error: [{\"field\":\"dsnParams.host\",\"validation\":\"required\",\"message\":\"required validation failed on dsnParams.host\"},{\"field\":\"dsnParams.port\",\"validation\":\"range\",\"message\":\"dsnParams.port must be in the range 0 to 65536 exclusive\"}]"
]
},
"messages": {
"dsn": [
"is invalid"
]
}
},
"stack": "ValidationError: The `dsn` instance is not valid. Details: `dsn` is invalid (value: undefined).\n at /home/bala/IRIS/Beginning/iris/node_modules/loopback-datasource-juggler/lib/dao.js:355:12\n at ModelConstructor.<anonymous> (/home/bala/IRIS/Beginning/iris/node_modules/loopback-datasource-juggler/lib/validations.js:577:13)\n at ModelConstructor.next (/home/bala/IRIS/Beginning/iris/node_modules/loopback-datasource-juggler/lib/hooks.js:93:12)\n at done (/home/bala/IRIS/Beginning/iris/node_modules/loopback-datasource-juggler/lib/validations.js:574:25)\n at /home/bala/IRIS/Beginning/iris/node_modules/loopback-datasource-juggler/lib/validations.js:652:7\n at Promise.resolve.then.then.catch.error (/home/bala/IRIS/Beginning/iris/server/models/dsn.js:17:7)\n at runMicrotasksCallback (internal/process/next_tick.js:58:5)\n at _combinedTickCallback (internal/process/next_tick.js:67:7)\n at process._tickCallback (internal/process/next_tick.js:98:9)"
}
}
When i return a new Error object to err() function, those errors are displayed as custom.Error in code.
Is there a way to obtain them as list of messages in
"messages": {
"dsn": [
"is invalid"
]
}
something like :
"messages": {
"dsn": [
"port": "is invalid",
"host": "required validation failed on dsnParams"
]
}

Resources