Get hyperlink to sheet based on SheetID - smartsheet-api

I am importing a Smartsheet Report through Python, using an API. One of the columns in this report contains a hyperlink that works in Smartsheet, however when importing the report with Python I only receive the words of this column, and not the link behind them. Is it possible to get the URLs of the sheets that these hyperlinks are referring to in any other way? I was thinking maybe based on SheetID (which I can find using the title of the indepentent sheets), but all other suggestions are very welcome!

I've been unable to reproduce the problem you've described.
The report I'm testing with contains the following data. The Google link in the first row is a normal URL that points to https://www.google.com and the Contacts List link in the second row is a sheet hyperlink that points to another sheet in Smartsheet.
First, I use the Python SDK to get the report and then print out the contents of the second cell of the first row (i.e., the one that contains the Google hyperlink):
reportID = 6667768033503108
report = smartsheet_client.Reports.get_report(reportID)
print(report.rows[0].cells[1])
The result of this code showed the following output (JSON formatted here for readability):
{
"columnId": 5228827298293636,
"displayValue": "Google",
"hyperlink": {
"url": "https://www.google.com"
},
"value": "Google",
"virtualColumnId": 2581703205119876
}
So, accessing the URL of the hyperlink can be accomplished with the following code:
url = report.rows[0].cells[1].hyperlink.url
print(url) #shows output: https://www.google.com
The same approach works for getting the URL of the sheet hyperlink in the second row. i.e., running the following code:
reportID = 6667768033503108
report = smartsheet_client.Reports.get_report(reportID)
url = report.rows[1].cells[1].hyperlink.url
print(url) #shows output: https://app.smartsheet.com/sheets/[ID]
This approach should work for you, but if for some reason you're seeing that the cell object in the JSON response (when using the Python SDK) for the cell that contains the link doesn't actually contain a hyperlink object with a url property -- that might indicate a bug either with the Python SDK or with the underlying API. In that case, you might try getting the URL string by using a dictionary, as shown in the following code. (Note: you'll need to import json for this code to work).
reportID = 6667768033503108
# get the report
report = smartsheet_client.Reports.get_report(reportID)
# load the contents of the second cell in the first row
resp_dict = json.loads(str(report.rows[0].cells[1]))
# read the url property from the dictionary
url = resp_dict['hyperlink']['url']
print(url) #shows output: https://www.google.com

Related

IBM Maximo REST service POST not setting attributes on MBO

I have tried to create a record of my customized object through REST service in IBM Maximo.
The problem is that I created the record but I can't assign values to the attributes.
Next I will show what I did and what happened:
I have an Object Structure called oxidato that represents my customized object.
I did a POST using POSTMAN to this URL:
http://hostname:port/maximo/oslc/os/oxidato?lean=1
In the body section this is the JSON I was trying to send:
{
"attribute1":"205",
"attribute2":"206"
}
The record was created but none of the attributes was filled.
In my opinion, the REST service received the POST but canĀ“t read the body.
What am I missing? I add an image of the POSTMAN as example:
EDIT1: I update the POST in order to use the newest API RES (Thanks Dex!)
EDIT2: I add an image of the header
I have found that Maximo will often ignore incoming attributes that aren't in the Maximo namespace (http://www.ibm.com/maximo). You could go through the trouble of setting up your VALOR1 and VALOR2 attributes to be in that namespace, but it's easier to just tell OSLC to ignore namespaces. You do that by setting the "lean" parameter to "1".
In your case, go to the "Params" tab and add an entry with a name of "lean". Give it a value of "1" and then send your POST again. You should see "?lean=1" appear at the end of the POST URL along the top there, but your body content should remain unchanged.
EDIT:
On the other hand, it looks like (based on your URL) that you aren't actually using the newer JSON/OSLC REST API; It looks like you are using the older REST services. This IBM page gives you a lot of information on the newer JSON REST API, including the correct URLs for it: https://developer.ibm.com/static/site-id/155/maximodev/restguide/Maximo_Nextgen_REST_API.html.
You should change your URL to /maximo/oslc/os/oxidato to use the newer API that naturally supports JSON and the lean parameter described above. This does required Maximo 7.6 to use though.
EDIT 2:
The attributes are often oddly case sensitive, requiring lowercase. Your example in your question of "attribute1" and "attribute2" are properly lowercase, but your screenshot shows uppercase attribute names. Try changing them to "valor1" and "valor2". Also, these are persistent attributes, right?
The response code received back (e.g. 200 - OK) and the response body will detail the record that was created.
I think you are correct in that the body of the post request is being ignored. Provided there are no required fields on the custom MBO your POST is probably creating an empty record with the next value in the sequence for the key field but you should see that in the response.
The following POST should create a record with values provided for attribute1 and attribute2 and provide a response with the record's identifier so that you can look it up in Maximo and show the values that were stored for attribute1 and attribute2:
http://hostname:port/maximo/rest/os/oxidato/?_format=json&_compact=1&attribute1=205&attribute2=206
Response: 200 OK
Reponse Body:
{ "CreateOXIDATOResponse": {
"rsStart": 0,
"rsCount": 1,
"rsTotal": 1,
"OXIDATOSet": {
"OXIDATO": {
"rowstamp": "[0 0 0 0 0 -43 127 13]",
"ATTRIBUTE1": "205",
"ATTRIBUTE2": "206",
"OXIDATOID": 13
}
} } }
You may also want to turn on debug logging for the REST interface in System Configuration -> Platform Configuration -> Logging for additional detail on what's happening in the log file.

Adding Pull Requests & Issues to a Project

Does the Github API provide an easy way to add a Pull Request or an Issue to a Project Board?
This is the programmatic equivalent of a user going to a pull request and selecting one more "Projects" from the sidebar menu
NOTE: The API does seem to provide a way to add cards to the Project, but I have to specify a specific project column. I'd love to just add the project blindly and let automation rules determine the column, similar to clicking on it through the UI.
Thanks!
I think the best way to associate an existing pull request with a project, in some kind of default column, would be to daisy-chain three separate pieces of the Github API, the Get a Single Pull Request method, the Create a Project Card method, and the List Project Columns method. The idea is as follows:
Use 'Get a Single Pull Request' to retrieve the ID
Use 'List Project Columns' to get a list of the columns
Do any conditional logic if you want to see if a certain column exists, or just use the first one, or create a certain column if it doesn't exist
Use "Create a Project Card" to add the card using the Pull request ID and Column you've selected.
Here is a simplified example in Python:
import requests, json
#get pull request
r = requests.get('https://api.github.com/repos/[myusername]/[myrepo]/pulls/2')
pull = json.loads(r.text)
#requires authentication ... create your token through Github.com
api_token = "mytoken"
#prepare dictionary of header data
h = {"Accept":"application/vnd.github.inertia-preview+json", "Authorization": "token %s" % api_token}
projects_r = requests.get('https://api.github.com/repos/[myusername]/[myrepo]/projects', headers=h)
#get projects data
projects = json.loads(projects_r.text)
#get columns url for the first project in the list projects
columns_url = projects[0]['columns_url']
columns_r = requests.get(columns_url, headers=h)
columns = json.loads(columns_r.text)
#get column url for the first column in the list of columns
column_url = columns[0]['cards_url']
#use retrieved data to build post
data = {"content_id":pull_id, "content_type":"PullRequest"}
#use post method with headers and data to create card in column
result = requests.post(column_url, headers=h, data=json.dumps(data))
#returns with status 201, created

How to get a working document preview link from MS Graph

I am trying to get a preview link for the useres recent documents over MS Graph. Unfortunately the link the endpoint returns does not work.
To get the informations about a file I first call GET https://graph.microsoft.com/beta/me/drive/recent. Then I copy the driveID and the id of a document from the parentReference property.
To get the preview link I use the Endpoint POST https://graph.microsoft.com/beta/drives/<DriveID>/items/<DocumentID>/preview
and this works fine. But when I click on the link I get the error "This item might not exist or is no longer avaiable". The document exists on the SharePoint, otherwise it would not appear under "recent documents". The url looks like this: https://www.onedrive.com/embed?webUrl=xyz.sharepoint.com/sites/nameOfTheSite/docLibName&id=sites/nameOfTheSite/DocLibName&embed=xxx&authToken=xxx
I expect the response of the /preview endpoint should return a working url. Do I have to make some configurations on O365?
Many Thanks
The embed link (preview) does not look valid in your example since id parameter refers to container (library): sites/nameOfTheSite/DocLibName. It is not supported, instead embed link should refer to a file
Most likely the issue is due to itemId:
https://graph.microsoft.com/beta/drives/<DriveID>/items/<DocumentID>/preview
^^^^^^^^^^^^
in your example it seems refers to a library instead of a file. Make sure the proper itemId is specified.
For example, https://graph.microsoft.com/v1.0/me/drive/recent endpoint returns the following payload:
{
"value" : {
//another properties are omitted for a clarity
//...
"remoteItem": {
"id": "01ECKZLCWSR7F76B64KZFL7I3QGZVPJELU"
//...
"parentReference": {
"driveId": "b!79yKq-2MdkSDnQ7_1Pf3FOkRyDCajpRIvqtA7UrsEO-vu3D_qkpaT50Y6CMcSmFv",
"driveType": "documentLibrary",
"id": "01ECKZLCV6Y2GOVW7725BZO354PWSELRRZ"
},
}
}
}
where
remoteItem.Id - corresponds to item id for a file
remoteItem.parentReference.driveId - corresponds to drive id
Dont get confused with remoteItem.parentReference.Id which corresponds
to item id of library

How to crawl data from encrypted url?

I'm trying to use scrapy to collect the university's professors' contact information from its directory. Since I can't post more than 2 links, I put all links in the following picture.
I set last name equals from the drop-down menu as shown in the picture. Then I search all professors by last name.
Usually, the url will have some pattern from other universities' website. However, for this one, the original url is (1). It becomes (2)when I search 'An' as last name. It seems like 'An' is replaced by something like 529385FD5FF90A198625819E002B8B41? I'm not sure. Is there any way I can get the url that I need to send as a request? I mean, this time I search 'An'. If I search another last name like Lee. It will be another request. They are irregular. I can't find a pattern.
The scraper is not as complex as you think it is. It just makes a POST call from the form and that returns a GET request. Below would work
import scrapy
from scrapy.utils.response import open_in_browser
class univSpider(scrapy.Spider):
name = "univ"
start_urls = ["http://appl103.lsu.edu/dir003.nsf/(NoteID)/5903C096337C2AA28625819E0038E3E4?OpenDocument"]
def parse(self, response):
yield FormRequest.from_response(response, formname="_DIRVNAM", formdata={"LastName": "Lalwani"},callback = self.search_result)
def search_result(self, response):
open_in_browser(response)
print(response.body)

Manage Titles when Uploading Multiple Images

It would be great if we could manage the titles of each image that we upload when uploading multiple images. This way I could select each image that I want to upload, title them, then hit the upload button. Right now one must either upload one by one or have all the selected images have the same title.
Kinda like Facebook or Panoramio where it's easy to manage the titles of the images before uploading.
This isn't natively supported in Fine Uploader at the moment, but I've opened up a feature request and tentatively scheduled it for the 3.7 milestone. In the meantime, you can certainly provide your own UI elements to allow users to provide alternate names for each upload-able item and pass these new names as a parameter. Server-side, you would have to parse this parameter and associate it with the uploaded item. Fine Uploader will have to adopt a parameter name that contains the user-supplied alternate filename anyway (and the server will have to be aware of this convention and parse this parameter), since we won't be able to change the value file input field sent along with the multipart encoded request.
use this:
var uploader = $('.uploader'),
titleBox = $('input[type=text]');
uploader.fineUploader({
request: {
endpoint: 'path/to/url'
},
formatFileName: function (name) {
var title = titleBox.val() + ' - ' + name + '';
titleBox.val('');
return title;
},
});
uploader.on('submit', function (event, id, name) {
uploader.fineUploader('setParams', {title: titleBox.val()}, id);
});