Updating asyncoperation fields in Dynamics 365 - dynamics-crm

I am trying to update AsyncOperation fields using REST API in Dynamics 365 CRM. But there is a problem.
If I try to update any field by request, for example
PATCH /api/data/v9.0/asyncoperations(GUID) HTTP/1.1
Content-Type: application/json
OData-MaxVersion: 4.0
OData-Version: 4.0
If-Match: *
{
"name":"new async operation name"
}
In response I receive this error message (with different codes for different GUIDs obviously):
The state transition requested is not valid for the current state.
Current state: 3, current status: 32, target state: 3.
Even if I did not make any changes to statecode and statuscode fields.
I can not update field even if update only 1 field in a time by
PUT /api/data/v9.0/asyncoperations(GUID)/name
with same response.
Updating other fields with "#odata.bind" does not work too.
What am I doing wrong? Maybe there is any header I miss or something. And is it even possible to update information for AsyncOperation entities?

you cannot update asyncoperations Entity for field Name.
This operation is not supported on asyncoperations Entity.

Related

Error Merging fields from Dynamics CRM workflow

I am trying to merge fields using Docusign for Dynamics. I have signed up for Sandbox Docusign and using with dynamics 365 CRM.
When I try to write a workflow to merge field using template , I receive following error. In docusign Template is perfect . Any help appreciated.
[DocuSignIntegration: DocuSign.DSIntegrationActivity.GetSignatures]
[DocuSignIntegration: DocuSign.DSIntegrationActivity.GetSignatures]
Calling endpoint https://partner.docusign.net/partners/msdynamics/api/GetSignatures
POST data: t=L%2BUL0dVaJKrxG7jPjGXtUacp4FfMOWprKbw6ML9qcvvUX76oVsfPu3hJ0sk3wbfc7SK6nQXcw44eGuum1P%2Fea2wlZxitPj%2Bas%2B52vVlmOq4%3D&baseUrl=https%3A%2F%2Fdemo.docusign.net&accountId=6b76af6b-6663-4b1b-aea4-6fedb0b159bf&uid=c20189f4-73d3-4298-8065-36e04a089458&refreshToken=AQABAAAAAAAm-06blBE1TpVMil8KPQ41Qy0jKUb0TMSdpFJKrCmxKKQWM9NCQTqtV3LKgZLnb47f-NnmSMgL2ssfXvlpw_9jcKLy7n_c-AmQhLjKXynoUgkUYt3-5ZeMaggxr7yT7Td1CeBVYQ4mV68t8TT-Eb5kbwcglNW-u5UuStp1KEKrVrePjq__n3PnTq9tMCBoUxCiIobg4Xj-aSSNeoH9UappzpFqhHjs8a1tv7JyJaDxJfEED8R2i_bXb6D54gPqDiZDhKBfiIBg29JgwReIIZeqWQytBnuQ-Mlitlmvw5LSHVgHA6CS6OFpvT36cIpjgejbakshREilAMbSt8U2kpOZ1MV9O89H7qkSJs_XGh02uPHptjiGPcdAkaKIL39HPNoTLz24EKXFmPB9i8X596LKBu7pil6D4QfL5nPSnoFWVDCvQE7Ot0wm9O6xM1ku6r9z2pd5XrcRLYwDZZ-tQQkxdwxIimh74ipC-eeslVJN1APC2WlC1rXROD4Z3TBBS3pMZcTS8VeCgQMn4TwF9FerJjSr-rS1yBJcftPGcbqqL9Hn9NDYJmc8Id0fV_d4H9kq86SBKq11XlXeZ0r8iSTHhTV2vtheNSV1QOvFPC_PWnk7u_rXjNu2ZCipgHVaLEgU3jfnXVUHnt0Qg7wwNqxPB8fVoR4DGxiwDx-myVdhUjVKfWMzUjwNt8vy3aqh9n7dsAnHszm8x_stv2p4MP1R9YPyqW4x3NsBnHASa6iST7ejSx155voSCWjNIIi4XnSUtrRHAydlZLhVZSM4ElwWqTYkf5gHNtArAyFlIv1wlQUWf_-rrAb2Hth4r64x1g4Cvjw4VYqpcamX-LGHklwYIAA&crmHost=s34.crm.dynamics.com&v=6.2.0.13&envelopeId=25a4f2db-c8af-483b-80b8-b9caf4ca0ff7&entityLogicalName=opportunity&entityId=628cf01a-aed1-e411-80ef-c4346bac7be8&oneclicksend=True&oneclickoption=Tag&templateId=019b6c8a-3faa-4a65-a256-97382dfa1554
Deserializing json response: {"Error":"Unknown","ErrorDescription":"The Envelope is not Complete. A Complete Envelope Requires Documents, Recipients, Tabs, and a Subject Line. Error querying documents for Envelope ID = 25a4f2db-c8af-483b-80b8-b9caf4ca0ff7 (ENVELOPE_IS_INCOMPLETE)"}
Error Message:
Unhandled exception:
Exception type: Microsoft.Crm.CrmException
Message: An unexpected error occurred from ISV code. (ErrorType = ClientError) Unexpected exception from plug-in (Execute): DocuSign.DSIntegrationActivity.GetSignatures: System.Exception: Unable to deserialize the returned JSON.
Endpoint: GetSignatures.
Params: t=L%2BUL0dVaJKrxG7jPjGXtUacp4FfMOWprKbw6ML9qcvvUX76oVsfPu3hJ0sk3wbfc7SK6nQXcw44eGuum1P%2Fea2wlZxitPj%2Bas%2B52vVlmOq4%3D&baseUrl=https%3A%2F%2Fdemo.docusign.net&accountId=6b76af6b-6663-4b1b-aea4-6fedb0b159bf&uid=c20189f4-73d3-4298-8065-36e04a089458&refreshToken=AQABAAAAAAAm-06blBE1TpVMil8KPQ41Qy0jKUb0TMSdpFJKrCmxKKQWM9NCQTqtV3LKgZLnb47f-NnmSMgL2ssfXvlpw_9jcKLy7n_c-AmQhLjKXynoUgkUYt3-5ZeMaggxr7yT7Td1CeBVYQ4mV68t8TT-Eb5kbwcglNW-u5UuStp1KEKrVrePjq__n3PnTq9tMCBoUxCiIobg4Xj-aSSNeoH9UappzpFqhHjs8a1tv7JyJaDxJfEED8R2i_bXb6D54gPqDiZDhKBfiIBg29JgwReIIZeqWQytBnuQ-Mlitlmvw5LSHVgHA6CS6OFpvT36cIpjgejbakshREilAMbSt8U2kpOZ1MV9O89H7qkSJs_XGh02uPHptjiGPcdAkaKIL39HPNoTLz24EKXFmPB9i8X596LKBu7pil6D4QfL5nPSnoFWVDCvQE7Ot0wm9O6xM1ku6r9z2pd5XrcRLYwDZZ-tQQkxdwxIimh74ipC-eeslVJN1APC2WlC1rXROD4Z3TBBS3pMZcTS8VeCgQMn4TwF9FerJjSr-rS1yBJcftPGcbqqL9Hn9NDYJmc8Id0fV_d4H9kq86SBKq11XlXeZ0r8iSTHhTV2vtheNSV1QOvFPC_PWnk7u_rXjNu2ZCipgHVaLEgU3jfnXVUHnt0Qg7wwNqxPB8fVoR4DGxiwDx-myVdhUjVKfWMzUjwNt8vy3aqh9n7dsAnHszm8x_stv2p4MP1R9YPyqW4x3NsBnHASa6iST7ejSx155voSCWjNIIi4XnSUtrRHAydlZLhVZSM4ElwWqTYkf5gHNtArAyFlIv1wlQUWf_-rrAb2Hth4r64x1g4Cvjw4VYqpcamX-LGHklwYIAA&crmHost=s34.crm.dynamics.com&v=6.2.0.13&envelopeId=25a4f2db-c8af-483b-80b8-b9caf4ca0ff7&entityLogicalName=opportunity&entityId=628cf01a-aed1-e411-80ef-c4346bac7be8&oneclicksend=True&oneclickoption=Tag&templateId=019b6c8a-3faa-4a65-a256-97382dfa1554
Error Description: The Envelope is not Complete. A Complete Envelope Requires Documents, Recipients, Tabs, and a Subject Line. Error querying documents for Envelope ID = 25a4f2db-c8af-483b-80b8-b9caf4ca0ff7 (ENVELOPE_IS_INCOMPLETE) (Unknown)
Server Response: {"Error":"Unknown","ErrorDescription":"The Envelope is not Complete. A Complete Envelope Requires Documents, Recipients, Tabs, and a Subject Line. Error querying documents for Envelope ID = 25a4f2db-c8af-483b-80b8-b9caf4ca0ff7 (ENVELOPE_IS_INCOMPLETE)"}
at Microsoft.Crm.Sandbox.SandboxCodeUnit.ProcessException(Exception originalException, IExecutionContext context, SandboxClient client, SandboxCallTracker callTracker, Boolean isSafeToRetry, DateTime performanceExecutionStartTime, SandboxTracker tracker, Guid parentExecutionId, CrmException& crmException, String& assemblyContents)
at Microsoft.Crm.Sandbox.SandboxCodeUnit.<>c__DisplayClass24_0.<Execute>b__0()
at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute(ILogger logger, EventId eventId, ActivityType activityType, Action action, IEnumerable`1 additionalCustomProperties)
at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute(ILogger logger, XrmTelemetryActivityType activityType, Action action)
at Microsoft.Xrm.RemotePlugin.CrmProvider.RemotePlugin.CDSExecute(IServiceProvider serviceProvider)
at Microsoft.Crm.Workflow.Services.ProxyCustomActivity.Execute(CodeActivityContext executionContext)
-- End stack trace --
usually this fails for these reasons:
1. No documents are attached, but if you used the template, then this doesn't applied
2. No recipients are provided. If you add a recipient, and the recipient role is incorrect (it's case sensitive), it will be added as a new recipient, but it might not be the required recipient the template specifies. Double check that you have the role name correct.
3. A good way to verify what is missing, is to copy the envelope ID created in the workflow, then open a new window and login to your docusign account. Look for the envelope using this ID, and you'll see it's in a draft state. You can spot check if it does have the required recipients.

Dynamics 365 - Get the value for selected option from Global Option Set

I'm trying to find a way to get a value for my field which is based on a GlobalOptionSet.
I'm managing to pull back data from my endpoint
https://TEST.test.dynamics.com/api/data/v9.1/projects which is returning my list of projects.
some of the fields on this dataset just show as GUID's which I've managed to expand into and get their values.
However, some of the fields returned are showing just numbers like 866110000 which I believe is an option in a GlobalOptionSet.
I know I can get the GlobalOptionSet definition and match up its value but I'm hoping to be able to get this information in a single query similar to the way I got other fields by expanding.
Does anyone know how to get it to return the selected Value for an option field instead of the ID of the option that was picked?
Thanks
All you have to do is include the below header to get the needed optionset & lookup display name values. Read more
Prefer: odata.include-annotations="OData.Community.Display.V1.FormattedValue"
Sample request:
GET [Organization URI]/api/data/v9.1/accounts?$select=name,donotpostalmail,accountratingcode,numberofemployees,revenue
&$top=1 HTTP/1.1
Accept: application/json
OData-MaxVersion: 4.0
OData-Version: 4.0
Prefer: odata.include-annotations="OData.Community.Display.V1.FormattedValue"
If its AJAX request using jQuery or XmlHttpRequest, for ex.
req.setRequestHeader("Prefer", "odata.include-annotations=OData.Community.Display.V1.FormattedValue");
Reference

How to support patch rest request with protobuf 3

We often have use cases where we only want to update a subset fields on a resource. So if we have a resource Person:
type Person struct {
Age int
Name string
Otherfield string
}
Say the calling client only wants to update the Age field. How would an endpoint be normally set up to handle this?
I believe this should be done with a PATCH request, with only the fields being set as part of the payload, ie:
{
Age: 21
}
However, this won't work with proto3 because as far as I know there are no null fields, only default values. This won't work in many cases where the default value is valid.
Looking at Google own protobuf files (e.g. here), they use FieldMask for partial update.
FieldMask object is passed along with the request, and has the form (in JSON):
{
mask: "Person.Age"
}
This allows the client to tell the server which fields they wish to update, without counting on the partial message itself to figure this out.
I think this adds unnecessary complexity on (each!) client, but we couldn't find any other way to achieve partial updates with proto3.
You can see full documentation of FieldMask here.
Note that it can also be used to filter out responses if the client doesn't need the entire object.

How to send graphql query by postman?

I use
POST type
URL http://######/graphql
Body:
query: "query: "{'noteTypes': {'name', 'label', 'labelColor', 'groupName', 'groupLabel', 'imageUrl'}}"
But it return
"message": "Must provide query string."
There's a better way to do it using the REST client Insomnia
Docs are here, how to send graphql queries: https://support.insomnia.rest/article/61-graphql
Below are the steps for postman
Step 1.
Run the GraphiQL in Chrome, open the Chrome Dev Console, click the Network tab, and make the query from graphiql, when you make the query, network tab will show the graphql request...
Step 2.
From the graphql request copy the request query, Select the Copy as cURL (cmd)
Step 3.
Open Postman, In the Top-Left click on the Import button, after you click Import you have to click the Paste Raw Text, and paste the copied cURL request as done in step2 after it's done click the Import
Step 4.
Postman is ready to send the Graphql request, Just Click on the Send Button, you will see the Response in the Response Box in body as below
Step 5.
To see how the query is being sent click on the Body tab next to Headers, you will get know how to provide the fields from postman in JSON format.
e.g: edges {\n node {\n id\n jobId\n }\n, If you want to view another field then you need to add it in with the suffix \n
like if need name then : edges {\n node {\n id\n jobId\n name\n }\n
\n here just means to represent a new line. Instead, you can make it simpler by providing a clear and illustrative JSON like below
===========================================================================
Note: The body type must be raw with application/json content-type. So, the query must be a valid JSON with quotes ".."
{
"query":"{viewer {user {edges {node {id jobId name }}}}}"
}
===========================================================================
you can directly start from step 5 if you know how to send the query in body and other things too that needs to be required while making a request from postman
With simplified JSON
You don't need INSOMNIA in case the GraphQL server responds to Content-type: application/graphql or postman.setEnvironmentVariable,
Just do it:
In Headers tab:
Content-Type: application/graphql
In Body tab, "raw" selected, put your query
Adding this for anyone searching on the topic ... you can utilize and test GraphQL calls far better and more easily with Insomnia:
https://insomnia.rest
It's been fantastic for GraphQL development.
There's a simple way to do it. Use a pre-request script to stringify the payload (source).
Step 1.
In the body of the request put a placeholder for the payload.
{
"query":{{query}}
}
Step 2.
Create the payload in the pre-request script and store it in an environment variable.
postman.setEnvironmentVariable("query", JSON.stringify(
`
{
search(query: "test", type: ISSUE, first: 10) {
issueCount
edges {
node {
... on Issue {
title
id
state
closed
repository {
name
}
}
}
}
}
}
`
));
That's it.
UPDATE 8-2019 - I know this is old, but regarding POSTMAN, if you haven't figured it out already, they do have a graphql (beta) option for posting body. There is no need to add any additional headers.
UPDATE 2:
It's not practical use POSTMAN, because the are working yet in a easy way to add headers, that take longtime, and i think POSTMAN is not made for work naturally with graphql,
you can follow the progress about that here:
https://github.com/postmanlabs/postman-app-support/issues/1669
I recommend to use another packages plugin like:
the best (like postman , but profile and sync price 5$ monthly):
https://insomnia.rest/
others:
https://github.com/andev-software/graphql-ide
https://github.com/imolorhe
for graphiql (no add headers possibility) you need to set three things (it's not easy to type):
Header:
Content-Type: application/json
Body:
Choose Ray < optiongroup
Choose JSON (application/json) < selectbox
Compose javascript object with "query" and the "value" of your graph query. Like all objects in js it'sneeded the propery and the value , in this case "quote" is the property, the value must be with double quotes. Inside the value (graphl string) you dont compose js objects, so you dont need use doble quotes, it's just a string.
{"query":"{ allQuotes { text } }" }
the problem is you need type all in a single line, no like grapIql... there is a post requirement in postman github so is easy work with graphql:
Postman just released inbuilt GraphQL support in version 7.2.
This version supports
Sending GraphQL queries in request body as POST requests
Support for GraphQL variables
Creating APIs in Postman with GraphQL schema type
Query autocompletion integrated with user defined GraphQL schemas
Please give it a try and give us your feedback on the tracking thread on our community forum
I faced the same problem when I try to used graphQl query using POSTMAN,
In POSTMAN send data from the raw tab with json type.
Query Command:
{"query":"{user(id:902){id,username,DOB}}"}
Mutations Command:
{ "query": "mutation {createMutations(reviewer:36, comments:\"hello\",data_id: 1659, approved: true ){id}}" }
#commnent: String Type
#data_id:Int Type
#approved:Boolean Type
If you're using Visual Studio, I have written a plugin to convert GraphQL to Restful body
https://marketplace.visualstudio.com/items?itemName=orasik.graphql-to-rest-queries
Postman has recently launched its out of box support for GraphQL: https://blog.getpostman.com/2019/06/18/postman-v7-2-supports-graphql/
Below is the screenshot of testing GraphQL locally:
Note: Running GraphQL locally using spring-boot https://www.baeldung.com/spring-graphql
Deriving from Estevão Lucas' answer.
You can also use header Content-type: application/json on postman
And define the body with:
{
"query": "{ your_query }"
}
This is easily constructed on the client side to form a request payload.
e.g.
Output:
Checkout https://github.com/hasura/graphqurl - curl for GraphQL:
CLI for making GraphQL queries with autocomplete
Run GraphiQL locally against any endpoint (with custom headers)
Use as a library with nodejs or from the browser
Supports subscriptions
I am one of the authors.
gq https://gentle-anchorage-72051.herokuapp.com/v1alpha1/graphql -i
IF we can pass header type, Then add the header Content-type: application/graphql
Below link can be used as reference:
link description here
By adding header we can run graphql query in the postman
Content-type: application/graphql

Creating Item, unprocessable entity

I'm trying to use the connect api to create new products. I keep getting the following error.
{ type: 'unprocessable_entity', message: 'Item[name]:name required, max length 255, min length 1; Item[variations]:Must have at least one variation' }
The object I'm passing does have an name and a variation.
{"variations":[{"price_money":{"currency_code":"USD","amount":500},"name":"Small","sku":"TST101"}],"name":"My Test","description":"This is a desc"}
I'm unsure of why this is failing, any help would be great.
I believe this error is occurring because your request does not include a Content-Type: application/json header. I attempted to create an item with the JSON body you list above, and the request succeeded. I then removed the Content-Type: application/json header from my request, and it failed with the same error you encountered.
This is clearly not a helpful error message, given the actual cause. I will work with the Connect API engineering team to improve it.

Resources