Is it possible to pass AWS EventBridge rule event variables to the target Invocation HTTP Parameters? - aws-event-bridge

I am pretty sure I miss something simple but I don't seem to fins any resource on my issue and I am a novice on AWS.
The problem is as follows: I have a scenario where I would like to trigger a REST POST API when files are uploaded to an S3 bucket. This POST API uses OAuth 2.0 and requires the file name in the body.
I created a rule that successfully triggers on upload and the API works well if I put a static filename as Invocation Http Parameter. But I would like this value to be dynamic, based on the file that triggers the event.
I have tried using the jQuery snippet $.detail.object.key but, as much as it works for adding a Query Parameter from the rule, it doesn't seem to work if used in the Invocation Http Parameters settings in the API connection.
The event pattern is as follows:
{
"source": ["aws.s3"],
"detail-type": ["Object Created"],
"detail": {
"bucket": {
"name": ["jna-test-bucket"]
},
"object": {
"key": [{
"prefix": "testFileForAPI"
}]
}
}
}

Related

Unable to authenticate on Crypto.com API C# REST API

Crypto.com offers an API where supposedly you could access their exchange platform. However, their documentation is extremely poor and inaccurate in terms of C# examples. I am unable to authenticate my REST calls using C#.
For all the private (account related) calls you need to sign your requests by adding a sig parameter to your payload JSON.
A simplified version of my code that calculates the sig parameter for the private/get-account-summary method looks like this (.net50):
private static string GetSignature()
{
string sigPayload = "private/get-account-summary" + 1 + API_KEY + "currencyCRO" + DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
var hash = new HMACSHA256(Encoding.UTF8.GetBytes(API_SECRET));
var computedHash = hash.ComputeHash(Encoding.UTF8.GetBytes(sigPayload));
return Convert.ToHexString(computedHash);
}
, while the request which makes use of this signature looks like this:
POST https://api.crypto.com/v2/private/get-account-summary
{
"id": "1",
"method": "private/get-account-summary",
"api_key": "[api_key]",
"params": {
"currency": "CRO"
},
"nonce": "1615048530368",
"sig": "1A7C7183CAF2E71F7F7DAB6A5C7F74319E692F2638710292BDB4FDFAC6C864D6"
}
As far as I know, I've correctly applied their algorithm for creating the signature and also used the correct parameters to call the method in question (https://exchange-docs.crypto.com/spot/index.html#private-get-account-summary). However, the response that I get tells me that I'm doing something wrong:
{
"id": 1,
"method": "private/get-account-summary",
"code": 10002,
"message": "UNAUTHORIZED"
}
I'm starting to have doubts that the API even works for private methods. Their support is awful and sent me to read the documentation again. I would appreciate any help in any language. If I at least hear that somebody else did it in another language I could use their example to figure out what I'm doing wrong.
The last line in the sample needs to be changed like this:
Convert.ToHexString(computedHash).ToLower();
In the end I followed my own advice and tried to call the service using one of the other sample languages. When I used JavaScript (which had a way better sample in the documentation) I've noticed the the resulting sig was lower case.

Cumulocity SmartREST GET Template using MQTT

