I am working on automating Intune to perform the Managed Google Play Application approvals, the API documentation I have been referencing is here:
https://learn.microsoft.com/en-us/graph/api/intune-androidforwork-androidmanagedstoreaccountenterprisesettings-approveapps?view=graph-rest-beta
Requirements for approveApps is almost identical to syncApps:
https://learn.microsoft.com/en-us/graph/api/intune-androidforwork-androidmanagedstoreaccountenterprisesettings-syncapps?view=graph-rest-beta
I can make the call to syncApps successfully but approveApps returns BadRequest. The only difference between the calls appears to be the body requirements.
It needs packageIds as a String collection and approveAllPermissions as a Boolean.
Please help me to successfully make a post to https://graph.microsoft.com/beta/deviceManagement/androidManagedStoreAccountEnterpriseSettings/approveApps
Minimum Reproducible Code:
var authHeader = {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json"
};
var appApprovePostData = JSON.stringify({
packageIds: ["com.bundle.example"],
approveAllPermissions: true
});
var appApproveOptions = {
method: "POST",
uri:
"https://graph.microsoft.com/beta/deviceManagement/androidManagedStoreAccountEnterpriseSettings/approveApps",
headers: authHeader,
body: appApprovePostData
};
response = await request(appApproveOptions);
The application needs to be prefaced with "app:". So, in your example, you need
var appApprovePostData = JSON.stringify({
packageIds: ["app:com.bundle.example"],
approveAllPermissions: true
Couple of thoughts -
If you get back a RequestID, can you post that?
Can you compare the request body submitted by the Azure Portal (F12 developer mode to get the request body trace) for the same app approval with your request body generated from code?
Dave
Related
I have developed a TFS extension for TFS 2017 on premises.
I need to get a list of the service endpoint within a project
I am using the following code inside a TFS extension (code-hub)
private callTfsApi() {
const vsoContext = VSS.getWebContext();
let requestUrl = vsoContext.host.uri
+ vsoContext.project.id
+ "/_apis/distributedtask/serviceendpoints?api-version=3.0-preview.1";
return VSS.getAccessToken().then(function (token) {
// Format the auth header
const authHeader = VSS_Auth_Service.authTokenManager.getAuthorizationHeader(token);
// Add authHeader as an Authorization header to your request
return $.ajax({
url: requestUrl,
type: "GET",
dataType: "json",
headers: {
"Authorization": authHeader
}
}).then((response: Array<any>) => {
console.log(response);
});
});
}
On every request the server responds with a status of 401 (Unauthorized).
If I use postman and basic authentication the call to the service endpoints APIs works.
Also, using the same code but a different API call (projects) works.
let requestUrl = vsoContext.host.uri + "_apis/projects?api-version=1.0";
Is there some sort of known bug related to the service endpoints APIs or maybe the extension must specify a scope? (not sure which one to include though)
Service endpoints are created at project scope. If you could query project info, you should also be able to query this.
You could try to add related scope vso.project in https://learn.microsoft.com/en-us/vsts/extend/develop/manifest#scopes page see if this do the trick.
Another way to narrow down this issue is directly using Rest API to call from code (not inside a TFS extension ) to see if the issue is related to extension side.
Add scope: vso.serviceendpoint_query
I'm trying to call the Prosperworks API through Code by Zapier. I can do this easy through curl, but for the life of me cannot get this POST call to work using fetch. Below is what I've got...any help appreciated. Thanks
fetch('https://api.prosperworks.com/developer_api/v1/people/fetch_by_email', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-PW-AccessToken': 'API_TOKEN',
'X-PW-Application': 'developer_api',
'X-PW-UserEmail': 'EMAIL'
},
body: JSON.stringify({'email': input.email})
}).then(function(res) {
var people_id = res.id;
return res.json();
}).then(function(body) {
callback(null, {id: 1234, rawHTML: body});
}).catch(function(error) {
callback("error");
});
I'm the lead engineer on the ProsperWorks developer API. sideshowbarker is correct; we do not accept cross-origin requests from Zapier. Given that we offer Zapier integration, though, perhaps we should. I'll bring it up with the dev team and see if we can get that onto an upcoming release :)
I'm trying to build a Google Apps Script that integrates with Trello, the idea being to use it to push information from spreadsheets and forms into the Trello API and create cards on a pending list on a certain board.
I found another question that pointed me in the right direction, and added in OAuth based on the GAS OAuth Documentation. The problem is I can't post the the board. I run the script, the OAuth prompt fires, and the script completes with no errors. I can also GET data from the private board, so I assume the authorization is working properly.
So, what am I doing wrong that prevents my script from POSTing to Trello?
Here's the code I'm working with:
var trelloKey = [Trello API key];
var trelloSecret = [Trello API key secret];
var trelloList = [the id of the list we're posting to];
var oauthConfig = UrlFetchApp.addOAuthService('trello');
oauthConfig.setAccessTokenUrl('https://trello.com/1/OAuthGetAccessToken');
oauthConfig.setRequestTokenUrl('https://trello.com/1/OAuthGetRequestToken');
oauthConfig.setAuthorizationUrl('https://trello.com/1/OAuthAuthorizeToken');
oauthConfig.setConsumerKey(trelloKey);
oauthConfig.setConsumerSecret(trelloSecret);
function createTrelloCard() {
//POST [/1/cards], Required permissions: write
var payload = {'name': 'apiUploadedCard',
'desc': 'description',
'pos': 'top',
'due': '',
'idList': trelloList};
var url = 'https://api.trello.com/1/cards'
var options = {'method' : 'post',
'payload' : payload,
'oAuthServiceName' : 'trello',
'oAuthUseToken' : 'always'};
UrlFetchApp.fetch(url, options);
}
You just need set fetch options contentType to application/json. I just resolved the same problem by this.
Try adding the scope=read,write in your authorization url.
from:
oauthConfig.setAuthorizationUrl('https://trello.com/1/OAuthAuthorizeToken');
to:
oauthConfig.setAuthorizationUrl("https://trello.com/1/OAuthAuthorizeToken?scope=read,write");
I need use API of some server from Sencha Touch 2 app . For using this API I need authenticate on server.
So I already implemented login functionality :
Ext.Ajax.request({
url: 'http://192.168.1.2:8080/spring-security-extjs-login/j_spring_security_check',
method: 'POST',
params: {
j_username: 'rod',
j_password: 'koala',
},
withCredentials: false,
useDefaultXhrHeader: false,
success: function(response){
var text = response.responseText;
Ext.Msg.alert("success", text, Ext.emptyFn);
},
failure: function(response){
var text = response.responseText;
Ext.Msg.alert('Error', text, Ext.emptyFn);
}
});
But how I can call API , because after authentication I try call API but they already want authentication. Probably I need save JSESSIONID and added it to another request, but I don't know how I can do it.
I can't use withCredentials: true , so I need to find another solution.
How I can get Set-Cookies from response HTTP Header ?
I see in Chrome console, that JSESSIONID present in response header , so , i need get it.
Please, help me find any solutions.
You can use requestcomplete & beforerequest events to read response headers and to write request headers respectively. Here is sample code :
Ext.Ajax.on('requestcomplete', function(conn, response, options, eOpts){
var respObj = Ext.JSON.decode(response.responseText);
Helper.setSessionId(options.headers['JSESSIONID']);
}, this);
Ext.Ajax.on('beforerequest', function(conn, options, eOptions){
options.headers['JSESSIONID'] = Helper.getSessionId();
}, this);
Hello,
I'm trying to acess, perform a post, into Tumblr with Oauth api provided by Tumblr) http://tumblr.com/api). I'm using Google Script and I've tryied too many solutions but anyone worked. To implement i've basaed myself into this(https://developers.google.com/apps-script/articles/twitter_tutorial) Google script twitter tutorial, once on Tumblr API web page they say that twitter api is almost the same that tumblr.
Contextualizing,
I've already set the Oauth class methods with data below and substituted consumer and secret keys with values got from the api i've created.
var oauthConfig = UrlFetchApp.addOAuthService("tumblr");
oauthConfig.setAccessTokenUrl(
"http://www.tumblr.com/oauth/access_token");
oauthConfig.setRequestTokenUrl(
"http://www.tumblr.com/oauth/request_token");
oauthConfig.setAuthorizationUrl(
"http://www.tumblr.com/oauth/authorize");
oauthConfig.setConsumerKey(<i>consumerkey</i>);
oauthConfig.setConsumerSecret(<i>consumerSecret</i>);
Error,
The code below isnt working as it should be.
var requestData = {
"method": "POST",
"oAuthServiceName": "tumbler",
"oAuthUseToken": "always"
};
var result = UrlFetchApp.fetch(
"https://api.tumblr.com/v2/blog/{blog}.tumblr.com/post?type=text&body=word",
requestData);
The Script to Twitter is almost the same and it works. Im able to perform tweets.
var result = UrlFetchApp.fetch(
"https://api.twitter.com/1/statuses/update.json?status=" + tweet,
requestData);
Response From Server
Request failed for returned code 400. Server response: {"meta":{"status":400,"msg":"Bad Request"},"response":{"errors":["Post cannot be empty."]}}
Possible Solutions
A possible solution can work using this information(got from tumblr.com/api):
OAuth
The API supports the OAuth 1.0a Protocol, accepting parameters via the Authorization header, with the HMAC-SHA1 signature method only. There's probably already an OAuth client library for your platform.
My question is, what am I doing wrong?(my post inst empty, i have 2 params). Had anyone had the same problem? Someone has suggestions?
Thank You.
I don't know anything about the tumblr api, but your http post is empty (the oAuth parameters aren't in the post body, they're advanced options), the body of the post needs to go in the "payload" parameter. See the section "Advanced parameters" in the docs. Or, as you aren't using the post can't you use a get request instead? Remove the method: POST parameter (GET is the default).
Thank You very much Daniel. It worked now!!
Everybody that want use Tumblr + Google Script API + oAuth can use de code below to perform posts.
I created I Google Spreadsheet and then a script there. Before to be able to post I neded to create and app into tumblr.com/api and get secret and consumer keys. Also I've deployed the Google script as an web app(ensure that the version is the last one(the final code)) before to create a new version. After that you go tu publish > deploy as web app !
That twitter tutorial I put on my first question is the only path you need to conclude your job.
function authorize() {
var oauthConfig = UrlFetchApp.addOAuthService("tumblr");
oauthConfig.setAccessTokenUrl(
"http://www.tumblr.com/oauth/access_token");
oauthConfig.setRequestTokenUrl(
"http://www.tumblr.com/oauth/request_token");
oauthConfig.setAuthorizationUrl(
"http://www.tumblr.com/oauth/authorize");
oauthConfig.setConsumerKey(getConsumerKey());
oauthConfig.setConsumerSecret(getConsumerSecret());
var requestData = {
"oAuthServiceName": "tumblr",
"oAuthUseToken": "always"
};
var result = UrlFetchApp.fetch(
"http://api.tumblr.com/v2/blog/{your_blog}.tumblr.com/posts/queue",
requestData);
}
function doGet(e) {
var tweet = e.parameter.tumblr;
var app = UiApp.createApplication().setTitle("Approved");
var panel = app.createFlowPanel();
authorize();
var encodedTweet = encodeURIComponent(tweet);
var payload =
{
"body" : encodedTweet,
"type" : "text"
};
var requestData = {
"method" : "POST",
"oAuthServiceName": "tumblr",
"oAuthUseToken": "always",
"payload" : payload
};
try {
var result = UrlFetchApp.fetch(
"https://api.tumblr.com/v2/blog/{your_blog}.tumblr.com/post",
requestData);
panel.add(app.createLabel().setText("You have approved: \"" + tweet + "\""));
} catch (e) {
Logger.log(e);
panel.add(app.createLabel().setText(e));
}
app.add(panel);
return app;
}