App Center. How launch creating a new one build via ps1 (PowerShell)? - xamarin.forms

If I created builds from Bitrise, I can launch builds via ps1.
for example:
$postParams = '{"hook_info":{"type":"bitrise","api_token":"AQKgU--wYxRIqpZqAkIJ1A"},"build_params":{"branch":"develop"}}' $result = Invoke-WebRequest -Uri https://www.bitrise.io/app/32363315d0fd1/build/start.json -Method POST -Body $postParams
How implement it for App Center? Thx.

The following powershell syntax can be used to create new builds in App Center, just replace the variables with your own. The url of your app will contain the user and app variables. You can create an api token in your account settings.
$branch = 'master'
$user = 'exampleUser'
$app = 'exampleApp'
$token = '1234567a7c13234567c9f512346'
Invoke-WebRequest -Uri "https://api.appcenter.ms/v0.1/apps/$($user)/$($app)/branches/$($branch)/builds" -Method "POST" -Headers #{"Accept"="application/json"; "X-API-Token"="$($token)"; "Content-Type"="application/json"};

Related

Use Powershell to download attached excel file from Servicenow ticket

I'm currently working on a powershell script that should be able to download an attached excel file from a service now ticket, before I explain more please see the basic flow of the automation below.
The user will be asked to enter the ticket number.
The system will then find that incident ticket to accurately get the excel file needed(I saw online that I need to use sys_id).
It will then be downloaded to a specific path on the user's machine. ex: "C:\downloads\Demo\".
Following all this, I found a sample script online that I'm trying to configure to match my needs; however, I'm not sure where to get the values on that sample script. You can check the bullets below the script for the questions I have in mind.
$IncidentNumber = Read-Host -Prompt 'Enter Incident Request #'
#$admin = "admin"
#$password = "admin" | ConvertTo-SecureString -AsPlainText -Force
#$Credential = New-Object pscredential -ArgumentList ($admin,$password)
$Uri = "https://dev42835.service-now.com/api/now/table/incident?sysparm_query=number=$($IncidentNumber)&sysparm_fields=sys_id&sysparm_limit=1"
$IncidentResult = Invoke-RestMethod -Uri $Uri #-Method Get -Credential $Credential
if($IncidentResult.result.sys_id -ne $null) {
$IncidentAttachments = Invoke-RestMethod -Uri "https://dev42835.service-now.com/api/now/attachment?sysparm_query=table_sys_id=$($IncidentResult.result.sys_id)" #-Method Get -Credential $Credential
$IncidentAttachments.result | Select file_name , download_link
}
else{
"Incident Not Found!"
}
Do I really need the credentials to run the script? If yes, is there a way to
remove the need of the credentials?
Where can I get the URL that is assigned to the $URI variable?
I'm new to powershell automation so I would appreciate it if you can recommend better approach if there are any.
Yes, you need credentials but don't hard code them like that. Instead you can use built-in method Get-Credential that will securely collect your username and password. The user will have to enter their own ServiceNow credentials each time this is run.
My version only has one thing you need to configure, the $SubDomain variable which is specific to your tenant.
$SubDomain = "YourServiceNowSubdomaingoeshere" # Configure this per tenant
$Credential = Get-Credential
If(!$Credential){
# User Cancelled
exit 1
}
$IncidentNumber = Read-Host -Prompt 'Enter Incident Request #'
$Uri = "https://$SubDomain.service-now.com/api/now/table/incident?sysparm_query=number=$($IncidentNumber)&sysparm_fields=sys_id&sysparm_limit=1"
$IncidentResult = Invoke-RestMethod -Uri $Uri -Method Get -Credential $Credential
if($IncidentResult.result.sys_id -ne $null) {
$IncidentAttachments = Invoke-RestMethod -Uri "https://$SubDomain.service-now.com/api/now/attachment?sysparm_query=table_sys_id=$($IncidentResult.result.sys_id)" -Method Get -Credential $Credential
$IncidentAttachments.result | Select file_name , download_link
}
else{
"Incident Not Found!"
}
Yes you need credentials.
Your URI is the URL of your servicenow instance. Change the dev42835 portion to match. If you're unsure of your instance, contact servicenow support.
https://dev42835.service-now.com
If you use the REST API explorer, you can view API endpoints and versions which will help with forming your requests. You do need to have the rest_api_explorer role to access the REST API Explorer. If you do not have this role, contact your service-now admin requesting it.
https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/integrate/inbound_rest/task/t_GetStartedAccessExplorer.html

