400 bad data error using API V8 PATCH

I am running version 7.11.15 and I am able to query via the v8 JSON API but when I try to update I get a 400 error. I thought it had something to do with the spacing or line breaks but I removed them all and that didn’t help.

Thanks!

I am using request type “PATCH”
URL: https://XXX.XXX.XX.XX/SuiteCRM/Api/V8/module

 {
    "data": {
    "type": "Accounts",
      "id": "7121ba98-d43e-3f77-2d28-5f688dfcb6f4",
      "attributes": {
        "name": "test account B"
        }
      }
    }

result is:
400
Bad Request

{
    "errors": {
        "status": 400,
        "title": null,
        "detail": "The option \"{\n\"data\":_{\"type\":_\"Accounts\",\"id\":_\"7121ba98-d43e-3f77-2d28-5f688dfcb6f4\",\"attributes\":_{\"name\":_\"test_account_B\"}}\n}\" does not exist. Defined options are: \"data\"."
    }
}

?††???›?††††???›???†††???=›???††††???›???4???›???†??

Hey,

hmm, If I copy your request as is:

 {
    "data": {
    "type": "Accounts",
      "id": "7121ba98-d43e-3f77-2d28-5f688dfcb6f4",
      "attributes": {
        "name": "test account B"
        }
      }
    }

Then it seems to submit as expected, with no issues
(I’m currently using Postman, are you using a different REST client / curl?)


You mentioned that you are able to query the V8 API,
So I assume that you are able to do both GET and POST requests without issue?


I believe the POST request uses pretty much the same data format for the body

(The Postman collection supplied with SuiteCRM has the following as the POST body):

{
  "data": {
    "type": "Accounts",
    "id": "{ID}",
    "attributes": {
      "name": "Test"
    }
  }
}

What happens if you use the POST content in the PATCH request?
(Ensuring you submit with an ID)

The error you’ve supplied looks like it might be some sort of formatting error in the request, so it would be interesting to see what happens

This was resolved when I changed the Content-type header to application/json. I had been trying to use application/x-www-form-urlencode because that was the only way I could get the authentication to work.

1 Like

Hi john,

do you have an example of a working curl patch function? i am able to run GEt request and pull info, but am not understanding the patch usage and arrays with curl.

Hey @rasel

I’ve had a look, and managed to have some success with using the snippet of Code posted by another user, here:
https://community.suitecrm.com/t/lead-generation-from-custom-contact-form/25434/6

You should be able to modify the “module_name” and various fields used, to update as you wish
As it is a PATCH request you’d like to do, you will need to include the “id” of the record you would like to update like so:
image
(This will update the contact record in my CRM with ID: 4855d4e4-576d-ba81-b192-600af0d71a0b, to set its name to “John UpdateMe”, feel free to change this)

Let me know if you have any trouble.
I’m not particularly experienced with cURL, but i’ll have a look!