I am trying to attach a contact to campaign response.
I am using rest API for that.
https://learn.microsoft.com/en-us/dynamics365/customer-engagement/web-api/campaignresponse?view=dynamics-ce-odata-9
Post Data :
{
"firstname": "TestFirst",
"lastname": "TestLast",
"emailaddress": "test#test.com",
"telephone": "1234567890",
"prioritycode": 0,
"responsecode": 1,
"subject": "Test Subject",
"statuscode": 1,
"regardingobjectid_campaign#odata.bind": "/campaigns(xxxx90c-11ef-e811-a966-000d3ad24a0d)",
"regardingobjectid_contact#odata.bind": "/contacts(xxxxfa2e-c3b5-e811-a962-000d3ad24a0d)"
}
Here is my JSON.
I am getting Error : “Campaign as RegardingObject must be supplied”. Without contact, it works fine.
I had the same problem and the documentation is not very clear about it, I had to check all the relationships of the CampaignResponse in order to understand how to solve this.
If you want to create a CampaignResponse linked to both a Campaign and a Contact you need to do the following:
Create a CampaignResponse with the "regardingobjectid_campaign#odata.bind" in the params sent.
POST "https://some_subdomain.crm6.dynamics.com/api/data/v9.0/campaignresponses"
{
"regardingobjectid_campaign#odata.bind": "/campaigns(CAMPAIGN_ID_HERE)",
"description": "some desc",
"subject": "some subject "
}
Then find the CampaignResponse you just created to get its activityid (every CampaignResponse is an Activity)
Finally, you need to create a new ActivityParty, that will link the Contact to the CampaignResponse.
POST "https://some_subdomain.crm6.dynamics.com/api/data/v9.0/campaignresponses(CAMPAIGN_ID_HERE)/activitypointer_activity_parties"
{
"partyid_contact#odata.bind": "/contacts(CONTACT_ID_HERE)",
"participationtypemask": 11 //this is the code for customers
}
The "Regarding" lookup field can only be set to a single "regarding" record. Even though it appears that there are different Regarding fields, one for each entity type, those are "helper" fields that let you easily set the main Regarding field by setting one of those regardingobjectid_xxx fields.
You must choose to use either a campaign or a contact as your Regarding field. You can of course create other lookups, so you could use the Regarding field for your campaign and then add an additional Contact lookup field, for example.
Related
So I created a person and also created an Organization and i want to send a PUT request to update a few fields of that Person (+ Organization they belong to).
So if my payload looks like:
{
"name": "Lorem Ipsum"
}
The persons name will be updated, all’s well.
But if I add the field ID for Organizations (org_id) as per the api docs on PUT requests, either nothing happens or i get an error.
If i add to the payload org_id as so, the name will be updated but not the organization.
{
"name": "Lorem Ipsum",
"org_id": 1, // <integer> of the Organizations ID
}
And if i format my payload just to include the org_id as so:
{
"org_id": 1
}
I get the following error:
“{"success":false,"error":"Bad request","error_info":"Please check developers.pipedrive.com for more information about Pipedrive API.","data":null,"additional_data":null}”
I’m stuck.
Can anyone help?
I'm writing a controller that handles an array of object, something like:
#PostMapping("/post")
public void saveEmployeeArray(#RequestBody Emoloyee[] employeeArray)
{
// Method body
}
Keep in mind that, in this case, employees are usually created, update, or deleted in bulk, meaning, I usually need to handle multiple employees at the same time.
A colleague told me that although it works I should only handle one employee in the controller as, according to him, it's rest best practice. But he didn't present an alternative to the issue of having to handle multiple employees most of the time, other than making multiple requests.
My question is, how is the best way to handle multiple objects?
If your list of Employee is inside another data structure (e.g. company), you can offer PATCH operation for outer resource to add or change a list of Employees. JSON PATCH is specified in RFC 6902, see https://datatracker.ietf.org/doc/html/rfc6902/
The JSON body of a PATCH request would look like this:
[
{ "op": "add", "path": "/employees", "value": { "name": "Employee 1", ...} },
{ "op": "add", "path": "/employees", "value": { "name": "Employee 2", ...} },
...
]
The body is a list of PATCH operations to change the addressed data structure at several places within one request, so it fits to your requirement.
The specification in RFC 6902 offers more than just adding elements, you can also remove, replace, move, copy and test. Have a look in the RFC for good and simple examples.
I've got a problem obtaining gender information from People API.
I'm making a request to https://people.googleapis.com/v1/people/account_id which is not returning gender field. If I add genders to personFields it is giving me Requested entity was not found error.
It looks like obtaining this information is forbidden. Is there any chance to get this field?
There are two ways to use the Google People api.
The first assumes that you have used Oauth2 to authenticate your user.
GET https://people.googleapis.com/v1/people/me
returns the info about the current authenticated user.
The second is a public call to the api. you can use an API key or Oauth2.
GET https://people.googleapis.com/v1/people/117200475532672775346
This will return the info about a specific user {117200475532672775346} but it will depend upon what that user has set to public. The above number is my personal g+ account, the following is the gender response.
"genders": [
{
"metadata": {
"primary": true,
"source": {
"type": "PROFILE",
"id": "117200475532672775346"
}
},
"value": "female",
"formattedValue": "Female"
}
I have no idea where you are getting your account id this is a users google id. The information must be filled out on Google plus i suggest you check the users google+ account to see what they have set to public https://plus.google.com/u/0/117200475532672775346. Note: It doesn't matter if this is the current authenticated user if they dont have the info set public you cant see it in your application.
Tip: assuming you only want to see genders you can use the fields parameter to request just that
?fields=genders
I am quite new to Dynamics CRM. I am building an app which should update entity in Dynamics CRM. I can update simple types without any issues. Now the situation is, I have declared some custom Option Sets in Contact entity.
Is there any way to retrieve all the possible OptionSet values (text and value) so that my app can look for appropriate value and set it in the payload it is generating?
I can not find any endpoint in WebAPI as well as XRMServices/2011/OrganizationData.svc. Any help would be really awesome.
You can use either the Web API or Organisation Service to retrieve The metadata and data models in Microsoft Dynamics CRM. Check out the sub articles of that one for specific examples and details.
Web API example Querying EntityMetadata attributes.
The following query will return only the PicklistAttributeMetadata
attributes and will include the LogicalName as well as expanding the
OptionSet and GlobalOptionSet collection-valued navigation properties.
GET [Organization URI]/api/data/v8.1/EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet,GlobalOptionSet
Another option would be to get the data via the StringMap entity:
[Organization URI]/api/data/v9.1/stringmaps?fetchXml=<fetch><entity name='stringmap'><filter><condition attribute='objecttypecodename' operator='in'><value>account</value><value>opportunity</value></condition></filter></entity></fetch>
Will provide data that looks like this:
{
"#odata.etag": "W/\"406742363\"",
"value": "Open",
"attributename": "statecode",
"langid": 1033,
"objecttypecode": "opportunity",
"attributevalue": 0,
"stringmapid": "0fe09734-3914-e711-80ef-e0071b6a7121",
"organizationid": "f95718b2-5c63-46df-adc3-c3b546cf686a",
"displayorder": 1
},
{
"#odata.etag": "W/\"406742364\"",
"value": "Won",
"attributename": "statecode",
"langid": 1033,
"objecttypecode": "opportunity",
"attributevalue": 1,
"stringmapid": "10e09734-3914-e711-80ef-e0071b6a7121",
"organizationid": "f95718b2-5c63-46df-adc3-c3b546cf686a",
"displayorder": 2
},
Simpler query:
[Organization URI]/api/data/v9.1/stringmaps?$filter=objecttypecode eq 'account' or objecttypecode eq 'opportunity'
If your options are global, this is the easiest way to get all options:
/api/data/v9.1/GlobalOptionSetDefinitions(Name='new_category')
Use below code to get specific option set for specific entity:
(replace EntityLogicalName and AttributeLogicalName with your input params)
GET [Organization URI]/api/data/v9.1/EntityDefinitions(LogicalName='EntityLogicalName')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet($select=Options),GlobalOptionSet($select=Options)&$filter=LogicalName eq 'AttributeLogicalName'
First, you need the attribute name and type, which you can find here:
/api/data/v9.1/EntityDefinitions(LogicalName='myEntity')?$select=LogicalName&$expand=Attributes($select=LogicalName)
Replace myEntity above with your entity name. The resulting page lists all the attributes that make up your entity. Locate the desired option set attribute and note its logical name and type.
Armed with that information, go here:
/api/data/v9.1/EntityDefinitions(LogicalName='myEntity')/Attributes(LogicalName='myAttribute')/Microsoft.Dynamics.CRM.MultiSelectPicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet($select=Options),GlobalOptionSet($select=Options)
Replace myEntity and myAttribute with your entity name and attribute name, respectively. If your attribute type is not MultiSelectPicklistAttributeMetadata, replace that with the correct type that was found on the previous page. This returns a list of all the possible values for the option set (both text and numeric values).
I am working on an application that has messages and I want to store all the messages. But my problem is the message has a from first name and last name which could change. So if for example my JSON was
{
"subject": "Hello!",
"message": "Hello there",
"from": {
"user_id": 1,
"firstname": "George",
"lastname": "Lastgeorge"
}
}
The user could potentially change their last name or even first name. Which would require basically looping over every record in elasticsearch and updating everyone with the user_id.
Is there a better way to go about doing this?
I feel you should use parent mapping.
Keep the user info as parent with userID as key.
/index/userinfo/userID
{
"name" : "George",
"last" : "Lastgeorge"
}
Next , you need to maintain each chat as a child document and map the parent to the userindo type.
This way , whenever you want to make some change to the user information , simply make the change in userInfo type.
With this feature intact , you can search your logs based on user information , or search users based on chat records.
Link - http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/parent-child.html