Quick problem here that I don't know how to solve and thought you guys could give me a heads-up on which way to go. I have successfully pulled all my connection data using the LinkedIn REST API both in XML and JSON and dumped them (the former using the cPickle plugin). The issue is that I need to refer to a single field within the data and so decided to use XML as it seemed to be the easiest one to use by far. When I refer to the specific field in my .pickle file, it gives me the following error:
AttributeError: 'str' object has no attribute 'location'
However, opening the pickle file with notepad, I can see that all my connections do have their location field stored in the XML format. It's very strange!
Here's my referral code:
import cPickle
connections_data = 'linkedin_connections.pickle'
response = cPickle.load(open(connections_data))
print response
locations = [ec.location for ec in response]
I have a print function set up to show what's in my file and all of the data appears as a normal XML output using the people call of the REST API. The XML data appears as follows:
<person>
<id>ID_number</id>
<first-name>blah</first-name>
<last-name>blah</last-name>
<headline>Business Development and Sales Executive at Computaris</headline>
<picture-url>picture_url</picture-url>
<api-standard-profile-request>
<url>profile_request</url>
<headers total="1">
<http-header>
<name>x-li-auth-token</name>
<value>name</value>
</http-header>
</headers>
</api-standard-profile-request>
<site-standard-profile-request>
<url>request_url</url>
</site-standard-profile-request>
<location>
<name>location</name>
<country>
<code>country_code</code>
</country>
</location>
<industry>industry</industry>
Any help will be much appreciated.
Related
I am trying to retrieve a value from a HTTP web service call in sharepoint designer. This should be simple. the Rest query is simple, and always returns only a single value:
https://Site.sharepoint.com/sites/aSiteName/_api/web/lists/getByTitle('MyListTitle')/items/?$select=Title&$top=1
In the Sharepoint Designer workflow, I'm setting the required Accept and Content-type header to the value of "application/json;odata=verbose
I am unable to get the value of the "Title" field that is returned by the call.
when I execute the REST query in the browser, I get the following data returned:
{"d":{"results":[{"__metadata":{"id":"af9697fe-9340-4bb5-9c75-e43e1fe20d30","uri":"https://site.sharepoint.com/sites/aSiteName/_api/Web/Lists(guid'6228d484-4250-455c-904d-6b7096fee573')/Items(5)","etag":"\"1\"","type":"SP.Data.MyListName"},"Title":"John Doe"}]}}
I've tried dozens of variations of the dictionary 'query', but they always return blank.
I'm using the 'get an item from a dictionary' action in SP Designer, using item name or path values like:
d/results(0)/Title
d/Title
d/results/Title
and literally dozens of other variations - but it always returns blank.
I'm writing the raw response from the webRequest to the list for debugging, and it shows the value like this:
{"odata.metadata":"https:\/\/site.sharepoint.com\/sites\/aSiteName\/_api\/$metadata#SP.ListData.MyListTitle&$select=Title","value":[{"odata.type":"SP.Data.MyListTitle","odata.id":"616ed0ed-ef1d-405b-8ea5-2682d9662b0a","odata.etag":"\"1\"","odata.editLink":"Web\/Lists(guid'6228d484-4250-455c-904d-6b7096fee573')\/Items(5)","Title":"John Doe"}]}
I must be doing something simple that is wrong?
Using "d/results(0)/Title" is right. Check the steps in article below to create a workflow.
CALLING THE SHAREPOINT 2013 REST API FROM A SHAREPOINT DESIGNER WORKFLOW
It working fine in my test workflow.
I faced the exact same issue. In my case the reason was that in the API call, the header was not set properly.
As you would have noticed many times, that if you type the variables inline when creating the "Call Http Web service" action, those might not get set properly. The surest way is to open the properties and set from there. In my case when i opened the properties i found that RequestHeaders was not set. Once i set it from there, i got the desired results.
Hope this helps to someone in future, this question being unanswered till now!!
tried dump those json called from sharepoint workflow into a list. Sometimes you'll get a different format than when you called that from browser. I experienced this issue when calling API projectserver (project online). When I called it using servistate (chrome extension) it returns d/results, but when I dump the value into the list I got value and yet I used same request header value.
I'm trying to search for a given user on a Sharepoint site using "lastname, firstname". I was able to use the following url to get the total list of site users as a large XML document:
https://thissite.com/sites/thatsite/_api/web/siteusers/
However, I haven’t been able to figure out how to search by Title. When I use the following url:
https://thissite.com/sites/thatsite/_api/web/siteusers/getbytitle(“lastname,%20firstname”)
I get this error:
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<m:code>
-1, Microsoft.SharePoint.Client.InvalidClientQueryException
</m:code>
<m:message xml:lang="en-US">
The expression "web/siteusers/getbytitle("lastname, firstname")" is not valid.
</m:message>
</m:error>
When I use the following url to get the same user's data:
https://thissite.com/sites/thatsite/_api/web/siteusers/getbyid(41)
Then I successfully get XML returned with that user's data.
I guess I could just parse the list obtained from /siteusers and load it into a searchable data object, but I was hoping for something more direct.
UserCollection resource does not expose getbytitle method, that's the reason why you get this exception.
In order filter user by title you could utilize $filter query option as demonstrated below:
https://contoso.sharepoint.com/_api/web/siteusers?$filter=Title eq '<Title>'
I'm building an application that inserts documents into MarkLogic server using the MLPHP library. The problem is when I insert a binary document, for example a PDF. The mime type will not be set properly, therefore the file cannot be opened as it should.
This is the code I use to insert a document:
// initialize REST client
$client = new MLPHP\RESTClient('127.0.0.1', 8010, 'v1', '', 'rest-writer-user', 'writer-pw');
// create new document and load content
$doc = new MLPHP\Document($client);
$doc->setContentType("application/pdf");
$doc->setContentFile("demo.pdf");
$doc->write('pdf_demo');
This is a dump of the $doc object after submitting to the server:
And here we have the inserted document in the search results:
But as expected, the browser cannot handle the file due to the wrong mimetype:
Anyone has got a clue what's going wrong here?
Check to see what the Response Header for content type is.
You Might have to set the format URL Parameter to binary. You can read the full documentation at http://docs.marklogic.com/REST/GET/v1/documents
here is what the request would look like
http://localhost:8010/v1/documents?uri=/pdf_demo.pdf&format=binary
...just wanted to confirm that since the latest soundcloud api does not provide a data interface, we are left with parsing the results from an http request.
my concern is that the resulting structure could change at anytime and thus render my parsing schema invalid. is anyone else doing something similar? or better?
This is correct. All SoundCloud API responses will be serialized as JSON or XML. We take backwards compatibility pretty seriously, so you can rely on the format and data returned.
Most languages have at least one library capable of automatically parsing JSON into an appropriate data type (i.e. an array of hashes). You can always check to ensure a key exists before you try to access it, for example in Python:
import json
import urllib
url = 'https://api.soundcloud.com/tracks.json'
fp = urllib.urlopen('%s?%s' % (url, urllib.urlencode({
'client_id': 'YOUR_CLIENT_ID',
'limit': 2
})))
data = fp.read()
tracks = json.loads(data)
for track in tracks:
print track.get('title', 'No title available')
Does that help answer your question?
I am trying to use HTTP to POST a file to an outside API from within a grails service. I've installed the rest plugin and I'm using code like the following:
def theFile = new File("/tmp/blah.txt")
def postBody = [myFile: theFile, foo:'bar']
withHttp(uri: "http://picard:8080/breeze/project/acceptFile") {
def html = post(body: postBody, requestContentType: URLENC)
}
The post works, however, the 'myFile' param appears to be a string rather than an actual file. I have not had any success trying to google for things like "how to post a file in grails" since most of the results end up dealing with handling an uploaded file from a form.
I think I'm using the right requestContentType, but I might have missed something in the documentation.
POSTing a file is not as simple as what you have included in your question (sadly). Also, it depends on what the API you are calling is expecting, e.g. some API expect files as base64 encoded text, while others accept them as mime-multipart.
Since you are using the rest plugin, as far as I can recall it uses the Apache HttpClient, I think this link should provide enough info to get you started (assuming you are dealing with mime-multipart). It shouldn't be too hard to change it around to work with your API and perhaps make it a bit 'groovy-ier'