How to execute an API PUT method that has [[FromForm]] argument in powershell

My API has a PUT method that update a reservation object.
[HttpPut]
public Reservation Put([FromForm] Reservation res) =>
repository.UpdateReservation(res);
I just want to know how can i execute this method in powershell using package manager console in Visual studio?
Note that this method has [FromForm] model binding method. So I have to send the Reservation data in form data.
I know that if this method had [FromBody] attribute instead of [FromForm] then I can do the following command on powershell.
Invoke-RestMethod http://localhost:8888/api/Reservation -Method PUT
-Body (#{Id="5"; Name="Mary"; StartLocation="Tokyo"; EndLocation="Abu Dhabi"} |
ConvertTo-Json) -ContentType "application/json"
But i want to know what will be the command for [FromForm] attribute, please help?
The FromForm attribute is for incoming data from a submitted form sent by the content type application/x-www-url-formencoded.
Therefore, set the contentType to application/x-www-url-formencoded.
Try it like this
$url = "http://localhost:8888/api/Reservation";
$body = #{Id="5"; Name="Mary"; StartLocation="Tokyo"; EndLocation="Abu Dhabi"};
Invoke-RestMethod -Uri $ClipsURL -Body $body -Method Put -ContentType "application/x-www-form-urlencoded"

Google Analytics API using PHP with service account

I have been searching and looking this up for two days now and can't figure out where I am going wrong. I am attempting to pull data from my google analytics account using php. I have followed all the steps to set up a service account and downloaded the JSON file. Here is the code I am using:
// Load the Google API PHP Client Library
require_once ('/google-api-php-client-1-master/src/Google/autoload.php');
$KEY_FILE_LOCATION = '/inc/ac_key.json';
// Create and configure a new client object.
$client = new Google_Client();
$client->setApplicationName("Hello Analytics Reporting");
$client->setAuthConfig($KEY_FILE_LOCATION);
$client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']);
$analytics = new Google_Service_Analytics($client);
function getResults($analytics, $profileId) {
// Calls the Core Reporting API and queries for the number of sessions
// for the last seven days.
return $analytics->data_ga->get(
'ga:' . $profileId,
'30daysAgo',
'today',
'ga:pageviews'
);
}
$profile = $r['google_analytics'];
$results = getResults($analytics, $profile);
$month = date('n');
$year = date('Y');
$results->setMonth($month,$year);
$visits = $results->getVisitors();
$views = $results->getPageviews();
/* build tables */
if(count($visits)) {
foreach($visits as $day=>$visit) {
$flot_datas_visits[] = '['.$day.','.$visit.']';
$flot_datas_views[] = '['.$day.','.$views[$day].']';
}
$flot_data_visits = '['.implode(',',$flot_datas_visits).']';
$flot_data_views = '['.implode(',',$flot_datas_views).']';
}
I am getting an error for an invalid client_secret.json file but I am attempting to authenticate using a service account so I am not sure what is going on here. I am then attempting to plot the data in a flot table but I am not worried about that part yet as I am still trying to get through this first hurdle. Any help would be appreciated!
I'm not quite up-to-date with the Google PHP API client, but apparently there are different versions on offer - when I cloned the repo I got the version that you app use and I did not get it to work with my credentials file. I then installed the current version of the library via composer:
composer require google/apiclient:^2.0
I was then able to access a Google Analytics with the following code:
<?php
include_once __DIR__ . '/vendor/autoload.php';
date_default_timezone_set('America/Los_Angeles');
$client = new Google_Client();
$client->setAuthConfig('/path/to/credentials.json');
$client->setApplicationName("Client_Library_Examples");
$client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']);
$service = new Google_Service_Analytics($client);
function getResults($service, $profileId) {
return $service->data_ga->get(
'ga:' . $profileId,
'30daysAgo',
'today',
'ga:pageviews'
);
}
$profile= "80493610";
$results = getResults($service, $profile);
print_r($results);
With a bit of poking around I managend to get an instance of the analytics service with the old version from your example. Apparently you have to use the loadServiceAccountJson function rather than setAuthConfig
<?php
// Load the Google API PHP Client Library
require_once ('google-api-php-client/src/Google/autoload.php');
$KEY_FILE_LOCATION = '/path/to/credentials.json';
// Create and configure a new client object.
$client = new Google_Client();
$client->setApplicationName("Hello Analytics Reporting");
$scopes = ['https://www.googleapis.com/auth/analytics.readonly'];
$client->loadServiceAccountJson($KEY_FILE_LOCATION, $scopes);
$analytics = new Google_Service_Analytics($client);
print_r($analytics);

