hacf-fr / renault-api

https://readthedocs.org/projects/renault-api/
MIT License
109 stars 38 forks source link

/actions/charging-start -> {"code":"err.func.wired.invalid-body-format","message":"Body has at least one wrongly formatted value"} #1247

Open fin2red opened 4 months ago

fin2red commented 4 months ago

Hello,

I've been trying a number of ways to call /actions/charging-start (the first action that I'm trying to call), but I'm always getting an error. The GET requests work well.

I'm not sure if I'm missing some header, or missing something in the payload, but here's a minimal example:

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-type: application/vnd.api+json',
    'x-gigya-id_token: '.$CONFIG['gigyaJWT'],
    'apikey: '.$CONFIG['kamereon_key']
]);

curl_setopt($ch, CURLOPT_URL, sprintf(
    "https://api-wired-prod-1-euw1.wrd-aws.com/commerce/v1/accounts/%s/kamereon/kca/car-adapter/v1/cars/%s/actions/charging-start?country=PT",
    $CONFIG['accountId'],
    $CONFIG['vin']
));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"data":{"type": "ChargingStart","attributes":{"action":"stop"}}}');
$json_raw = curl_exec($ch);

I also tried application/json as the Content-type, and removing/adding spaces in the JSON, also different cURL options, etc...

But I always get:

{"type":"FUNCTIONAL","messages":[{"code":"err.func.wired.invalid-body-format","message":"Body has at least one wrongly formatted value"}],"errors":[{"errorCode":"err.func.wired.invalid-body-format","errorMessage":"Body has at least one wrongly formatted value"}],"error_reference":"FUNCTIONAL"}

Any idea why?

It seems consistent as per the documentation: https://renault-api.readthedocs.io/en/stable/endpoints.html#actions-charging-start

And as per the payload in this comment: https://github.com/hacf-fr/renault-api/issues/763#issuecomment-1372388595

So, I'm not sure what I'm doing wrong! Thank you!

jumpjack commented 4 months ago

Forget charging-start, you must use "actions/charge-mode" with this payloads:

Start charging:

{
    "data": {
        "type": "ChargeMode",
        "attributes": {
            "action": "always_charging"
        }
    }
}

Stop charging:

{
    "data": {
        "type": "ChargeMode",
        "attributes": {
            "action": "schedule_mode"
        }
    }
}

And you will need at least one charging schedule already active.

fin2red commented 4 months ago

Thank you very much!!

Does that mean that if I want to start charging (by plugging), I need to call "always_charging" first, or otherwise it won't start charging, because it's on "schedule_mode" since the last time I requested to stop charge?

jumpjack commented 4 months ago

Good question. I didn't verify that, I always stopped by hand directly on the car, but I think you are right: if you use this method, you'll have to switch back to "always" once you disconnect.

But the real problem is that your command is not accepted at all, while usually it is accepted but not executed because improperly formatted.

I just noticed that I am receiving same error on my test page (warning: use it at your own risk, use a temporary password!): "start" is accepted, "stop" is not, hence something changed in the api: or "stop" has been changed to something else, or there is a new endpoint like "charging-stop"; I tried some new random names, but no luck.

jumpjack commented 4 months ago

My new discoveries:

{ "data": { "type": "ChargingStart", "attributes": { "action": PARAMETER } } }

PARAMETER value --> server response: 0 -->

{
    "data": {
        "type": "ChargingStart",
        "id": "ea11e720-b9f2-47bf-bcf3-3031bb364bb5",
        "attributes": {
            "action": "start"
        }
    }
}

1 --> Action must be 'start' but was 'pause' 2 --> Action must be 'start' but was 'resume' 3 --> Body has at least one wrongly formatted value

fin2red commented 4 months ago

Thank you for your responses!

But sorry - I'm not sure I understand your last discovery.

Are you saying that we can call "ChargingStart", but instead of "start" or "stop", we can put "0", "1", "2", etc... ?

So I guess "0" or "start" works for starting, but you couldn't find one that works for stopping.

Thank you again.

jumpjack commented 4 months ago

As far as I can understand, you can use "raw values" 0, 1 or 2, or the equivalent strings "start", "pause" and "resume", but "start" is only for /actions/charging-start endpoint, I am trying to figure out which is the right one for pause and resume. Instead, apparently "stop" is not an allowed option.

jumpjack commented 4 months ago

Ok here it is (but no tested yet):

/commerce/v1/accounts/ACCOUNT/kamereon/kcm/v1/vehicles/VIN/charge/pause-resume

payload: {"data":{"type": "ChargePauseResume","attributes": { "action": "pause" } }}