Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 55831

Trying to use the API to submit a post to an account

$
0
0

Hi,

I'm new at using the API, but I have been able to read data from the API and also post a Task via the API!

However now I want to submit a Post to a specific account via the API! But I get an Error: error BAD request!

Any ides why this is!

This is the code I use:

var entity = {};
entity["regardingobjectid_account@odata.bind"] = "/accounts(22FAECC2-43C8-E611-8102-C4346BAC4B68)";
entity.source = 3;
entity.text = "API Post Test";
entity.type = 3;

$.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    url: Xrm.Page.context.getClientUrl() + "/api/data/v8.2/posts",
    data: JSON.stringify(entity),
    beforeSend: function(XMLHttpRequest) {
        XMLHttpRequest.setRequestHeader("OData-MaxVersion", "4.0");
        XMLHttpRequest.setRequestHeader("OData-Version", "4.0");
        XMLHttpRequest.setRequestHeader("Accept", "application/json");
    },
    async: true,
    success: function(data, textStatus, xhr) {
        var uri = xhr.getResponseHeader("OData-EntityId");
        var regExp = /\(([^)]+)\)/;
        var matches = regExp.exec(uri);
        var newEntityId = matches[1];
    },
    error: function(xhr, textStatus, errorThrown) {
        Xrm.Utility.alertDialog(textStatus + " " + errorThrown);
    }
});

I'm a bit unsure on what the put on the source and type entity??

thanks for any help

//Martin


Viewing all articles
Browse latest Browse all 55831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>