Due to a bug in the Azure portal, I am needing to create an Azure Cognitive Search data source, index, and indexer programmatically using the REST API. There were no issues creating the data source or index, but the POST request below returns the following error.
{
"error": {
"code": "",
"message": "The request is invalid. Details: dataSource : A resource without a type name was found, but no expected type was specified. To allow entries without type information, the expected type must also be specified when the model is specified.\r\n"
}
}
The following POST request is a modified example found on this page, with the variables replaced with the correct names of the service-name, admin-key, dataSourceName and targetIndexName.
POST request (using postman)
POST https://SERVICENAME.search.windows.net/indexers?api-version=2019-05-06
Content-Type: application/json
api-key: ADMINKEY
{
"name" : "my-json-indexer",
"dataSourceName" : "BLOBDATASOURCE",
"targetIndexName" : "TARGETINDEX",
"schedule" : { "interval" : "PT2H" },
"parameters" : { "configuration" : { "parsingMode" : "json" } }
}
Seems that when you've created your data source, the type property was not provided.
Here's the two requests:
Create data source
POST https://[service name].search.windows.net/datasources?api-version=2019-05-06
Content-Type: application/json
api-key: [admin key for Azure Cognitive Search]
{
"name" : "my-blob-datasource",
"type" : "azureblob",
"credentials" : { "connectionString" : "DefaultEndpointsProtocol=https;AccountName=<account name>;AccountKey=<account key>;" },
"container" : { "name" : "my-container", "query" : "optional, my-folder" }
}
Create indexer
POST https://[service name].search.windows.net/indexers?api-version=2019-05-06
Content-Type: application/json
api-key: [admin key for Azure Cognitive Search]
{
"name" : "my-json-indexer",
"dataSourceName" : "my-blob-datasource",
"targetIndexName" : "my-target-index",
"schedule" : { "interval" : "PT2H" },
"parameters" : { "configuration" : { "parsingMode" : "json" } },
"fieldMappings" : [
{ "sourceFieldName" : "/article/text", "targetFieldName" : "text" },
{ "sourceFieldName" : "/article/datePublished", "targetFieldName" : "date" },
{ "sourceFieldName" : "/article/tags", "targetFieldName" : "tags" }
]
}
Related
I am using the Salesforce REST APIs to create a Contact and then an associated User. If I allow the creation of a User (via SCIMv2) to create an Account and Contact automatically (as details at link), the creation works. Unfortunately, I need to populate a custom field in the Contact and must create it separately.
The link also states that I can include the AccountId and ContactId to prevent the auto-creation. To do this I include the specified Account and Contact in the SCIMv2 JSON as shown below.
{
"schemas" : [ "urn:ietf:params:scim:schemas:core:2.0:User", "urn:salesforce:schemas:extension:external:2.0", "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User" ],
"userName" : "fred.bloggs#example.com",
"name" : {
"familyName" : "Bloggs",
"givenName" : "Fred"
},
"emails" : [ {
"type" : "work",
"primary" : true,
"value" : "fred.bloggs#example.com"
} ],
"preferredLanguage" : "en_US",
"locale" : "en_AU",
"timezone" : "Australia/Hobart",
"active" : true,
"entitlements" : [ {
"value" : "00e5j000000md3VAAQ"
} ],
"urn:salesforce:schemas:extension:external:2.0" : {
"contactId" : "0039D00000JBLfvQAH",
"accountId" : "0019D00000OkFMYQA3"
}
}
When I make this request I get an error response from Salesforce:
Response Status:400 - Insert failed. First exception on row 0; first error: DUPLICATES_DETECTED, You're creating a duplicate record. We recommend you use an existing record instead.
Since there is definitely not a User object already in the system for this user, I am assuming it's trying to create the Contact again and failing.
Any help to understand what is happening and what I am doing wrong would be appreciated.
I want to set the createdDate for a new feed-element (via SalesForce Rest API).
I tried to do this:
{
"body" : {
"messageSegments" : [
{
"type" : "Text",
"text" : "When should we meet for release planning? "
}]
},
"feedElementType" : "FeedItem",
"subjectId" : "0060Y00000XYZXYZ",
"createdDate ": "2016-10-27T08:01:56.000Z"
}
But I get this error message:
[
{
"errorCode": "JSON_PARSER_ERROR",
"message": "Unrecognized field \"createdDate \" at [line:-1, column:-1]"
}
]
I read that I can set the createdDate via API (https://developer.salesforce.com/docs/atlas.en-us.chatterapi.meta/chatterapi/connect_resources_feed_element.htm), but I don't find a example or a way to do this.
Also I tried to set the createdDate in a update request, but the same result.
I hope someone can help me. Thanks!
I am successfully sending emails using SendGrids Web API v3 but can't get the subsitutions to work when sending emails using templates. The emails come through successfully but no substitutions take place. Here is my (simplified) SendGrid template:
<html>
<head>
<title></title>
</head>
<body>
<div>You can reset your password by clicking on this link: {callbackUrl}</div>
<%body%>
</body>
</html>
And here is the JSON formatted body I'm sending:
{
"personalizations":[
{
"to":[
{
"email":"destinationemail#gmail.com"
}
]
}
],
"sub" : {
"{callbackUrl}" : "www.mysite.com/changepassword"
},
"from":{
"email":"example#example.com"
},
"template_id" :"5f852a2e-996b-4f04-be05-31766d1092d8",
"subject":"Reset your password",
"content":
[
{"type": "text/plain", "value": "Thank you"}]
}
The email is generated with the correct template, subject, and is sent to the correct email address however the email body contains the template without substitutions:
You can reset your password by clicking on this link: {callbackUrl}
Thank you
I'm at a loss as to what I'm doing wrong. I'm using currently using Postman to send the request while attempting to track down the issue.
You need to use key substitutions under personalizations, not sub as it's said in the docs. Also it has different structure than sub.
{
"personalizations" : [ {
"substitutions" : {
":name" : "John"
},
"subject" : "Hello from Java",
"to" : [ {
"email" : "john#example.com"
} ]
} ],
"from" : {
"email" : "john#example.com"
},
"template_id" : "11111111-1111-1111-1111-111111111111"
}
How can I get in a call back after inserting a file using collectionFS the key value?
Images.insert(file, function (err, fileObj) {
if (err) {
console.log(err);
} else {
console.log('success', fileObj);
setTimeout(function () {
console.log('url', fileObj.url());
let url = fileObj.url('images');
$scope.slideshows.url = `${url}`
$scope.$apply();
}, 2000);
}
});
I'm building a cms which handles file uploads to show in different apps, I'm able to see the uploaded file using {{image.url}} in the cms but I'm unable to view the images uploaded using this method in the other apps.
Every app is connecting to the same database and I'm uploading the images into my server using:
Images = new FS.Collection("images", {
stores: [new FS.Store.FileSystem("images", {path: '/home/uploadedimages'})]
});
I'm then using nginx to serve those images so I can access them via http://domain.com/uploadedimages.
In order to fix my problem I need to somehow get the key value in this schema stored by collectionFS:
{
"_id" : "5BEe4maLCMFtHAZAj",
"original" : {
"name" : "wantedposter.jpg",
"updatedAt" : ISODate("2016-05-19T13:34:32.050Z"),
"size" : 28828,
"type" : "image/jpeg"
},
"uploadedAt" : ISODate("2016-05-19T21:30:54.299Z"),
"copies" : {
"images" : {
"name" : "wantedposter.jpg",
"type" : "image/jpeg",
"size" : 28828,
"key" : "images-5BEe4maLCMFtHAZAj-wantedposter.jpg",
"updatedAt" : ISODate("2016-05-19T21:30:54Z"),
"createdAt" : ISODate("2016-05-19T21:30:54Z")
}
}
}
So I can do /uploadedimages/:key
QUESTION
Is there a way to get the key value from collectionFS?
It is not clear to me the best practice for maintaining $scope of objects when making calls to a RESTful API. The problem I'm having is working with a Schema that has nested sub arrays, see below.
Is it best practice when making RESTful API call to expect a full JSON document in the response to update the $scope, or should I be able to maintain $scope on the client with Angular with nothing more than a http response code (ie 200)? It makes sense when making updates to the user object, but when I need to update profiles or favorites sections of the document, I'm just passing that portion of the document to the API and getting an http reponse code back, and my $scope doesn't reflect with the change, especially when pushing or pulling over PATCH route.
{
"_id" : ObjectId("558d53eebdd9804820090fa1"),
"name" : "Frank",
"email" : "Frank#FrankTheTank.com",
"profiles" : [
{
"avatar" : "div-male",
"age" : "35",
"gender" : "Male",
"profilename" : "Oly Lifter",
"_id" : ObjectId("558d5404bdd9804820090fa2"),
"favorites" : [
{
"name" : "Power Clean"
},
{
"name" : "Hang Clean"
},
{
"name" : "Clean and Jerk"
}
],
"createdAt" : ISODate("2015-06-26T13:30:44.661Z")
}
],
"createdAt" : ISODate("2015-06-26T13:30:22.884Z"),
"role" : "user"
}