Evernote PHP sdk integration with Symfony2

I am using this documentation to set up Evernote cloud sdk php into Symfony2 :
https://github.com/evernote/evernote-cloud-sdk-php/blob/master/documentation/Getting_Started.md
As they say, I installed it first with composer.
Then I am using this code
$sandbox = true;
$oauth_handler = new \Evernote\Auth\OauthHandler($sandbox);
$key = '%key%';
$secret = '%secret%';
$callback = 'http://host/pathto/evernote-cloud-sdk-php/sample/oauth/index.php';
$oauth_data = $oauth_handler->authorize($key, $secret, $callback);
echo "\nOauth Token : " . $oauth_data['oauth_token'];
I changed the parameters with mine, but the problem is inside Evernote\Auth\OauthHandler :
https://github.com/evernote/evernote-cloud-sdk-php/blob/master/src/Evernote/Auth/OauthHandler.php
The lib is using the function header(location: ...);
And the function is not executing.
I guess Symfony2 is not allowing the usage of this function.
Is there a way to force it ?
Or how can I change it in a good way (and to be able to push on my git repository) ?
Thanks,

Cannot Authenticate Salesforce in a Wordpress Plugin

I'm getting an error (INVALID_SESSION_ID) when trying to send an authenticated GET request to Salesforce.com.
Here is the plug-in in its entirety, which basically just outputs the body of the REST response to whatever page has the [MembershipTables] shortcode:
if (!class_exists('WP_Http')) {
include_once(ABSPATH . WPINC . '/class-http.php');
}
// This is obviously the real username
$username = 'xxxx#xxxx.xxx';
// And this is obviously the real password concatonated with the security token
$password = 'xxxxxxxxxxxxxx';
function getMembershipTables() {
$api_url = 'https://na15.salesforce.com/services/apexrest/directory';
$headers = array('Authorization' => 'Basic ' . base64_encode("$username:$password"));
$args = array('headers' => $headers);
$request = new WP_Http;
$result = $request->request($api_url, $args);
$body = $result['body'];
echo "$body";
}
add_shortcode( 'MembershipTables', 'getMembershipTables' );
I should note that I can successfully hit this endpoint with Curl, though I use a session token I get from Salesforce using the old SOAP API to keep it equivalent (i.e., no client id/secret).
Am I doing something wrong with WP_Http? Or cannot I not authenticate a salesforce.com request using basic auth?
Thanks.
The salesforce API does not support Basic authentication, you need to call it with a sessionId. You can obtain a sessionId by various methods include interactive & programatic OAuth2 flows, and via a Soap login call.
Basis Interactive had a similar problem to solve. When I worked on the project I opted to to call the SalesForce CRM via the preset form plugin and a custom JS Cookie PHP Wordpress Plugin. We had this problem easily resolved by developing custom calls to SalesForce CRM via a getRequest in PHP passing data to the SalesForce CRM.
Test Site in Use:
http://newtest.medullan.com/wp/?page_id=3089
Here is the code and recycle the logical queries
Download Link:
http://basisinteractive.net/webdesign.html#wordpress

Resources