Using the ScanR API from gouv.fr for a POST request that, given a company name, returns its id - rest

I'm trying to use the ScanR API:
Technical documentation: https://scanr-api.enseignementsup-recherche.gouv.fr/api/swagger-ui.html
General presentation: https://api.gouv.fr/les-api/scanR
Online interface: https://scanr.enseignementsup-recherche.gouv.fr/
My goal is to give the API a structure/company name, and receive, among others, a structure/company id. Then I am able use the GET endpoint '/v2/structures/structure/{id}' to access the description.
I believe that to do this, I would use the POST endpoint '/v2/structures/search'.
However, I don't manage to structure the query in a way that works.
Can anyone give me an example?

The scanR team kindly provided an example that I share here:
url_structures = "https://scanr-api.enseignementsup-recherche.gouv.fr/api/v2/structures/search"
my_query = "carbon\ waters"
params = {
"pageSize": 12,
"query": my_query
}
scanr_output = requests.post(url_structures, json=params).json()

Related

Salesforce REST API how to avoid leaking sensitive data in query parameter

I'm trying to do query using REST API, and ran into the following problem:
Using GET request on the query endpoint exposes the entire query string, which may contain sensitive data such as SSN, phone number, etc...
https://[instance-url].my.salesforce.com/services/data/v48.0/query/?q=SELECT Id FROM Contact WHERE SSN__c = '123456789'
How can I do such a query using rest api securely?
IS there an equivalent request I can make using at least POST request with post body being the query? since that part is encrypted over https.
Thank you for help
You have two options.
Parameterized Search API. This option is available out of the box with POST as the method. The API is a RESTful interface to Salesforce's text-based search engine. Normally, text-based search uses SOSL as the query language. Parameterized Search API skips SOSL and gives you an easier option to work with.
If you POST the following body to /services/data/v48.0/parameterizedSearch
{
"q": "123456789",
"sobjects": [
{
"name": "Contact",
"where": "SSN__c = '123456789'"
}
],
"fields": ["id"]
}
you should see something like this as the response, assuming single record is returned by search (ID is redacted):
{
"searchRecords" : [ {
"attributes" : {
"type" : "Contact",
"url" : "/services/data/v48.0/sobjects/Contact/003..."
},
"Id" : "003..."
} ]
}
The value of q key in the JSON payload must be the same as the value in the where key/clause. You're doing a full-text search on 123456789 across all objects and all fields in the search index. This could return many records..but you're filtering the search down in a structured way to guarantee that you'll only see Contact records where SSN__c = '123456789'. As long as the objects + fields you're trying to retrieve are present in the index the results you'll see via Parameterized Search in this specific example are going to be the same as that of a SOQL query via /query
Custom REST API (aka Apex REST / Apex web service). This is a typical implementation option for cases like yours. You can send whatever payload via POST and then process it however you like.
Apex class:
#RestResource(urlMapping='/findcontactbyssn')
global class ContactResource {
#HttpPost
global static void findContactBySSN() {
SearchRequest input = (SearchRequest)JSON.deserialize(RestContext.request.requestBody.toString(),SearchRequest.class);
Contact c = [SELECT Id FROM Contact WHERE SSN__c = :input.ssn];
SearchResponse output = new SearchResponse();
output.id = c.id;
RestContext.response.responseBody = Blob.valueOf(JSON.serialize(output));
RestContext.response.statusCode = 200;
}
class SearchRequest {
public String ssn {get;set;}
}
class SearchResponse {
public String id {get;set;}
}
}
POST to /services/apexrest/findcontactbyssn with
{
"ssn": "12345678"
}
and you should see this response:
{
"id": "003..."
}
AFAIK, salesforce only provides a GET method for executing SOQL queries. One can write their own REST endpoint in their org that accepts a query in body and execute it, but thats a waste of time in my opinion.
Query string parameters are secured over https. Its a common misconception, where people think whole url is open in plain text in transmission. When a request is made to an https url, first it establishes a Secure Tunnel to [instance-url].my.salesforce.com then transmits the rest of the url and any other data over the secure tunnel.
If you're worried about some man in the middle attack sniffing out the SSN from your query string, don't. One downside is, if you are accessing this url from a browser instead of a programmatic call, then there is a chance for browser to stored/cache for history or auto complete, then it won't be so good.
But I doubt if you would be able to do this via browser, as salesforce requires a bearer token set in Authorization header and there is no easy way that I know of to set headers while typing the url in the browser or clicking a link.
To know more about how query string is secure over https please refer to this stackoverflow question

Obtain specific data from Google Firestore using Rest API calls (HTTP-GET)

