500 — Server Error

Hi Team,

We are using subscription feature with a webhook. We noticed an error 500 that after processing of webhook (refer attached snap). Hence we would like to know the structure/format of the response that needs to send by a webhook. We tried to find in API docs, but couldnt find anything specific to webhook response.

We have configured webhook url without any headers. Is there anything missing from our end?

Could you please help us to get rid of the error ?

Looking forward to your kind support and co-operation.

Thanks,
Amitkumar

@david do you have any thoughts?

Hi @Amit.Panchal

You’ve reached an undocumented section of the application, congratulations! :slight_smile:

The app is expecting an array of returned data, with a minimum of the following:

[
            "message" => "Success",
            "status_code" => 200]
]
1 Like

Hi David/Hillel,

Thanks for quick reply.
We’ll try this out and reach out to you in case of any difficulties.

Thanks,
Amitkumar

Hi David,

We tried to send below response.
[
“message”: “Success”,
“status_code”: 200
]

But ended up with an error 500. Could you please share the full details of the response required to send. Like sample payload, http status code, content type (xml or json) etc.

image

@Amit.Panchal

That is the response from your webhook endpoint, it is returning the 500 error, so you’ll need to inspect it.

In regards to payloads that the webhook sends to your service, there are a couple of variations depending on the context:

Recurring Purchase

'body' => [
'context' => 'recurring_purchase',
'recurring_invoice' => $recurring_invoice->hashed_id,
'invoice' => $invoice->hashed_id,
'client' => $recurring_invoice->client->hashed_id,
'subscription' => $this->subscription->hashed_id,
'contact' => auth('contact')->user()->hashed_id,
];

Single Purchase

'body' => [
'context' => 'single_purchase',
'invoice' => $invoice->hashed_id,
'client'  => $invoice->client->hashed_id,
'subscription' => $this->subscription->hashed_id,
];

