Where to find ArcGIS service url and how to create one? How upload and view content from the server - arcgis

I am new to ArcGIS. I would like to know where I could find the service URL to list all the items in the MyContents tab which could be found by logging into my organization's ArcGIS URL. I want to do this using the Javascript or Rest API provided by ArcGIS.
I was able to get Token from ArcGIS using
https://www.arcgis.com/sharing/rest/oauth2/token
this URL.
When I try to upload a file to one of the sample servers using Code, I am not able to do it. It works in postman though.
These are the code that I used for uploading a file to a sample server which failed.
$.ajax({
async: true,
crossDomain: true,
url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/uploads/upload",
method: "POST",
headers: {
"Content-Type": "multipart/form-data",
"Accept": "application/json"
},
contentType: false,
processData: false,
mimeType: "multipart/form-data",
data: {
"f": "json",
"file": "C:/Users/georgy.f/Downloads/Screenshot_20190422-114420.jpg",
"description": "descrioption",
}
}).done(function (response) {
console.log(response);
});
Another code for uploading that I tried.
var uploadsettings = {
"async": false,
"crossDomain": true,
"url": "https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/uploads/upload",
"method": "POST",
"headers": {
"Content-Type": "multipart/form-data",
"Accept": "application/json"
},
contentType: false,
processData: false,
"mimeType": "multipart/form-data",
"data": form
{
"f": "json",
"file": "https://images.pexels.com/photos/67636/rose-blue-flower-rose-blooms-67636.jpeg",
"description": "descrioption",
}
}
$.ajax(uploadsettings).done(function (response) {
console.log(response);
});
My aim is to list all the MapViews and SceneViews available in my organization.
Also, will I be able to view BIM models in ArcGIS using Javascript or REST API by somehow uploading it to ArcGIS server?

Related

flutter http post request showing status code 500 although its works in postman

