I need to create a confluence page via the REST API. Creating a simple page is working, however if I try to add content to an existing HTML page I get http_response 400 (bad request).
Code snippet:
confluence_page_content = File.open("local_html_report", "r").read
json_data = {
"body" => {
"storage" => {
"representation" => "storage",
"value" => "#{confluence_page_content}"
}
},
"space" => {
"key" => "#{test_parameters["confluence_space"]}"
},
"title" => "TestPageFromChef",
"type" => "page"
}.to_json
Hy, solved it :)
Code snippet:
confluence_page_content = "<ac:structured-macro ac:name=\"html\">
<ac:plain-text-body><![CDATA[
#{confluence_page_content}
]]></ac:plain-text-body>
</ac:structured-macro>
"
Related
I have a telerik mvc grid (NOT JAVASCRIPT) with groupable() turned on. The column i am grouping by has a link in it. No big deal since that's easy on a column template. However, header templates don't allow access to data from a column different that the one the grouping is set on, and our links are all based on the "ID" column (hidden) whereas the grouping is on the "Name" column.
Can I call javascript from the header template to get the data I need?
here is an example of what has worked
.Groupable()
.Selectable()
.Columns(columns =>
{
columns.Template(#<text></text>).ClientTemplate("#= rowCommandsUndelete(data, false, true) #").Title(" ").Width(100);
columns.Bound(m => m.Active)
.Title("Active?")
.ClientTemplate("#= ActiveState(data.Active) #")
.Width(85);
columns.Bound(m => m.Origin.Name)
.ClientGroupHeaderTemplate("<a href='www.google.com'>link </a>")
.ClientTemplate("<div id='#=data.ID#'></div><a href='/Origins?id=#=data.Origin.ID#'>#=data.Origin.Name#</a>") //Empty div with "data.ID" is required (see JavaScript section below)
.Width(300);
and this doesn't work and gives an error: Uncaught TypeError: Cannot read property 'ID' of undefined
columns.Bound(m => m.Origin.Name)
.ClientGroupHeaderTemplate("<a href='www.google.com'> #=data.Origin.ID#</a>")
the final answer is thanks to sandro. On an ajax page, use clientgroupheadertemplate like this on a column:
columns.Bound(m => m.Origin.Name)
.ClientGroupHeaderTemplate("#=buildHeader( value )#")
buildheader is a javascript function, and value is a built-in value in the header. Here's the javascript function:
function buildHeader(value) {
return "<h4><u><a href='\origins?OriginName=" + encodeURIComponent(value) + "'>" + value + "</a></u></h4>";
}
value contained the string from the column and i was able to create a link this way and set it to the column header. I have also successfully called javascript now from a footer to trigger something after a calculation.
It's groupHeaderTemplate configuration.
Example:
$("#grid").kendoGrid({
columns: [
{ field: "name" },
{ field: "link",
groupHeaderTemplate: "<a href=#=value# target='_blank'>google.com</a>"
}
],
dataSource: {
data: [
{ name: "Jane Doe", link: "https://google.com" },
{ name: "John Doe", link: "https://google.com" }
],
group: { field: "link" }
}
});
I am trying to upload products via ruby (not with rails). I have uploaded 100 + products via API, although I cannot upload a product with more than one option value. Even if I assign three option values, it will not populate the other two.
Here is the script:
require 'shopify_api'
require 'open-uri'
require 'json'
begin_time = Time.now
shop_url = "*https*(yes I know the * are their)://-YouWish-:-I'dShareNakedPics-#dev-tactical.myshopify.com/admin/products.json"
include ShopifyAPI
ShopifyAPI::Base.site ="*https*://-YouWish-:-I'dShareNakedPics-#dev-tactical.myshopify.com/admin/"
raw_product_data = JSON.parse(open('omg.json') {|f| f.read }.force_encoding('UTF-8'))
raw_product_data_size = raw_product_data.size
puts '========================================================================='
puts "#{raw_product_data_size} seconds till explosion. assistance
needed..."
puts '-------------------------------------------------------------------------'
single_product_begin_time = Time.now
# Create new product
new_product = ShopifyAPI::Product.new
new_product.title = "Variants Suck"
new_product.body_html = "So"
new_product.product_type = "Much"
new_product.vendor = "Please"
new_product.tags = "Help"
new_product.variants = [
{
"option1" => "This One Works",
"option2" => "Lost Cause",
"option3" => "/wrist",
"postion" => "1",
"price" => "10.00",
"sku" => "12345",
"inventory_management" => "shopify",
} ]
new_product.images = [
{
src: "https://cdn.shopify.com/s/files/1/0750/0067/files/Pro-Tapes.jpg?11603036243532110652"
} ]
new_product.save
creation_time = Time.now - single_product_begin_time
puts '-------------------------------------------------------------------------'
puts "Sorry About the mess babe, atleast it only took #{begin_time - Time.now} minutes."
puts '========================================================================='
I am testing this on a dev shop, but I am attempting to rebuild something previously built on magento, where I can have people convert my csv data entry to json, then array/hash the data.
Please don't link me to the (shopify)/API info. I have read it. I don't understand the formatting of it. If I were to shopify-cli console, and paste the api example in irb, it won't execute properly. I am sure I am just lacking the required knowledge of working with APIs, although if you can help me just slightly it would be much appreciated.
This node.js script adds item with variants. The difference here is that it includes a list of options on the product element. Note that if you comment out the options element then I get the same problem you are reporting in that only the first option is imported.
var https = require('https');
var cred = new Buffer(privateAppAPIKey +":"+ privateAppPassword).toString('base64');
var headers = {Authorization: "Basic "+cred, "Content-Type": "application/json"};
var options = {
host: 'kotntest1.myshopify.com',
port: 443,
path: '/admin/products.json',
method: 'POST',
headers: headers
};
// Setup the request. The options parameter is
// the object we defined above.
var req = https.request(options, function(res) {
res.setEncoding('utf-8');
var responseString = '';
res.on('data', function(data) {
responseString += data;
console.log(data);
});
res.on('end', function() {
var resultObject = JSON.parse(responseString);
});
});
req.on('error', function(e) {
// TODO: handle error.
console.log(e);
});
var product = {
product:{
title:'My First Test Product',
options : [
{name : "First"},
{name : "Second"},
{name : "Third"}
],
variants: [
{
title:'v1',
option1: 'Red',
option2: "Honda",
option3: 'Prelude'
},
{
title:'v2',
option1 :'Blue',
option2 :'Ford',
option3 :'Escort'
}
]
}
};
req.write(JSON.stringify(product));
req.end();
I used #bknights code as a reference and got my code to work in ruby. You just have to set the option names on the product level first:
new_product = ShopifyAPI::Product.new
new_product.options = [{"name" => "Size"}, {"name" => "Color"}]
Then adding variants work:
new_product.variants = [
{
"option1" => "S",
"option2" => "Black",
"position" => "1",
"price" => "10.00"
},
{
"option1" => "M",
"option2" => "Black",
"position" => "1",
"price" => "10.00"
}
]
new_product.save
Im trying to save a Point with float value into fitness.body.
Getting value is not a problem, while saving a new point causes 403. No permission to modify data for this source.
Im using DataSetId derived:com.google.weight:com.google.android.gms:merge_weight to find point and read value, and raw:com.google.weight:com.google.android.apps.fitness:user_input to insert data.
.
Here is a workflow using Ruby and google-api-ruby-client:
require 'google/api_client'
require 'google/api_client/client_secrets'
require 'google/api_client/auth/installed_app'
require 'pry'
# Initialize the client.
client = Google::APIClient.new(
:application_name => 'Example Ruby application',
:application_version => '1.0.0'
)
fitness = client.discovered_api('fitness')
# Load client secrets from your client_secrets.json.
client_secrets = Google::APIClient::ClientSecrets.load
flow = Google::APIClient::InstalledAppFlow.new(
:client_id => client_secrets.client_id,
:client_secret => client_secrets.client_secret,
:scope => ['https://www.googleapis.com/auth/fitness.body.write',
'https://www.googleapis.com/auth/fitness.activity.write',
'https://www.googleapis.com/auth/fitness.location.write']
)
client.authorization = flow.authorize
Forming my new data Point:
dataSourceId = 'raw:com.google.weight:com.google.android.apps.fitness:user_input'
startTime = (Time.now-1).to_i # 1 Second ago
endTime = (Time.now).to_i
metadata = {
dataSourceId: dataSourceId,
maxEndTimeNs: "#{startTime}000000000", # Faking nanoseconds with tailing zeros
minStartTimeNs: "#{endTime}000000000",
point: [
{
endTimeNanos: "#{endTime}000000000",
startTimeNanos: "#{startTime}000000000",
value: [
{ fpVal: 80 }
]
}
]
}
Attempting to save the point:
result = client.execute(
:api_method => fitness.users.data_sources.datasets.patch,
:body_object => metadata,
:parameters => {
'userId' => "me",
'dataSourceId' => dataSourceId,
'datasetId' => "#{Time.now.to_i-1}000000000-#{(Time.now).to_i}000000000"
}
)
And as I indicated previously im getting 403. No permission to modify data for this source
#<Google::APIClient::Schema::Fitness::V1::Dataset:0x3fe78c258f60 DATA:{"error"=>{"er
rors"=>[{"domain"=>"global", "reason"=>"forbidden", "message"=>"No permission to modif
y data for this source."}], "code"=>403, "message"=>"No permission to modify data for
this source."}}>
I believe, I selected all required permissions in the scope. I tried submitting the point to both accessible datasetid's for fitness.body.
Please let me know if im doing anything wrong here.
Thank you!
I encountered the same situation, turns out you can NOT insert data points directly into the datasource "raw:com.google.weight:com.google.android.apps.fitness:user_input". From the name, one might guess out this datasource is reserved. So the workaround is to add your own datasource, note should with dataType.name="com.google.weight", like this:
{
"dataStreamName": "xxxx.body.weight",
"dataType": {
"field": [
{
"name": "weight",
"format": "floatPoint"
}
],
"name": "com.google.weight"
},
"dataQualityStandard": [],
"application": {
"version": "1",
"name": "Foo Example App",
"detailsUrl": "http://example.com"
},
"device": {
"model": "xxxmodel",
"version": "1",
"type": "scale",
"uid": "xxx#yyy",
"manufacturer": "xxxxManufacturer"
},
"type": "derived"
}
then after the successful creation, you can use this datasource(datastream id) to insert your own data points, and then the inserted data points will also be included in the datasource "derived:com.google.weight:com.google.android.gms:merge_weight" when you do the querying with suffix "dataPointChanges".
Try adding an Authorization header:
result = client.execute(
:api_method => fitness.users.data_sources.datasets.patch,
:headers => {'Authorization' => 'Bearer YOUR_AUTH_TOKEN'},
:body_object => metadata,
:parameters => {
'userId' => "me",
'dataSourceId' => dataSourceId,
'datasetId' => "#{Time.now.to_i-1}000000000-#{(Time.now).to_i}000000000"
}
)
I use Mandrill plugin for Codeigniter.
I created HTML template through Mandrill account, named fess1 with merge tag FNAME, after I published it.
Example:
...
<p>
<span>Hi *|FNAME|*,<br></span>
</p>
....
Now I try to send mail from codeigniter like:
private function sendMailMandrill($owner_name,$business_name,$owner_email){
$message = array('dest_mail' => $owner_email);
$message['to'] = array(array('email' => 'mim#wefi.com'));
$mergeVars[] = array(
'rcpt' => array(array('email' => 'mim#wefi.com')),
'vars' => array(
array(
'name' => 'FNAME',
'content' => 'Fessy'
)
)
);
$message['merge'] = true;
$template_name = 'fess1';
$template_content = array( // I don't know what I need to provide here, left it empty
array(
'name' => 'example name',
'content' => 'example content'
)
);
$message['merge_vars'] = $mergeVars;
return $this->mandrill->messages_send_template($template_name, $template_content, $message);
}
The result:
I get the mail, based on fess1 template, but with the tag *|FNAME|*.
Sounds like Mandrill didn't recognize the merge tag.
I used mandrill->messages_send_template but since my template stored into Mandrill account I have no clue what I need to provide for $template_content.
So I wrote dummy info there.
Did I miss something?
Thank you,
[EDIT]
From logs this is what I send:
{
"template_name": "fess1",
"template_content": [
{
"name": "example name",
"content": "example content"
}
],
"message": {
"owner_name": "עידו",
"business_name": "פלאפל מוסקו",
"dest_mail": "maxim#wifi.com",
"to": [
{
"email": "maxim#wifi.com"
}
],
"merge": "true",
"merge_vars": [
{
"rcpt": [
{
"email": "maxim#wifi.com"
}
],
"vars": [
{
"name": "FNAME",
"content": "Fessy"
}
]
}
]
},
"key": "xxxxxxxxxxxxxxxx"
}
You can provide blank information for the template_content parameter. That parameter allows you to use mc:edit regions in your template. It is a required parameter, but a blank array will suffice if all of the content is in your template in Mandrill.
As for whether the merge_vars were recognized, the first thing we recommend is inspecting the API Logs for your account (Settings > API Logs) since that will show you the JSON that Mandrill received. You can then compare that to the expected JSON format from the Mandrill API docs: https://mandrillapp.com/api/docs/messages.JSON.html#method=send-template
It looks like your arrays may not be nested as expected. Once you view the JSON that's being generated as compared with the expected format, you can also view the PHP documentation for the Mandrill PHP client. It may not be identical to the CodeIgniter plugin, but should give you an idea of how the merge_vars parameter would be structured in PHP: https://mandrillapp.com/api/docs/messages.php.html
In mergeVars you created array instead key:value. Change it to:
'rcpt' => 'mim#wefi.com',
I'm trying to replicate Facebook action links with the Open Graph API. I have the following snippet:
HTTParty.post("https://graph.facebook.com/me/feed", query: { message: "...", picture: "...", access_token: "...", actions: [{ link: "http://google.com", name: "Example" }] })
However it is returning (and I'm not sure why):
{"error":{"type":"OAuthException","message":"(#100) The post's action links must be valid URLs."}}
Anyone have any experience with action links using the graph API?
Note that the actions array should be JSON encoded, HTTParty might not do this automatically / correctly. Try
HTTParty.post(
"https://graph.facebook.com/me/feed",
:query => {
:message => "...",
:picture => "...",
:access_token => "...",
:actions => [{ link: "http://google.com", name: "Example" }].to_json
}
)
(Assuming you have a library included that provides Array#to_json…)