0

What I do

I'm really confused about the following.

  • I'm logged in via Exact Online oAuth2 (works)
  • I'm redirected to the set redirect url (works)
  • Now, I'm doing a POST request for creating an CRM Account to

https://start.exactonline.com/api/v1/1645882/crm/Accounts

with headers:

  • Authorization: Bearer MY_TOKEN
  • Content-Type: application/json

with json data:

{
    "Name": "James Fellows",
    "Code": "JF"
}

Code (simplified)

$this->client->request('POST', 'https://start.exactonline.com/api/v1/1645882/crm/Accounts', ['headers' => ['Authorization' => 'Bearer MY_TOKEN']], ['json' => json_encode(['Name' => 'James Fellows', 'Code' => 'JF'])]);

Problem

And now the problem. I always get this error:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">\r\n
    <code></code>
    <message xml:lang="">Error processing request stream. JSON text specified is not valid.
</message>
</error>

Documentation

I used the following api documentation:

schellingerht
  • 5,726
  • 2
  • 28
  • 56

2 Answers2

1

Just don't use json_encode() for your data if you use json option. This option accepts an array and automatically encodes it internally.

Alexey Shokov
  • 4,775
  • 1
  • 21
  • 22
-1

You should omit the ID field. That field will be auto-filled.

There are also some problems with the formatting of your JSON (quotes to be specific). This one should do:

{ Code : 'JF'
, Name : 'Jeff Fellows'
}
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325