**flutter**
As you can see below code of post method in which i pass static data for post through post API,
those data are work in postman but not in this method
Future addbuss() async {
var urlpost = "https://jcien.com/api/addBusinessReceived";
var responce = await http.post(urlpost,
headers: {
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode({
"user": "7",
"ch_id": "1",
"user_from": "9",
"entry_date": "2021-05-31",
"amount": "1234",
"business_type": "new",
"referral_type": "inside",
"remarks": "demoapii",
}));
print(responce.statusCode);
**statusCode**
status code showing error of 500
}
The error message is self-explanatory:
You must debug your API, the error is from there.
Check log server.
I think It might be because of
headers: {
'Content-Type': 'application/json; charset=UTF-8',
},
Use this instead
headers: {
'Content-Type': 'application/json'
},

React native sending image to server using formdata

I have a problem sending a picture to a server, that's like the default approach, but it does not seem to work.
var source = '/Users/alexx/Library/Developer/CoreSimulator/Devices/44F0FA92-4898-4CFB-862E-4E5EC4C8AB28/data/Containers/Bundle/Application/34BCE695-4B4F-472F-AB5C-F2336AC45273/DoorLock.app/123.jpg';
const form = new FormData();
form.append('image', {
uri: source,
type: 'image/jpg',
name: '123.jpg',
});
const data = () => {
fetch(api ,{
method: 'POST',
body: form,
})
that's the response i get from the server:
{
"_bodyBlob": {
"_data": {
"__collector": [
Object
],
"blobId": "78B18938-15BF-4F18-B3C8-1EB30A24D9F8",
"name": "test.html",
"offset": 0,
"size": 192,
"type": "text/html"
}
},
"_bodyInit": {
"_data": {
"__collector": [
Object
],
"blobId": "78B18938-15BF-4F18-B3C8-1EB30A24D9F8",
"name": "test.html",
"offset": 0,
"size": 192,
"type": "text/html"
}
},
"bodyUsed": false,
"headers": {
"map": {
"connection": "keep-alive",
"content-length": "192",
"content-type": "text/html",
"date": "Mon, 02 Nov 2020 22:57:21 GMT",
"server": "PythonAnywhere"
}
},
"ok": false,
"status": 400,
"statusText": undefined,
"type": "default",
"url": api
}
Although this python code works perfectly and gets a correct response
img = {'file':('123.png', open('the path to the pic/123.png', 'rb'), 'image/png)}
post(api, files = img)
is there any way to get this working or its the server side problem that can't receive the correct arguments?
Adding "file://" to the beginning of the source string fixed the problem.
so the src looks like
var source = 'file:///Users/alexx/Library/Developer/CoreSimulator/Devices/44F0FA92-4898-4CFB-862E-4E5EC4C8AB28/data/Containers/Bundle/Application/34BCE695-4B4F-472F-AB5C-F2336AC45273/DoorLock.app/123.jpg';
then it fetches perfectly, hope it helps anybody who tries to send a local image using formdata, the summary looks like this now
const form = new FormData();
form.append('file', {
uri: source,
name: '123.jpg',
fileName: 'file', //optional
});
fetch(uri,{
method: 'post',
body: form,
})
.then(response => {
console.log("image uploaded")
console.log(response)
})
.catch(console.log);
In Formdata when you pass files, you need to pass 3 parameters where
key expected from the backend (in your case image).
It will be an object which has three properties named name, type, and uri where type is the mime type (ex: image/jpeg).
name of the file
Eg:
data.append("FilePath",{
name:"image.png",
type:"image/png",
uri:"content://com.camera/image.png"
},image.png)

MVC : how to protect my API parameters in ajax call being edited

I have An MVC5 Application, I use APIs, I call my APIs using AJAX, so my parameters are available to be edited from the Script Code file, now I want to protect parameters from being updated from the inspection feature in any browser,What shall I do?
ex:
var checkupType = {
"id": 0,
"name": "My name",
"description": "My description"
}
$.ajax({
url: '/api/CheckupTypes',
method: 'post',
headers: { 'Content-Type': 'application/json' },
data: JSON.stringify(checkupType)
})

How to create a webhook on a repository on the GitHub web api using AJAX?

I am experimenting with Webhooks in the GitHub api. I got one working by doing it manually as in going into my repository and clicking into the setting and enabling a web hook. But now I want to do this in AJAX and I am getting problems. Anytime I try to send a POST to the web api it fails with a 400 (Bad Request). I am not sure where I am going wrong with my code.
function createWebHooksOnRepos(token){
const webhookURL = "https://api.github.com/repos/DanoBuck/AlgorithmsAndDataStructures/hooks";
const json = {
"name": "WebHook",
"active": true,
"events": [
"issue_comment",
"issues"
],
"config": {
"url": "http://39a40427.ngrok.io/api/webhooks/incoming/github",
"content_type": "json"
}
};
$.ajax({
headers: {
"Authorization": "Token " + token
},
url: webhookURL,
data: json,
type: "POST",
dataType: "json",
success: function(data){
console.log(data);
}
});
}
Thank you
From github Webhook API doc :
name - string - Required. Use "web" for a webhook or use the name of a valid
service. (See /hooks for the list of valid service names.)
So in your case, just rename Webhook to web :
const json = {
"name": "web",
"active": true,
"events": [
"issue_comment",
"issues"
],
"config": {
"url": "http://39a40427.ngrok.io/api/webhooks/incoming/github",
"content_type": "json"
}
};
Also JSON.stringify your data before sending :
$.ajax({
headers: {
"Authorization": "Token " + token
},
url: webhookURL,
data: JSON.stringify(json),
type: "POST",
dataType: "json",
success: function(data) {
console.log(data);
}
});

Using the access token with the SkyDrive API

I have been trying to get access to the json result with the following link:
https://apis.live.net/v5.0/file.a4423f3123801749.A4423F3123801749!418
But as you can see by clicking on it yourself, you need an access token.
I already have an access token, but it only lasts for 3600 seconds (1 hour).
Is there a way to get the results of the link (the json shown below) without the access token expiring? I know there is a refresh token, but I am unsure how to use it.
{
"id": "file.a4423f3123801749.A4423F3123801749!418",
"from": {
"name": "Andrew Wong",
"id": "a4423f3123801749"
},
"name": "Mod Permissions.xlsx",
"description": "",
"parent_id": "folder.a4423f3123801749.A4423F3123801749!129",
"size": 89956,
"upload_location": "https://apis.live.net/v5.0/file.a4423f3123801749.A4423F3123801749!418/content/",
"comments_count": 0,
"comments_enabled": true,
"is_embeddable": true,
"source": "https://hvbqwg.dm2302.livefilestore.com/y2m6t-kEOaAd1qXi2n4cvNuVCMqU2Is3Ft_7g7UGM1h6Ib8oyGSFzT70rT3F3mz5PFsrzUDkyAfhYoh1YIZWNY3INmCIKheJpZWoUVTvz-xh5I/Mod%20Permissions.xlsx?psid=1",
"link": "https://skydrive.live.com/redir.aspx?cid=a4423f3123801749&page=view&resid=A4423F3123801749!418&parid=A4423F3123801749!129",
"type": "file",
"shared_with": {
"access": "Public"
},
"created_time": "2014-01-16T07:06:41+0000",
"updated_time": "2014-01-16T07:14:51+0000",
"client_updated_time": "2014-01-16T07:14:51+0000"
}
Do a post to https://login.live.com/oauth20_token.srf to convert your refresh_token to an access_token. Read more in MS documentation bullet #6.
Here are a sample node.js code
var options,request;
request = require('request');
options = {
url: 'https://login.live.com/oauth20_token.srf',
form: {
client_id: YOUR CLIENT_ID,
redirect_uri: YOUR REDIRECT_URI,
client_secret: YOUR CLIENT_SECRET,
refresh_token: YOUR REFRESH_TOKEN,
grant_type: 'refresh_token'
},
headers: {
'Accept': 'application/json'
}
};
request.post(options, function(err, response, data) {
});