API Authentication issues from bubble to claifai - clarifai

I have built a Bubble App and need to integrate it with a application custom model I am building in Clarifai but when I use the Bubble API plugin to connect to do an image predict it says I have an authentication issue 10002
Bubble API header details
Bubble POST call
what am I doing wrong???

Please try using the following cURL command and replacing it with your variable. I have tested it on my side and it works. As for the Bubble issue, that is something you would need to contact their Support about. We are not sure how they are processing their requests but Bubble doesn't seem to able to handle API calls from Clarifai.
curl -X POST \
-H "Authorization: Key YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '
{
"inputs": [
{
"data": {
"image": {
"url": "https://samples.clarifai.com/metro-north.jpg"
}
}
}
]
}'\
https://api.clarifai.com/v2/models/{YOUR_MODEL_NAME}/outputs

Related

Add button to forward message from channel in Telegram

I'm not quite sure it's possible but probably someone did that. Is it possible to use bot for appending button to message user forwarded to bot? I mean:
Admin posted a message in his channel.
Admin forwarded message to bot (assume bot added in channel).
Bot appends to original message in channel with button.
So the answer is yes - it can be done with editMessageReplyMarkup API method:
curl
--request POST \
--url https://api.telegram.org/bot{BOT_SECRET_TOKEN}/editMessageReplyMarkup \
--header 'Content-Type: application/json' \
--data '{
"chat_id": {CHANNEL_ID},
"message_id": {CHANNEL_MESSAGE_ID},
"reply_markup": {
"inline_keyboard": [
[
{
"text": "Hello world!",
"url": "https://google.com"
}
]
]
}
}'

How do you specify the sourceBranch for a Run of Pipelines via the REST API?

