Jump to content
  • 0

Edit service endpoint error: Failed to parse date time string


codym

Question

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
Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

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.

Link to comment
Share on other sites

  • 0

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.

Link to comment
Share on other sites

  • 0

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.

Link to comment
Share on other sites

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...