Service Fabric Client REST API - Syntax for parameters in body - azure-service-fabric

I'm trying to use the client rest api to upgrade an application. I can get the application types, version etc using the api but I'm struggling when trying the "Start Application Upgrade". The problem looks like it's with the encoding of the Application Upgrade Description, all the ways I've tried I can't get past
{
"Error": {
"Code": "FABRIC_E_INVALID_NAME_URI",
"Message": "Invalid name URI."
}
}
I could be way off but I'm using JSON format like below for the body:
{
"ApplicationUpgradeDescription":{
"Name":"fabric:/twinpeaks",
"TargetVersion":"1.0.1",
…..other params as per spec
}
Any pointers?
Cheers

Close but not quite.. The body just needs to be:
{
"Name":"fabric:/twinpeaks",
"TargetApplicationTypeVersion":"1.1.0",
….. etc
}
Once I made this change the upgrade was accepted, all good.

Related

Facebook Marketing API returns error on "breakdowns call"

I'm trying to make an API call with the folowing URL
act_XXXXXXXX/insights?fields=ad_id,clicks,unique_clicks,impressions,reach,spend,date_start,date_stop,actions,action_values,unique_actions,account_id&level=ad&breakdowns=platform_position&time_range={"since":"2019-09-07","until":"2019-09-07"}
and the response is :
{
"error": {
"message": "(#100) Current combination of data breakdown columns (action_type, platform_position) is invalid ",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "XXXXXXXXXXXXXXXXXXXX"
}
}
the reason is in "breakdown" value = "platform_position"
but the problem is that I need exactly that breakdown :(
when I do an API call and change "breakdown" in URL to something else, for example to "publisher_platform":
act_XXXXXXX/insights?fields=ad_id,clicks,unique_clicks,impressions,reach,spend,date_start,date_stop,actions,action_values,unique_actions,account_id&level=ad&breakdowns=publisher_platform&time_range={"since":"2019-09-07","until":"2019-09-07"}
it is OK and responds with data.
I don't know why it happens because I'm not specifying any "action_type" breakdown but it tells that I am :(
What I've tried:
I tried to remove all the parameters from that URL one by one but it still returns an error
The main questions are: why the API call for "breakdown" value = "platform_position" fails and how to make it work.
Thanks.
PS: you can use FB API testing tool to test requests to FB api.
I'm using API version v8.0
You will need both publisher and position:
breakdowns=publisher_platform,platform_position

Please guide me about my Yii2 code about RESTFul authentication by token

I have been look around google whole day and still not getting idea how to achieve RESTFul httpBasicAuth by using token.
First, I would like to ask can i using RESTFul HttpBasicAuth without Https ?
Then, below is my code to try to do Yii2 RESTFul HttpBasicAuth authenticaton, hope someone can spend some time review on my code and guide me what wrong on my code.
First this is my yii2 config setting about User Application component:
'user' => ['identityClass' => 'common\models\Users',
'enableAutoLogin' => false
],
then below is snippet of my common\models\Users IdentityClass
namespace common\models;
use Yii;
use yii\base\NotSupportedException;
use yii\web\IdentityInterface;
use app\models\Ostoken;
class Users extends \yii\db\ActiveRecord implements IdentityInterface
{
public static function findIdentityByAccessToken($token, $type = null) {
/* Compulsory for RESTFul*/
// die("trying...");
// throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
file_put_contents("/var/www/html/y2api/logs/RESTFul_login_".date("Y-m-d"), date("H:i:s").":".$token."\r\n", FILE_APPEND);
$apiUser = Ostoken::find()
->where(['token' => $token])
->one();
return static::findOne(['username' => $apiUser->username]);
}
}
then I try to call the restful URL by http://192.168.33.10/api/Banktransactions?access-token=xxxxxxxx
then i get following error in json format :
{
"name": "Unauthorized",
"message": "Your request was made with invalid credentials.",
"code": 0,
"status": 401,
"type": "yii\\web\\UnauthorizedHttpException"
}
as you can see I put a file_put_contents in findIdentityByAccessToken but it never execute.
First question:
First, I would like to ask can i using RESTFul HttpBasicAuth without Https ?
Answer: You can, but:
Since an access token can be used to uniquely identify and authenticate a user, API requests should always be sent via HTTPS to prevent man-in-the-middle (MitM) attacks. (https://www.yiiframework.com/doc/guide/2.0/en/rest-authentication#authentication)
Second...question?:
I'm 100% sure this is because CORS.
Check out this:
https://www.yiiframework.com/doc/api/2.0/yii-filters-cors
Ever tried to reach the url through localhost? If so and it worked then you need to set up a CORS filter to be able to make a request to your server.

Setting up daily notifications for a Google Assistant App via DialogFlow

I apologize if this is a stupid question. I have been spending quite a while trying to get daily updates for my google assistant app to work (found at https://developers.google.com/actions/assistant/updates/daily).
I get the prompt on my phone to initiate the daily updates because my server gets the configure updates event. However, I think I am not sending the correct response back because I just get the error "UnparseableJsonResponse: API Version 2: Failed to parse JSON response string with 'INVALID_ARGUMENT' error: ": Cannot find the field."
Usually, my server just responds with a JSON in the structure:
return{
"speech": 'sample text',
"DisplayText": 'sample text',
"source": "sample"
}
However, according to the Google documentation, I need to return the JSON
{
"conversationToken":"",
"expectUserResponse":true,
"expectedInputs":[
{
"inputPrompt":{
"initialPrompts":[
{
"textToSpeech":"PLACEHOLDER_FOR_REGISTER_UPDATE"
}
],
"noInputPrompts":[
]
},
"possibleIntents":[
{
"intent":"actions.intent.REGISTER_UPDATE",
"inputValueData":{
"":"",
"intent":"tell.tip",
"triggerContext":{
"timeContext":{
"frequency":"DAILY"
}
},
}
}
]
}
]
}
I tried returning this exact JSON but as I suspected it's not that simple. I'm not sure how to adapt this format to one that dialogflow expects. Any help would be much appreciated. Note that I'm looking at the response structure at https://dialogflow.com/docs/fulfillment. I also considered the actions on google structure too at https://developers.google.com/actions/reference/rest/Shared.Types/AppResponse. I'm just very confused on how to do this since the guide is mostly suited for people using node js and the SDK.

I keep getting error 422 when trying to start process instance using REST API

I'm trying to use the REST API, from Postman REST client on Chrome.
Here's my screenshot:
I keep getting error 422: "The server understands the content type of the request entity and the syntax of the request entity is correct but was unable to process the contained instructions".
I'm using Activiti 5.16.3 on MacOS Maverick, with Java 1.8.
The process I tried to call is the one that comes with the demo of Activiti, Vacation Request.
The JSON payload in my request is:
{
"processDefinitionKey":"vacationRequest",
"variables":[
{"name": "employeeName", "value": "Raka","type":"string"},
{"name": "numberOfDays", "value": "5", "type":"integer"},
{"name": "vacationMotivation", "value": "", "type":"string"},
{"name": "startDate", "value": "01-01-2014 11:11", "type":"date"}
]
}
Oh, and I had to add a header "Content-Type" with its value set to "application/json" (otherwise I'd get error code 415: "The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method").
What am I missing?
Btw, I need to be able to demonstrate the use of the REST API through tools like Postman. So, no Java code. It's because another programmer (front-end) will interact directly with Activiti bpm.
Thanks in advance for your help. This is really critical.
**
Additional comments:
I didn't have issue with other REST methods that are GET (for example: listing process definitions, etc). Looks like I'm only having trouble with POST (and maybe PUT too).
Not much info on this on google: https://www.google.com/search?as_q=rest+422&as_epq=&as_oq=&as_eq=&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all&as_sitesearch=http%3A%2F%2Fforums.activiti.org&as_occt=any&safe=images&as_filetype=&as_rights=&gws_rd=ssl
I've tried also this suggestion. Didn't work for me: http://forums.activiti.org/comment/23039#comment-23039
**
Best regards,
Raka
Solved now....
Looks like there should be no whitespace between the opening { and the rest of the document.
Here's my screenshot:

REST Web Service API: upload/update report template

I want to store and deploy report template with my code.
With this one in mind running a report is a two step process:
upload or update existing report template jrxml (it does not have links to other resources like images)
run it with my data (this one is done)
The official documentation doesn't contain a minimal example for updating report template
What is raw request which uploads/updates report template xml via JasperReports Server REST API?
I tried this way
here is my raw request
here is response
here what I see in /var/lib/tomcat6/webapps/jasperserver/WEB-INF/logs/jasperserver.log
What am I doing wrong? What does 400 error: could not find the binary content for resource: /Reports/product_structures_workshops mean?
This works for Jasper 5.5+ (but does not for 5.1-, returns just 404 Not Found "Specified page not found" instead).
Uploading
POST http://your-host:port/jasperserver/rest_v2/resources/path/to/resource/
Content-Type: application.repository.reportUnit+json
{
"label": "Sample",
"jrxml": {
"jrxmlFile": {
"label": "MyJRXML",
"type":"jrxml",
// encode your file in Base64 and put here
"content": "PD94bWwg..."
}
}
}
Updating
PUT http://your-host:port/jasperserver/rest_v2/resources/path/to/resource/myReport/
Content-Type: application.repository.reportUnit+json
{
"label": "Sample",
"jrxml": {
"jrxmlFile": {
"label": "MyJRXML",
"type":"jrxml",
// encode your file in Base64 and put here
"content": "PD94bWwg..."
}
}
}
References:
https://community.jaspersoft.com/questions/822949/example-creating-report-resource-rest-v2
http://community.jaspersoft.com/sites/default/files/docs/jasperreports-server-web-services-guide.pdf
We ended up with writing proprietary local JAVA application with jasper libraries, which does same thing
It looks like this is doable in older jasper versions (> 5.2):
they simplified significally REST API (look for API v2)
https://community.jaspersoft.com/wiki/getting-started-rest-web-service-api
With the completion of the v2 REST API, Jaspersoft announces the
deprecation of the original REST API and the end-of-life of the SOAP
services