I've been trying to run a pipeline for a particular branch of the repository I'm using.
In the UI, there is a convenient option, but I don't understand what to try in the request.
No matter what I do I always run from master.
How do I change that? I tried filling out the repository parameters but to no avail: https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run%20pipeline?view=azure-devops-rest-6.0#repositoryresourceparameters
Here is an example request:
curl --location --request POST 'https://dev.azure.com/<redacted>/<redacted>/_apis/pipelines/<redacted>/runs?api-version=6.0-preview.1' \
--header 'Authorization: Basic <redacted>' \
--header 'Content-Type: application/json' \
--header 'Cookie: VstsSession=<redacted>' \
--data-raw '{
"previewRun": true,
"resources": {
"repositories": {
"refName": "refs/heads/<redacted>"
}
},
"runParameters":
{
"namespace" : "<redacted>",
"image" : "<redacted>",
"tag" : "<redacted>",
"package" : "<redacted>",
"version" : "8.4.4"
}
}'
From your screenshot, it seems that you are using the YAML pipeline.
I have tested your example , and the root cause of this issue is that the request body(data-raw) has some issues.
You could try my sample
curl --location --request POST 'https://dev.azure.com/<redacted>/<redacted>/_apis/pipelines/<redacted>/runs?api-version=6.0-preview.1' \
--header 'Authorization: Basic <redacted>' \
--header 'Content-Type: application/json' \
--header 'Cookie: VstsSession=<redacted>' \
--data-raw '{
"stagesToSkip":[],
"resources":
{
"repositories":
{
"self":{"refName":"refs/heads/{Branchname}"}
}
},
"templateParameters":
{
"namespace":"{value}",
"image":"{value}",
"tag":"{value}",
"package":"{value}",
"version":"{value}"
},
"variables":{}
}'
Result:
For Http Request (you can test it with Postman)
1. Get pipeline api url like this
https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=7.1-preview.1
Source: https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run-pipeline?view=azure-devops-rest-7.1
Fill in your organization, project and pipelineId.
(all of this can be found in the link when you open your pipeline definition in Azure DevOps)
2. Add Basic Auth headers
key: Authorization, value:"Basic [your azure Person Access Token from Azure Dev Ops with Access to Pipeline goes here]"
Should look like this
"Basic OndzNWdz43FKfjdi98hjKDJFH8kkg9854HJKHF9D8RFEHui4387lkNXE="
And set content type to application/json
like this
key: Content-Type, value: application/json
3. Put this JSON Into Raw Body
{
"templateParameters":{
"inputName":"johnsmith"
},
"resources":{
"repositories":{
"self":{
"refName":"refs/heads/feature/#JIRATask01_Blabla"
}
}
},
"variables":{
}
}
Replace refName value with branch you want to run the pipeline for.
If you have multiple repo pipeline look into this topic (but i haven't tested that solution):
Azure DevOps API to Trigger Multi Repo changing branches

how to design dynamic response in mock server

I'm now using the mock server from https://www.mock-server.com/ and run it in a docker container.
Now I would like to let the response change as request body changes. I've looked up for dynamic response on official webiste for a while, but have no idea on how to extract specific data from request body.
curl -v -X PUT "http://localhost:1080/mockserver/expectation" -d '{
"httpRequest": {
"path": "/some/path"
},
"httpResponseTemplate": {
"template": "return { statusCode: 200, body: request.body };",
"templateType": "JAVASCRIPT"
}
}'
The code above is to create a simple expectation, which will response the request body. For example,
$curl http://localhost:1080/some/path -d '{"name":"welly"}'
{"name":"welly"} //response
Now I want to change the way of giving the response. For example, I would like to input {a:A, b:B} and get the response {a:B, b:A}.
So, how to modify the json data in request body and give it to response? I guess there are some methods to extract specific data from json file, or modify json data, etc. Also, I want to know how to better search the detailed information, since the official website and full REST API json specification
(https://app.swaggerhub.com/apis/jamesdbloom/mock-server-openapi/5.11.x#/expectation/put_expectation) is hard for me to understand.
Thanks a lot!
I needed to do this as well, I think I got this to work have a look at my curl example for the expectation I hope that helps:
curl -v -X PUT "http://localhost:1080/mockserver/expectation" -d '{
"httpRequest": {
"path": "/api/fun",
"method": "POST"
},
"httpResponseTemplate": {
"template": "
req = JSON.parse(request.body.string)
rid = req[\"id\"]
return { statusCode: 201, body: {new_id: rid} }
",
"templateType": "JAVASCRIPT"
}}'
After you do this if send:
curl -X POST http://localhost:1080/api/fun --data '{"id": "test_1"}'
it should return:
{ "new_id" : "test_1" }
Javascript templating supported via Nashorn engine and thus will no longer be available from Java 15. Here is the note from the Mockserver docs.
From Java 15 Nashorn is no longer part of the JDK but it is available as a separate library that requires Java 11+. Once MockServer minimum Java version is 11 then this separate library will be used.

How to invoke AWS lambda while running EventGateway locally

I am trying to invoke an AWS Lambda function from a locally running EventGateway (version: 0.9.1) instance. However, the subscription call is failing due to an "Event Type: http.request not found".
The lambda has been deployed independently using serverless framework, and the ARN has been injected in the registration call:
The lambda is just a hello world type of lambda listening for http request:
functions:
hello-world:
handler: bin/hello-serverless
events:
- http:
path: /hello
method: get
My function registration call looks like this:
curl --request POST \
--url http://127.0.0.1:4001/v1/spaces/default/functions \
--header 'content-type: application/json' \
--data \
'{"functionId": "helloserverless", "type": "awslambda", "provider":{ "arn": "<lambda-arn>", "region": "ap-southeast-2", "accessKeyId": "<my-access-key>", "secretAccessKey": "<my-secret-key"}}'
Now, when I try to subscribe to an event:
--url http://127.0.0.1:4001/v1/spaces/default/subscriptions \
--header 'content-type: application/json' \
--data '{"functionId": "helloserverless", "type": "sync", "path": "/hello", "method": "GET", "eventType": "http.request"}'
I get the following error:
{"errors":[{"message":"Event Type \"http.request\" not found."}]}
Any pointer to the right solution or working example is pretty much appreciated.
If you want to call a function like an endpoint you need to have your application running. There is a plugin called serverless-offline to help you on this.
In case you want to call your function using serverless options, the command is called INVOKE. https://serverless.com/framework/docs/providers/aws/cli-reference/invoke-local/

Using Taxee.io API

I'm trying to access the Taxee.io API using the request npm module. The documentation is slightly poor and the difference between the Mashape info and the website's info is confusing.
https://taxee.io/
The docs have one example of a request here.
curl 'https://taxee.io/api/v2/calculate/2017' -H 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJBUElfS0VZX01BTkFHRVIiLCJodHRwOi8vdGF4ZWUuaW8vdXNlcl9pZCI6IjU4NDQ4MTA4Mzg2NjhhMTU4ZDU0ZmIzNSIsImh0dHA6Ly90YXhlZS5pby9zY29wZXMiOlsiYXBpIl0sImlhdCI6MTQ5OTA1MzU0NX0.pOwC5JEC7trLaaZVgHHGu_rvN0-EGa3RMm8BgJ-M9gk' -H 'Content-Type: application/x-www-form-urlencoded' --data 'state=NC&filing_status=married&pay_periods=26&pay_rate=116500&exemptions=2'
I however want to use the request npm module and am struggling to bridge the gap in how it will work in my express app.
const request = require('request');
request.post('https://taxee.io/api/v2/calculate/2017', {
'auth': {
'Bearer': 'mykey'
}
});
This is what I have thus far. Any help is appreciated.
Keep in mind that properties are case sensitive in JavaScript. You must pass the bearer token under the key bearer and not Bearer.
To replicate the Content-type and pass data, use the form support of the library.
E.g. like this:
{
auth: {
bearer: '<token>',
},
form: {
state: 'NC',
// ...
},
}