How to set document in ProjectCollection scope?
I tries to call setDocumentByName method but ScopeType and ScopeValueparameters are requred.
When I tries to set empty strings for these parameters it doesn't work.
import * as azdev from "azure-devops-node-api";
import extmgmtm = require("azure-devops-node-api/ExtensionManagementApi");
let authHandler = azdev.getPersonalAccessTokenHandler(token);
let connection = new azdev.WebApi(orgUrl, authHandler);
let api = await connection.getExtensionManagementApi();
await api
.setDocumentByName(
{
id: "key",
value: inputString,
},
publisher,
extensionName,
"User", //scopeType
"Me", //scopeValue
"collection1"
)
.then((doc) => {
console.log(doc);
});
I found solution!
For scopeType we need to use Default instead of User
and Current for scopeValue instead of Me.
Related
I want to create a specific class of assignments.
At Graph Explorer,
https://graph.microsoft.com/beta/education/classes/{classId}/assignments
This request works well.
But in my C# code,
var assignInfo = new EducationAssignment
{
DisplayName = "test",
DueDateTime = DateTimeOffset.Parse("2020-09-20T18:00:00Z"),
Instructions = new EducationItemBody
{
ContentType = BodyType.Html,
Content = "hi"
},
Status = EducationAssignmentStatus.Draft,
AllowStudentsToAddResourcesToSubmission = true,
AssignTo = new EducationAssignmentClassRecipient
{
},
Grading = new EducationAssignmentPointsGradeType()
{
MaxPoints = 100
},
CreatedDateTime = DateTimeOffset.Parse("2020-09-20T12:00:00Z"),
AssignDateTime = DateTimeOffset.Parse("2020-09-20T13:00:00Z"),
AssignedDateTime = DateTimeOffset.Parse("2020-09-20T13:00:00Z"),
CloseDateTime = null,
AllowLateSubmissions = true
};
await graphClient.Education.Classes[pClassId].Assignments
.Request()
.AddAsync(assignInfo);
It occured error:
{"Code: 20132\r\nMessage: The content of the request is invalid. Common causes are an invalid Content-Type header or no content in the body.\r\nInner error:\r\n\tAdditionalData:\r\n\tdate: 2020-09-20T07:25:14\r\n\trequest-id: d2181119-9116-4f1d-9ed4-d007e2e406d0\r\n\tclient-request-id: d2181119-9116-4f1d-9ed4-d007e2e406d0\r\nClientRequestId: d2181119-9116-4f1d-9ed4-d007e2e406d0\r\n"}
Why is this happening? I've been thinking and trying all day.
I tried
await graphClient.Education.Classes[pClassId].Assignments
.Request()
.Header("Content-Type", "application/json")
.AddAsync(assignInfo);
But there was the same error.
If only the displayname element was requested, the results were the same.
The Permissions has been dealt with.
EduAssignments.ReadWriteBasic, EduAssignments.ReadWrite.. etc
And the dll(NuGet pakage) is also prepared in beta version.
I referred to this document.
I'm desperate for help..
Thanks.
adding this assignInfo.ODataType = null; fixes the problem.
In new Zapier UI, I used to do below..
return z.request(options).then(response => {
response.throwForStatus();
const results = z.JSON.parse(response.content);
let attachmentArray = [];
attachmentArray = results.data.map(function(result) {
let attachment = {};
attachment.id = result.attachment_id;
let file_url = options.url + `/${attachment.id}`;
attachment.url = file_url;
attachment.file = z.dehydrateFile(file_url, {
method: "GET",
headers: { Authorization: `Bearer ${bundle.authData.access_token}` }
});
return attachment;
});
return attachmentArray;
});
This is my code to provide a trigger. Currently, it throws
Error: You must pass in a function/array/object. We got string instead.
David here, from the Zapier Platform team. That error comes from this line, which is responsible for finding methods on your root App object. We've actually got a test covering that exact case here.
The offending code doesn't seem to be in the sample you provided above, but take a look at anywhere you're calling dehydrate('some str') or appTester('some string')
I am able to upload a file on android to a C# web api, using nativescript-camera with nativescript-background-http.
I set the params as follows:
var params = [{ name: "image", filename: fileUri, mimeType: 'application/octet-stream' }];
...
And send the request:
let request = {
url: this.API_URL + "/UploadOctetFile",
method: "POST",
headers: {
"Authorization": accessTokenJson,
"Content-Type": "application/octet-stream",
"File-Name": imageName
},
description: "{ 'uploading': " + imageName + " }"
};
return this.session.multipartUpload(params, request);
In android the fileUri is returned in a fairly straight forward manner:
takePictrue.then((imageAsset: ImageAsset) => {
Then imageAsset.android has the file uri that is needed to send the image. However, for ios, imageAsset.ios is a PHAsset. To get the file URI, I use the following code:
let manager = PHImageManager.defaultManager()
let options = new PHImageRequestOptions();
options.resizeMode = PHImageRequestOptionsResizeMode.Exact;
options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
manager.requestImageForAssetTargetSizeContentModeOptionsResultHandler(imageAsset.ios, { width: 2048, height: 1536 }, PHImageContentModeAspectFill, options, function (result, info) {
let srcfilePath = info.objectForKey("PHImageFileURLKey").toString();
...
});
In the above: srcfilePath (which I pass as fileUri) is: file:///var/mobile/Media/DCIM/101APPLE/IMG_1902.JPG
The image name is then IMG_1902.JPG
However, this uploads an empty file. I'm guessing that I need to change the fileUri or perhaps I should be using a different method to: requestImageForAssetTargetSizeContentModeOptionsResultHandler.
I have tried the solution suggested here to do:
let fileUri = image.fileUri.replace("file://","");
and I've tried changing the mime type "mimeType":"image/jpg".
Any ideas are much appreciated.
Sam, this might help. I did the following to handle an iOS user selecting a photo from their gallery for use later in the app (Android is simple and straightforward like in your case, but iOS returns a PHAsset):
import { ImageSource } from "image-source";
import { Image } from "tns-core-modules/ui/image";
import { path, knownFolders } from "tns-core-modules/file-system";
//iOS user picks photo...
const iosImg = new ImageSource();
iosImg.fromAsset(myPHAsset).then(imsr => {
this.counter += 1; //class property to allow unique filenames
const folder = knownFolders.documents();
const path2 = path.join(folder.path, `Image${this.counter}.jpg`);
const saved = imsr.saveToFile(path2, "jpg");
const img = new Image();
img.src = path2;
this.data.changeImage(img); //Ng service to allow use of image in other components
});
Links: {N} docs
{N} imagepicker #197
{N} imageUpload code
I tried to change the existing angularjs library to angular2 for my need. http.post method in the below code throws TypeError {} as exception. Someone please help as i am stuck on this.
login() {
return new Promise((resolve, reject) => {
if(typeof jsSHA !== "undefined") {
var signatureObj = (new OauthUtility()).createSignature("POST", this.magentoOptions.baseUrl+"/oauth/initiate", this.oauthObject, {oauth_callback: "http://localhost/callback"}, this.magentoOptions.clientSecret, null);
let headersInitiate = new Headers();
headersInitiate.append('Authorization',signatureObj.authorization_header);
headersInitiate.append('Content-Type','application/x-www-form-urlencoded');
let url = this.magentoOptions.baseUrl + "/oauth/initiate";
let callback = "oauth_callback=http://localhost/callback";
try{
this.http.post(url, callback,{headers: headersInitiate})
.subscribe(
(result) => {
console.log("i am inside");
var rParameters = (result).split("&");
.....
}
catch(Exception){
console.log(Exception)
}
You should try something like that:
var signatureObj = (new OauthUtility()).createSignature("POST",
this.magentoOptions.baseUrl+"/oauth/initiate", this.oauthObject,
{oauth_callback: "http://localhost/callback"},
this.magentoOptions.clientSecret, null); let headersInitiate = new Headers();
headersInitiate.append('Authorization',
signatureObj.authorization_header);
headersInitiate.append('Content-Type',
'application/x-www-form-urlencoded');
let url = this.magentoOptions.baseUrl + "/oauth/initiate";
let payload = ' ... ';
this.http.post(url, payload,{headers: headersInitiate})
.subscribe(
(result) => {
console.log("i am inside");
var rParameters = (result).split("&");
(...)
});
Here are the comments I would have on your code:
The second parameter of the post method should be a string corresponding to the payload not a callback. I see from your headers that you want to send url-encoded form, so you need to create it by your own
The try catch isn't necessary since executing an HTTP is asynchronous and errors can be "catched" within the second parameter (another callback) of the subscribe method.
You don't need at all a promise. For HTTP, Angular2 uses observables under the hood. They target asynchronous processing as well.
After fixing all of this, I think that you won't have error anymore...
Hope it helps you,
Thierry
I found to stuck even after proceeding with the above all steps. The complete solution is as follows.
Remove try catch block and promise as suggested by Thierry.
Use dependency injection of http inside the constructor as follows to define http.
import {Http,HTTP_PROVIDERS,Headers} from 'angular2/http';
import {Injector} from "angular2/core";
constructor() {
var injector = Injector.resolveAndCreate([HTTP_PROVIDERS]);
this.http = injector.get(Http);
}
I get a bunch of different URL from my sources and what I would like is to redirect to the same URL, but with campaign data added to URL (to track the referred clicks).
For example I have these URLs:
www.example.com/category/product/name.html
www.example.com/id_product=5
I want to add at the end the following: utm_source=SOURCE&utm_medium=MEDIUM&utm_campaign=CAMPAIGN
And the URLs to become
www.example.com/category/product/name.html?utm_source=SOURCE&utm_medium=MEDIUM&utm_campaign=CAMPAIGN
www.example.com/id_product=5&utm_source=SOURCE&utm_medium=MEDIUM&utm_campaign=CAMPAIGN
How to I correctly check and cover all the cases if a URL string has parameters, and add mine?
I want to do it in node.js
Thank you
Elaborating on #snkashis, a similar but arguably more elegant solution, again using node's url module, is:
var addQueryParams = function (cleanUrl) {
var obj = url.parse(cleanUrl, true, false);
obj.query['utm_source'] = 'SOURCE';
obj.query['utm_medium'] = 'MEDIUM';
obj.query['utm_campaign'] = 'CAMPAIGN';
delete obj.search; // this makes format compose the search string out of the query object
var trackedUrl = url.format(obj);
return trackedUrl;
};
This works, because url.format first looks for search and, if it can't find it, it composes the query string from the query object
(taken from node url module documentation http://nodejs.org/api/url.html#url_url_format_urlobj )
search will be used in place of query
query (object; see querystring) will only be used if search is absent.
Here is a example showing different scenarios using Node's URL module.
var url = require('url');
var exurls = ["www.example.com/category/product/name.html","www.example.com/id_product=5?hasparam=yes"]
var to_append = "utm_source=SOURCE&utm_medium=MEDIUM&utm_campaign=CAMPAIGN";
for (i=0;i<exurls.length;i++) {
var parsedobj = url.parse(exurls[i],true,false);
//Below checks if param obj is empty.
if (Object.keys(parsedobj.query).length!==0) {
var newpath = parsedobj.href+"&"+to_append;
}
else {
var newpath = parsedobj.href+"?"+to_append;
}
console.log(newpath);
}
Connect will help you:
var connect = require('connect');
var app = connect();
app.use(connect.query());
app.use(function (req, res, next) {
console.log(req.query);
res.end(JSON.stringify(req.query));
});
app.listen(3000);