SalesForce Chatter Rest API - Can not set CreatedDate - salesforce

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!

Related

Problem creating a Salesforce User via SCIMv2 when specifying ContactId

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.

React + Apollo "Getting Started" Error in Prisma Playground

I am in the Getting Started React + Apollo chapter: https://www.howtographql.com/react-apollo/1-getting-started/
When I enter the following query in the Prisma Playground (as the tutorial tells me to do):
mutation CreatePrismaLink {
post(
description: "Prisma gives you a powerful database toolkit 😎"
url: "https://prisma.io"
) {
id
}
}
mutation CreateApolloLink {
post(
description: "The best GraphQL client for React"
url: "https://www.apollographql.com/docs/react/"
) {
id
}
}
I get this error message that I don't understand. It seems to be something about the server
"errors": [
{
"message": "Argument id for data.postedBy.connect.id must not be null. Please use undefined instead.\n",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"post"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"clientVersion": "2.12.1",
"stacktrace": [
"Error: Argument id for data.postedBy.connect.id must not be null. Please use undefined instead.",
"",
" at Document.validate (C:\\Users\\shanm\\hackernews-react-apollo\\server\\node_modules\\#prisma\\client\\runtime\\index.js:77413:19)",
" at NewPrismaClient._executeRequest (C:\\Users\\shanm\\hackernews-react-apollo\\server\\node_modules\\#prisma\\client\\runtime\\index.js:79065:17)",
" at C:\\Users\\shanm\\hackernews-react-apollo\\server\\node_modules\\#prisma\\client\\runtime\\index.js:79002:52",
" at AsyncResource.runInAsyncScope (async_hooks.js:197:9)",
" at NewPrismaClient._request (C:\\Users\\shanm\\hackernews-react-apollo\\server\\node_modules\\#prisma\\client\\runtime\\index.js:79002:25)",
" at Object.then (C:\\Users\\shanm\\hackernews-react-apollo\\server\\node_modules\\#prisma\\client\\runtime\\index.js:79119:39)",
" at processTicksAndRejections (internal/process/task_queues.js:93:5)"
]
}
}
}
],
"data": null
}
please help me find the problem?
This is old but in case somebody else hits this issue and Googles it like me:
Unfortunately the answer here didn't work for me, but the solution is something that was covered in the Node+GraphQL tutorial, which you might not be able to figure out on your own:
In order to post you have to first create a user and then be authorized as that user. The mutation to create a user is listed as an example on the page, but unfortunately the author forgot to instruct the reader to run it before trying to create a post.
Paste this into the playground to create a user
mutation {
signup(name: "Sarah", email: "sarah#prisma.io", password: "graphql") {
token
user {
id
}
}
}
Copy the token that is returned
Open the "HTTP Headers" pane in the bottom left
Enter this with your token:
{
"Authorization": "Bearer TOKEN_HERE"
}
Now you can run the mutations to create the posts
That's because the server has been written with the business rule in mind that a Post will always belong to a User. The database has a NOT NULL postedById field on the Link table i.e. a post will always have a user id attached to it. You need to make postedById field nullable in the Link model in the Prisma ORM schema. To fix this, make the following changes on server side code and relaunch the server
In the server folder go to schema.prisma file, and make both fields postedBy and postedById optional/nullable by suffixing them with ?
postedBy? User #relation(fields: [postedById], references:[id])
postedById? Int
Then run the following command to recreate database with the changes
npx prisma migrate reset
Update the post resolver function in Mutation.js file to replace the line
postedBy: { connect: { id: userId } }
with
postedById: userId,
because prisma connect api does not accept a null value

How to create an Azure Search indexer using the REST API

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" }
]
}

Firebase Cloud Firestore - Fail to write via REST API

This is not an authentication error, write is enabled on the database rules.
My cloud Firestore database looks like the picture below.
There is a COLLECTION called colA, inside it there is a DOCUMENT called docA, and inside it there are some fields (strings) stored.
On Postman, if I do GET https://firestore.googleapis.com/v1/projects/eletronica-ab6b1/databases/(default)/documents/colA/docA, I do receive the following answer, and it is correct:
{
"name": "projects/eletronica-ab6b1/databases/(default)/documents/colA/docA",
"fields": {
"fieldB": {
"stringValue": "ABCD"
},
"fieldA": {
"stringValue": "888"
}
},
"createTime": "2020-01-31T16:48:26.859181Z",
"updateTime": "2020-02-05T19:21:49.654340Z"
}
Now, when I try to write a new field (fieldC) via POST https://firestore.googleapis.com/v1/projects/eletronica-ab6b1/databases/(default)/documents/colA/docA, with JSON content:
{
"name": "projects/eletronica-ab6b1/databases/(default)/documents/colA/docA",
"fields": {
"fieldC": {
"stringValue": "1000"
}
}
}
After SEND, I receive this:
{
"error": {
"code": 400,
"message": "Document parent name \"projects/eletronica-ab6b1/databases/(default)/documents/colA\" lacks \"/\" at index 60.",
"status": "INVALID_ARGUMENT"
}
}
What I'm doing wrong? I really would like to write strings there via REST API.
Regards.
Updating a document is done with a PATCH request, according to the [reference documentation).
A POST request is used to create a new document in a collection, which probably explains the error you get: you're pointing to a document, but POST expects a collection path.

Error when calling the ApiMethod with optional parameters

I have created a ApiMethod and marked couple of arguments as #Nullable. From my client webpage when i am making a request its throwing the below error. It was worked fine when i tested the samples (Greetings.java). But not in my API. Any ideas what I am missing?
{
"error" : {
"message" : "java.lang.IllegalArgumentException",
"code" : 400,
"errors" : [ {
"domain" : "global",
"reason" : "badRequest",
"message" : "java.lang.IllegalArgumentException"
} ]
}
}
Here is my code samples:
import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.Named;
import com.google.api.server.spi.config.Nullable;
#ApiMethod(name = "adddetails", path = "admin/adddetails")
public Details addDetails(
#Named("date") long date,
#Named("hours") int hours,
#Named("weekend") #Nullable boolean weekend,
#Named("holiday") #Nullable boolean holiday
Inside my webpage (html page)
var request = api.adddetails({
"date": date.getTime(),
"hours": 0
});
request.execute();
If I ran below lines then the ApiMethod is called without any errors:
var request = api.adddetails({
"date": date.getTime(),
"hours": 0,
"weekend": row.weekend,
"holiday": row.holiday
});
request.execute();
I have checked the myapi.api file and inside that it shows the parameters as "required" : false so that mean i am received the correct api on to client side. But not sure whats going wrong.
I am testing on localhost.
Use Boolean, not boolean for parameters marked Nullable. There should probably be a warning for using it with primitives, which of course, can't be null.

Resources