Problem
I want to retrieve specific data from Google Firestore.
It's only possible to get all of the 'Fields' data. But no specific data within fields
Example of the GET-Request:
https://firestore.googleapis.com/v1beta1/projects/edubox-49528/databases/(default)/documents/nodes/EduBox-1234567?key=[My_API_KEY]&fields=fields
As you can see, It is possible to obtain all the items in the object 'Fields'. But it is not possible to get any further into detail to obtain more specific data (test, message, nodeID, ...)
Tryouts
I have already tried:
fields=fields/test
fields=fields.test
fields=fields(test)
fields=fields/test/integerValue
...
Expected Results
I want to obtain specific data like the String / integer value of my objects in 'Fields'.
This example should return the integerValue with 30
https://firestore.googleapis.com/v1beta1/projects/edubox-49528/databases/(default)/documents/nodes/EduBox-1234567?key=[My_API_KEY]&fields=fields/test
This example should return 30
https://firestore.googleapis.com/v1beta1/projects/edubox-49528/databases/(default)/documents/nodes/EduBox-1234567?key=[My_API_KEY]&fields=fields/test/integerValue
Solution
While browsing the web, I came across Google Api Explorer:
https://developers.google.com/apis-explorer/#search/firestore/firestore/v1beta1/
When trying out some possibilities, I came across this:
https://firestore.googleapis.com/v1/projects/edubox-49528/databases/(default)/documents/nodes/EduBox-1234567?mask.fieldPaths=nodeID&fields=fields&key={YOUR_API_KEY}
This gives me the right information
but I still need a more detailed form of this answer like only the 'EduBox-1234567'
The way to retrieve a specific field is to use mask.fieldPaths. For example the following GET method:
https://firestore.googleapis.com/v1beta1/projects/edubox-49528/databases/(default)/documents/nodes/EduBox-1234567?key=[My_API_KEY]&fields=fields&mask.fieldPaths=nodeID
is going do return:
{
"fields": {
"nodeID": {
"stringValue": "EduBox-1234567"
}
}
Documentation references here and here.

Facebook InsightsAPI calls limited to 25 entries

I'm pretty new to programming and I'm currently trying to use the InsightsAPI of Facebook in order to extract our performance data. The problem is that the response of the API call is limited to 25 entries.
I use the following code for the call:
String access_token = "xxx";
String ad_account_id = "yyy";
setApp_secret("zzz");
APIContext context = new APIContext(access_token).enableDebug(false);
APINodeList<AdsInsights> response = new AdAccount(ad_account_id, context).getInsights()
.setLevel(AdsInsights.EnumLevel.VALUE_CAMPAIGN)
.setBreakdowns(Arrays.asList(AdsInsights.EnumBreakdowns.VALUE_COUNTRY))
.setTimeRange("{\"since\":\"2017-09-01\",\"until\":\"2017-09-30\"}")
.requestField("account_id")
.requestField("campaign_id")
.requestField("impressions")
.requestField("clicks")
.execute();
How can I extend the limit of the response? I found some information about how to do this via curl but there were no hints on how to do this with java. Would be great if anyone of you could help me!
All the best,
Paul
All the responses of Graph API are paginated which means you will get at most 'x' number of results where 'x' is 25 by default at the moment.
You can specify a higher value using limit param but it is not recommended as it is likely to cause a timeout.
You should look into using pagination instead: https://developers.facebook.com/docs/graph-api/using-graph-api/#paging

Unable to retrieve 'ContentId' property of Attachment in Office365 REST Api

I'm trying to retrieve attachments in the Office365 rest api. Since I want to avoid downloading the entire attachments, I'm using a select clause to avoid downloading the content, which is in the ContentBytes property:
$select="ContentId,ContentType,Id,IsInline,Name,Size"
So basically, I want to retrieve everything except the content. However, this gives the following error message (json):
{
"error":
{
"code": "RequestBroker-ParseUri",
"message": "Could not find a property named 'ContentId' on type 'Microsoft.OutlookServices.Attachment'."
}
}
It's telling me that ContentId doesn't exist, which contradicts the specifications.
Edit: Here is the full request:
GET /api/v2.0/me/messages/AAMkAGZlZjI3N2I3LTg1YWUtNDFiNC05MGI0LTVjYTVmZGI5NGI2YQBGAAAAAABzr8uDji9LRqgTCEsDv22wBwBWTXbvZW0dTKuxUGxpK4-lAAAAAAEMAABWTXbvZW0dTKuxUGxpK4-lAAC5QnKBAAA=/attachments?%24select=ContentId%2CContentType%2CId%2CIsInline%2CName%2CSize
Even more strange, when I do the same query without specifying any select clause, it returns me a full attachment object, including a ContentId.
Anybody can help?
In case anyone has the same question for microsoft graph, you need to pass this filter:
$select=microsoft.graph.fileAttachment/contentId
like this:
GET https://graph.microsoft.com/v1.0/me/messages/attachments?$select=microsoft.graph.fileAttachment/contentId
The request that you posted is getting the message specifications but not the attachments. Since you need to get the content id, you need to add /attachments to the request with any required parameters.
GET https://outlook.office.com/api/v2.0/me/messages/{message_id}/attachments/{attachment_id}
So please add the attachments to your query to be able to get the content id.
Hope this helps.
Solved it. The answer was suggested by Brian's comment and I found an additional hint here.
Since 'ContentId' is a property of a FileAttachment, you need to specify that in the request, like so:
$select="Microsoft.OutlookServices.FileAttachment/ContentId,ContentType,Id,IsInline,Name,Size"
That did the trick. Thanks for the suggestions.

How to get a single gist from github with GET /gists/:id

Somehow I fail to get a single gist from github.
Lets say i would like to get the following gist: https://gist.github.com/jrm2k6/6637633
Just copy&paste in URL field of your browser.
With https://api.github.com/users/jrm2k6 I can get the users info as json.
With https://api.github.com/users/jrm2k6/gists I can list all the public gists from this user as json.
But how do I get a specific gist GET /gists/:id with the id = 6637633 like it is described here in the api documentation: http://developer.github.com/v3/gists/#get-a-single-gist
With https://api.github.com/users/jrm2k6/gists/6637633 I should receive the content of the gist as json but instead I receive an error
{
"message": "Not Found",
"documentation_url": "http://developer.github.com/v3"
}
What am I doing wrong?
SOLUTION: You do not need the /users/:user. Working: https://api.github.com/gists/6637633
The documentation for all gists mentions
GET /users/:user/gists
Notice that the documentation for a single gist mentions
GET /gists/:id
so you do not need a user. https://api.github.com/gists/6637633 will work.