OroCRM Forums

Covering OroCRM topics, including community updates and company announcements.

Forums Forums OroCRM REST API POST command not working

This topic contains 2 replies, has 3 voices, and was last updated by  igalayev 5 years, 10 months ago.

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #30891

    gp arm
    Participant

    Hello Guys,

    I am trying to use built in OroCRM REST API, but it seems not to be working.

    1.) For example, when trying to create new user I always get validation errors no matter what input data is provided. Please see example below.

    Response:

    Notice that same fields are marked as required when using HTTP FORM System/ User Management/ Users/ Create user

    2.) I also tried to create new contact (via REST API) but there I got different error (no matter what input data I provide)

    3.) I am using OroCRM 3.0.0 beta.
    Can you tell me what I am missing? It’s working for GET methods, but not for POST commands.

    4.) I also noticed there is a lot of DEPRECATED methods labeled as “Deprecated since v1.8. Will be removed in v2.0.”.
    Apparently that never happened. Any reason for that? Is REST API not maintained properly?

    Thank you and best regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #30892

    Martin
    Participant

    Hi,

    i’ve not looked at 3.0Beta so far, but for the current stable api try the following:

    I guess the api just don’t recognizes your data structure so try setting your post body the same way the api responds to your GET Request. This includes the “data” key as well as the “type” key. Also your primary data like username and email should be under attributes.:

    Also notice how relational data is encapsuled with “data” and “type” key.

    You can test the api within the docs:

    http://yourhost/api/doc/rest_json_api#get–api-users-{id}

    Regards

    #30893

    igalayev
    Participant

    Hi, gp arm.
    Please note that you’re using old version of API.
    It’s recommended to transit to a new version of API as for an old one only bugfixes applied.

    The new version accepts data in format described by Martin.

    To use POST method in old version you need to set header first Content-type: application/json.
    In the API sandbox there’s a special input for this.

    Secondly you need to pass data in a valid format (here’s the minimum data needed to create the user):

    Thirdly you have malformed json as there’s no comma after “plainPassword” : “secretpassword” field. Also there are some extra fields (e.g. lastLogin) in your request. Please note that you have to provide ids for related entities such as owner (i.e. “owner”: 1). I hope this will help you to get 201 response.

    Regarding deprecated methods they should be removed in 3.0 version. They have appeared as a consequence of upgrading fosrestbundle to 1.7.1 version where api resources naming conventions were changed.

Viewing 2 replies - 1 through 2 (of 2 total)

The forum ‘OroCRM’ is closed to new topics and replies.

Back to top