AppSync resolver: Trailing characters at the end of the JSON string are not allowed - aws-appsync

When creating a custom AppSync resolver, it is saved and well deployed but when I request the API I get this response.
I have absolutely no chars after the last bracket. What's wrong ?
{
"data": null,
"errors": [
{
"path": [
"listUsers"
],
"data": null,
"errorType": "MappingTemplate",
"errorInfo": null,
"locations": [
{
"line": 2,
"column": 3,
"sourceName": null
}
],
"message": "Trailing characters at the end of the JSON string are not allowed."
}
]
}

My bad, I only had a duplicate bracket in my mapping template. The console doesn't tell anything for these cases and you only have the error at runtime.

I can confirm that this error happens when a rogue character in your Velocity template.
Somehow I copied and pasted the template into my cloud formation template with a curly bracket at the end.
Thanks to this question I found it.

Related

not being able to add dynamic expression to .json

do you see why I see the error when using the #guid() inside the below .json in the web activity of data factory
[
{
"id":#{guid()}
, "subject": "data/company"
, "topic": null, "eventType": "statusupdated"
, "eventTime": "2022-07-26T09:41:00.9584103Z", "data": { "firstName": "testname", "salary": "test" }, "dataVersion": "1.0", "metadataVersion": null
}
]
error when debug is run:
{"error":{"code":"InvalidRequestContent","message":"The request content is not valid and could not be deserialized: 'Unexpected character encountered while parsing value: b. Path '[0].id', line 2, position 5.'."}}
As the error message The request content is not valid and could not be deserialized: 'Unexpected character encountered while parsing value: b. Path '[0].id', line 2, position 5 indicates, the issue is with the content.
While parsing the JSON, it encountered an unexpected character. This is because of the value of the key id that is #{guid()}. You can validate the json using this third-party validator which indicates the same.
The main issue is the incorrect usage of String Interpolation (#{...}). This feature is used when we need to utilize pipeline expressions inside a string.
But here you have used it directly inside a json as a value for key (id). You can try correcting this by enclosing #{guid()} inside Double quotes ("") to make it a valid JSON (can be checked using the above third-party validator) as shown below:
[
{ "id": "#{guid()}" , "subject": "data/company" , "topic": null, "eventType": "statusupdated" , "eventTime": "2022-07-26T09:41:00.9584103Z", "data": { "firstName": "testname", "salary": "test" }, "dataVersion": "1.0", "metadataVersion": null }
]

IBM Watson Assistant: Where to set output.user_defined object in JSON editor?

IBM Watson Assistant apidoc v2 says that output.user_defined as
"An object containing any custom properties included in the response. This object includes any arbitrary properties defined in the dialog JSON editor as part of the dialog node output."
But it does not say where in JSON editor to set it up. Is it under output?
{
"output": {
"text": {
"values": [],
"selection_policy": "sequential"
},
"xxx": "aaa"
},
"context": {}
}
Can't set it to root level in JSON editor as the editor would complain that only output, output.generic, actions, context are allowed.
Where should I put it in JSON editor so that it appears in output.user_defined in response to /message REST call?
You can move that into the output section as user_defined. Here is what I tried:
"output": {
"text": {
"values": [],
"selection_policy": "sequential"
},
"user_defined": {
"test": "henrik"
}
}
I then used the V2 API of my test tool to verify. Here is the relevant part of how it was reported:
"output": {
"generic": [
{
"text": "Ok, checking the event information.",
"response_type": "text"
},
{
"text": "ok.",
"response_type": "text"
}
],
"debug": {...
},
"intents": [...
],
"user_defined": {
"test": "henrik"
},
"entities": [
{...
See also this section in the IBM Watson Assistan documentation with some more information on the response JSON.
As #data_henrik stated above, extra json elements added via the JSON editor to the output section of the response are moved into the user_defined section of the V2 output response.
These "extra" json elements do not have to be labelled user_defined. In my own case I have output.extra elements within my dialog responses. In V1 they remain output.extra, but in V2 they become output.user_defined.extra.
As you are just starting, it would be best to keep consistent and use output.user_defined as your starting point.

Creating a domain in Plesk's REST API

So, experimenting with Plesk's REST API (available as of version 17.8) for a project at work, and I'm starting to get a feel for it. I've been trying to experiment with adding a domain, but it's been giving me errors when I have to specify the hosting type.
The request body itself is as follows:
{
"name":"example.com",
"hosting_type":"virtual",
"description":"Description goes here"
}
This gets the following cryptic response:
{
"code": 1014,
"message": "htype\/vrt_hst is specified but there is no hosting\/vrt_hst"
}
Per the documentation provided at /api/v2/swagger.yml, any of the following values should be allowed: virtual, standard_forwarding, frame_forwarding, none
No matter what I put in, however, I get a variant of the response above (htype\/{type} is specified but there is no hosting\/{type}).
At this point I'm kind of stuck; I'm not sure what to check, and any references when I try to look up the error code go to references on Plesk's XML API instead. What's the missing link here needed to get the request to work?
It looks like system user is not specified - hosting_settings. Try to add domain with full json request. Here is example:
{
"name": "example.com",
"description": "My website",
"hosting_type": "virtual",
"hosting_settings": {
"ftp_login": "test_login",
"ftp_password": "test_pwd"
},
"base_domain": {
"id": 7,
"name": "a10-52-41-48.qa.plesk.ru",
"guid": "b623e93d-dc72-4102-b5f0-ded427cf0fb1"
},
"parent_domain": {
"id": 7,
"name": "a10-52-41-48.qa.plesk.ru",
"guid": "b623e93d-dc72-4102-b5f0-ded427cf0fb1"
},
"owner_client": {
"id": 7,
"login": "a10-52-41-48.qa.plesk.ru",
"guid": "b623e93d-dc72-4102-b5f0-ded427cf0fb1",
"external_id": "b623e93d-dc72-4102-b5f0-ded427cf0fb1"
},
"ipv4": [
"212.192.122.46"
],
"ipv6": [
"2002:5bcc:18fd:c:123:123:123:123"
],
"plan": {
"name": "Unlimited"
}
}
Examples for REST API https://app.swaggerhub.com/apis/plesk/api/v2#/Domains/post_domains

Google Fit REST API - dataStreamId with whitespace results in error

I want to use Google's REST API to get the Fitness data of my account. To do so i issue 2 subsequent calls.
GET https://www.googleapis.com/fitness/v1/users/me/dataSources. This returns a list of all available dataSources as in [1].
POST https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate.
I use the dataType name and dataStreamId in the request body from [1] to build the request body [2].
The problem: The second call returns an error [3] for all dataSourceIds that contain whitespace although they were returned exactly that way in the first request. In the code sample there is whitespace because the dataSourceId contains the phone model "Nexus 5". If there is no whitespace, the request succeeds without errors.
I already tried replacing the space by something else ("%20" or "_" or "+") but nothing helped. Is this a bug in the API or am i doing something fundamentally wrong?
Thanks in advance!
Edit 1:
btw i am using Google's oauth-playground with all the fitness scopes selected.
https://developers.google.com/oauthplayground/
Edit 2:
In code sample [2] i used the wrong dataTypeName. Was "activity_confidence" but should be "com.google.activity.samples".
[1] GET response
{
"dataSource": [
{
"application": {
"packageName": "com.google.android.gms"
},
"dataQualityStandard": [
],
"dataStreamId": "derived:com.google.activity.samples:com.google.android.gms:LGE:Nexus 5:c80045fc:detailed",
"dataStreamName": "detailed",
"dataType": {
"field": [
{
"format": "map",
"name": "activity_confidence"
}
],
"name": "com.google.activity.samples"
},
"device": {...},
"type": "derived"
},
...
]
}
[2] POST body
{
"aggregateBy": [
{
"dataSourceId": "derived:com.google.activity.samples:com.google.android.gms:LGE:Nexus 5:c80045fc:detailed",
"dataTypeName": "com.google.activity.samples"
}
],
"endTimeMillis": 1511132400000,
"startTimeMillis": 1510268400000
}
[3] POST Error message
{
"error": {
"code": 400,
"errors": [
{
"domain": "global",
"message": "datasource not found: derived:com.google.activity.samples:com.google.android.gms:LGE:Nexus 5:c80045fc:detailed",
"reason": "invalidArgument"
}
],
"message": "datasource not found: derived:com.google.activity.samples:com.google.android.gms:LGE:Nexus 5:c80045fc:detailed"
}
}
Did you try using a escape character like '\'?
Your data stream ID would look like
derived:com.google.activity.samples:com.google.android.gms:LGE:Nexus\ 5:c80045fc:detailed

Validate referential integrity of object arrays with Joi

I'm trying to validate that the data I am returned it sensible. Validating data types is done. Now I want to validate that I've received all of the data needed to perform a task.
Here's a representative example:
{
"things": [
{
"id": "00fb60c7-520e-4228-96c7-13a1f7a82749",
"name": "Thing 1",
"url": "https://lolagons.com"
},
{
"id": "709b85a3-98be-4c02-85a5-e3f007ce4bbf",
"name": "Thing 2",
"url": "https://lolfacts.com"
}
],
"layouts": {
"sections": [
{
"id": "34f10988-bb3d-4c38-86ce-ed819cb6daee",
"name": "Section 1",
"content:" [
{
"type": 2,
"id": "00fb60c7-520e-4228-96c7-13a1f7a82749" //Ref to Thing 1
}
]
}
]
}
}
So every Section references 0+ Things, and I want to validate that every id value returned in the Content of Sections also exists as an id in Things.
The docs for Object.assert(..) implies that I need a concrete reference. Even if I do the validation within the Object.keys or Array.items, I can't resolve the reference at the other end.
Not that it matters, but my context is that I'm validating HTTP responses within IcedFrisby, a Frisby.js fork.
This wasn't really solveable in the way I asked (i.e. with Joi).
I solved this for my context by writing a plugin for icedfrisby (published on npm here) which uses jsonpath to fetch each id in Content and each id in Things. The plugin will then assert that all of the first set exist within the second.