I am trying to receive a response using a custom GET template implemented on the Cumulocity UI however I'm having some trouble. I have defined my message template like so:Message Template and my response template like so: Response template.
At the moment when I publish to topic 's/uc/template1' (where template1 is my X-ID) with the payload of '999, 12345'(where 12345 is my External ID), no response is received and no error is found. The speeds are known to exist in the object because when I request a GET command to {{url}}/inventory/managedObjects this responds with:
"speed": {
"1": {
"unit": "m/min",
"value": 1
},
"2": {
"unit": "m/min",
"value": 1
}
I've also followed this post where #TyrManuZ suggests to add c8y_Global: {} to the application. I have done this through a PUT request to {{url}}/inventory/managedObjects/{{deviceId}} on Postman and can verify that c8y_Global: {} exists there.
Is there something I am doing wrong, and if so what is the correct way? Any help would be greatly appreciated!

Documenting error codes definition in Swagger API contract

Imagine you are working under following circumstances:
You have REST API modules with API documentation generated into swagger-ui.html
Possible HTTP status codes for endpoints are documented well via io.swagger.annotations.* on controller method level for each endpoint.
In case of some error state (4XX or 5XX) application replies with ErrorResponseDTO with structure like
"ErrorResponseDTO": {
"type": "object",
"properties": {
"errorCode": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
}
}
}
Application have tens of errorCodes (within range like 1 - XX and please consider them as a legacy definiton without an easy way to change them).
List of errorCodes is relevant for the whole application so you prefer to keep their definiton list/table in overall API documentation rather then maintaining errorCodes definiton for each API endpoint separately.
Now you are looking for an effective way how to document these application error codes into API contract.
The approach of including a list of errorCodes with codes description into generated swagger-ui.html seems like a better way to keep API documentation up to date instead of having static and handwritten codes definition table attached in Markdown format in some Readme file.
Would you please have any recommendation how to document various codes which your applications produce?
Do you follow some specific good practice in this topic?
Thank you in advance.
Meanwhile within a small internal dev team and with frequent API extensions there can be used generated swagger-ui with included error codes:
#Bean
public Docket swaggerSettings() {
ApiSelectorBuilder builder = new Docket(DocumentationType.SWAGGER_2)
.apiInfo(
new ApiInfoBuilder()
.title("Response errorCodes table")
.description(RestResponse.generateErrorsDocumentation().toString())
.build()
)
...
.select();
return builder.apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
.paths(PathSelectors.any())
.build()
.useDefaultResponseMessages(false);
}

How to send a device management request using NodeRed or any REST client

I am trying to sent a DM firmware update command from a NodeRed Flow.
Function node:
msg.payload = {"MgmtInitiationRequest": {
"action":"firmware/update",
"devices": [{
"typeId": "myType",
"deviceId": "myDevice"
}]
}}
msg.headers={"Content-Type":"application/json"}
return msg;
I send it to a http request node with a POST to
https://orgid.internetofthings.ibmcloud.com/api/v0002/mgmt/requests
Basic Authentication with api keys. I based it of Initiate a device management request
I get back a 403 which the docs have as:
One or more of the devices does not support the requested action
Anyone see what I'm missing? It works fine from the IoT Platform UI to the same devicetype/deviceid.
EDIT: Same 403 if I use a Rest client like Postman.
The swagger API documentation is a little bit misleading in that the 'body' parameter is given a name.
But, like the other POST APIs, that name isn't actually included anywhere as part of the payload.
The payload should just look like this:
{
"action": "firmware/update",
"devices": [
{
"typeId": "string",
"deviceId": "string"
}
]
}
This page in the documentation provides more detail:
https://console.ng.bluemix.net/docs/services/IoT/devices/device_mgmt/requests.html#firmware-actions-update
Has your appliance published the set of supported commands it supports when it announced itself as a managed device?
A device connects to the Watson IoT Platform and uses the managed devices operation to become a managed device.
Which looks something like this
Topic: iotdevice-1/mgmt/manage
{
...
"supports": {
"deviceActions": true,
"firmwareActions": boolean
},
...
},
...
}
https://console.ng.bluemix.net/docs/services/IoT/devices/device_mgmt/index.html

"additional properties" error in Survey Monkey API call

I'm trying to use the create_flow endpoint to the Survey Monkey API. It is sending back a status 3 message with the following error:
additional properties not defined by 'properties' are not allowed in field '_data'
I'm able to do successfully use all other API endpoints and have a valid API key and durable OAuth token.
Here's an example JSON body that I'm sending to: https://api.surveymonkey.net/v2/batch/create_flow?api_key=apikeyhere
{
"survey": {
"template_id": "566",
"survey_title": "test1",
"collector": {
"type": "email",
"name": "collector1",
"recipients": [
{
"email": "email#example.com"
}
]
},
"email_message": {
"reply_email": "myemail#example.com",
"subject": "this is a test"
}
}
Note: JSON formatting here is being generated automatically using RJSONIO
Any ideas what might be causing the error? It seems like all fields are correctly named and where they're supposed to be, so I'm not sure what the problem is.
It's a bad error message unfortunately - it's a known issue. It means you are providing extra keys that are not part of the create_flow schema.
The issue here is that the "email_message" and "collector" keys have been nested inside of "survey", instead of being in the main JSON body like the "survey" key. Move them out a level and it should work.

Resources