Is Eligible endpoint (used to test whether the client to access the subscription

'body' => [
'context' => 'is_eligible',
'subscription' => $this->subscription->hashed_id,
'contact' => $contact->hashed_id,
'contact_email' => $contact->email,
'client' => $contact->client->hashed_id,
];

Trial Plans

'body' => [
'context' => 'trial',
'recurring_invoice' => $recurring_invoice->hashed_id,
'client' => $recurring_invoice->client->hashed_id,
'subscription' => $this->subscription->hashed_id,
'account_key' => $recurring_invoice->client->custom_value2,
];

Hi David,
Thanks for your reply.
FYI, its expecting a json (like below), not an array (it may be treated an array in your code).
{
“message”: “Success”,
“status_code”: 200
}

Anyway, we are able to proceed further. We noticed after sending response to request with [“context”: “is_eligible”], webhook triggered again and request contains [“context”: “plan_paid”]. So we would like to know all sequence of events which triggers a webhook.

For ex.
1st event : is_eligible
2nd event : plan_paid
3rd event : ??
4th event : ??

Last event : ??

Below is what we got after [“context”: “is_eligible”]:

{
  "body": {
    "context":"plan_paid",
    "subscription":"kQBexxxxxx",
    "recurring_invoice":null,
    "client":"Jxboxxxxxx",
    "contact":"olejxxxxxx",
    "invoice":"ZdPNxxxxxx",
    "account_key":null,
    "db":"db-ninja-01"
  }
}

Thanks in advance.

Hi David, Could you please reply us ?

Hi @david/@hillel

We are waiting for our query below (asked 5/6 days back).

We noticed after sending response to request with [“context”: “is_eligible”], webhook triggered again and request contains [“context”: “plan_paid”]. So we would like to know all sequence of events which triggers a webhook.

For ex.
1st event : is_eligible
2nd event : plan_paid
3rd event : ??
4th event : ??

Last event : ??

Thanks in advance.

Hi @hillel @david

I know you mentioned that we’ve hit an undocumented part of IN, so any extra input you can provide us would be great… We’re on the Enterprise plan, so please let @Amit.Panchal and myself know if you’d like us to email you…

Hi @Amit.Panchal

Sorry for the delay

The response we are looking for in the ‘is_eligible’ request is

a response property message with value Success

If this passes it indicates the system will be able to move onto the next step which is plan_paid.

The system doesn’t need any return response after the plan_paid, this is a notification to your system to advise that payment has been processed, Invoice Ninja will then either

  1. return the user to the client portal screen
  2. return the user to a redirect URL if any is present.
1 Like

Hi @david / @hillel ,

Happy new year. :slight_smile:
Hope you are doing great.

Back with the question. We are using /api/v1/clients/{id} to get the client information. We are getting country ids in the response. We will need country name for corresponding country id. We had a look on API document, but couldnt find any supporting api to get the details about country based on country id. Could you please suggest how can we get the country name ? Sample response is given below.

Looking forward to your early and positive reply.

Thanks,
Amitkumar Panchal

{
“data”: {
“id”: “LDdwBWW8b1”,
“user_id”: “LDdwEOza1Y”,
“assigned_user_id”: “WPe9wGDbLy”,
“name”: “Traniya”,
“website”: “”,
“private_notes”: “”,
“balance”: 0,
“group_settings_id”: “”,
“paid_to_date”: 0,
“credit_balance”: 0,
“last_login”: 0,
“size_id”: “”,
“public_notes”: “”,
“client_hash”: “r0M3TRDVLs7ygwV2azQSD51p6HAfJslTBcx6532D”,
“address1”: “MyStreet”,
“address2”: “MySuite”,
“phone”: “”,
“city”: “MyCity”,
“state”: “MyState”,
“postal_code”: “11001”,
"country_id": “840”,
“industry_id”: “”,
“custom_value1”: “”,
“custom_value2”: “”,
“custom_value3”: “”,
“custom_value4”: “”,
“shipping_address1”: “MyShippingStreet”,
“shipping_address2”: “MyShippingSuite”,
“shipping_city”: “MyShippingCity”,
“shipping_state”: “MyState”,
“shipping_postal_code”: “12001”,
"shipping_country_id": “840”,
“settings”: {
“currency_id”: “2”
},
“is_deleted”: false,
“vat_number”: “”,
“id_number”: “”,
“updated_at”: 1638098612,
“archived_at”: 0,
“created_at”: 1638076555,
“display_name”: “Traniya”,
“number”: “0021”,
“contacts”: [
{
“id”: “qaQWgkmldn”,
“first_name”: “Traniya”,
“last_name”: “Geli”,
“email”: “traniya84@jmortgageli.com1”,
“created_at”: 1638076555,
“updated_at”: 1638098612,
“archived_at”: 0,
“is_primary”: true,
“is_locked”: false,
“phone”: “1212121212”,
“custom_value1”: “”,
“custom_value2”: “”,
“custom_value3”: “”,
“custom_value4”: “”,
“contact_key”: “bO3OBmUESPEGrIO37TJeXq1ENFgBRZt1MqRV6lNv”,
“send_email”: true,
“last_login”: 0,
“password”: “”,
“link”: “https://fg-testing.invoicing.co/client/key_login/bO3OBmUESPEGrIO37TJeXq1ENFgBRZt1MqRV6lNv
}
],
“documents”: [],
“gateway_tokens”: []
}
}

Hi @Amit.Panchal

You’ll want to use the statics route:

    Route::get('statics', 'StaticController');

This route will return all the meta data that the application relies on. Inside will be an array of countries.

Hi @david ,

Thanks for your prompt reply. We have java application and using Rest endpoints. We checked API Docs (Build, Collaborate & Integrate APIs | SwaggerHub), but couldnt find any endpoint related to statics. Could you please share the endpoint for statics, if available any.

Thanks,
Amitkumar Panchal.

@Amit.Panchal

I’ve updated the API docs here:

https://app.swaggerhub.com/apis/invoiceninja/invoiceninja/5.3.26

TLDR;

GET /statics

Hi @david
Perfect. Thank you.
We’ll have a look on it and come back to you in case of any difficulties.
Thanks,
Amitkumar