Jump to content
  • 0

Edit service endpoint error: Failed to parse date time string


Question

Posted (edited)

Hello,

I'm working on the services/edit endpoint, in an attempt to add a configurable option to a clients' existing service. I am defining all of the following parameters as follows:

    parent_service_id = PSID
    package_group_id = PGID
    pricing_id = PricingID
    client_id = ClientID
    module_row_id = 1
    coupon_id = null
    qty = 1
    status = pending
    date_added = "2019-11-02 17:14:08"
    date_renews = "2019-12-02 18:14:08"
    date_last_renewed = null
    date_suspended = null
    date_canceled = null
    use_module = true
    configoptions = [currentConfigOptions, newConfigOption] 



I am using the services/get endpoint to retrieve the service by ID and then plugging those values directly into the edit endpoint, except for adding a single configurable option (which is my intended change).

When sending the request, I get the following error:

{
    "message": "An unexpected error occured.",
    "response": "DateTime::__construct(): Failed to parse time string (null) at position 0 (n): The timezone could not be found in the database"
}

 

I've taken the following steps to troubleshoot this:

  • ensured the timezone is set in Blesta
  • tried URL encoding the DateTime string that comes out of the get endpoint
    • 2019-11-02%2017%3A14%3A08
  • passed DateTime string in quotes
    • "2019-11-02%2017%3A14%3A08"
  • passed null in DateTime
    • null

Any suggestions?

Thanks!

Edited by codym
added examples of date value

6 answers to this question

Recommended Posts

  • 0
Posted

An example of your data might be helpful.

I'm not sure what type the "DateTime string" represents exactly, but the error indicates one of the dates is being passed to DateTime as null.

Dates should be passed as strings representing the date in the company's timezone (unless timezone info is provided), in a php-parseable format by the date() function, e.g. "Y-m-d H:i:s" in local time or "Y-m-d H:i:sZ" in UTC or "Y-m-dTH:i:s+00:00" UTC, etc. For instance, date('c') would be a valid date format.

  • 0
Posted

Thanks for your reply Tyson. I edited my above question to include examples of the DateTime value I am passing.
In regards to:

Quote

the error indicates one of the dates is being passed to DateTime as null

I am passing the date_added and date_renews as dates, and the other three date options as null. Surely those must not be defined as those actions have not happened on this service, which was newly created.

Additionally, the services/get endpoint returns those three values as null so I don't believe those three are the issue.

  • 0
Posted

This isn't something I have been able to duplicate, so we may need more info. Do you have any errors in your Blesta logs about this? Perhaps that refer to a stack trace or file/line number where the issue originated?

What is the data set you are passing to Services::edit? (i.e. a var_dump)

  • 0
Posted

The data set I am passing is as follows:

image.png.1b49f343350a80ba6918310938242ffd.png

I have one error that exists in my directory, but I don't think it has anything to do with this issue as it is from days before:

image.thumb.png.28f39301e0c3184f8fc649faf0201074.png

  • 0
Posted

I actually just got it to work. Even though all of the vars[] are shown to be required in the docs, if it has a null value it is not to be sent in the request. Specifically, vars[date_last_renewed], vars[date_suspended], and vars[date_canceled] were all fields throwing the error I reported by passing null to them. Additionally, vars[coupon_id] and vars[parent_service_id] were also throwing errors due to null values after I fixed the others. The documentation should be updated to show which vars are actually optional and which are not.

Lastly, the raw string is the correct format to be passed as a parameter. No quotes and no URI encoding.

  • 0
Posted

Can you post the raw data sent in the request? null is acceptable for dates like the date_canceled, which would remove any cancellation date set on the service. This works for me via the UI and via the API. Are you using the API SDK?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...