How to issue a Morning (Green Invoice) tax invoice or invoice-receipt automatically when a Pipedrive deal is won: the webhook that fires, the Morning token and document codes, the field mapping, and the guards that stop one deal from producing two invoices.
Key takeaways
- Pipedrive has no dedicated deal-won event: the trigger is a change.deal webhook plus a check that status became won and the previous block held another status.
- Morning issues the document through POST /documents; type 305 is a tax invoice and 320 a tax invoice-receipt, and the response returns the document id, number and download URL.
- Morning tokens come from POST /idp/v1/oauth/token with client credentials and last one hour; API keys are available on the Best plan and above.
- Duplicates come from Pipedrive retries, your own write-back, reopened deals and bulk edits, so key every job on the deal id and check before issuing.
To connect Pipedrive to Morning (Green Invoice), subscribe a Pipedrive webhook to change.deal. When a deal's status changes to won, your code finds or creates the client in Morning, issues a document through POST /documents - usually type 305, a tax invoice, or 320, a tax invoice-receipt - and writes the returned document number back to the deal.
Morning's integrations page does not list Pipedrive (checked September 2026), so this is a small integration you build or commission. Pipedrive is the sales pipeline; Morning is where the tax documents live. The part worth planning is not the API call itself but making sure one won deal produces exactly one document, with the right client details on it.
What does a Pipedrive to Morning integration actually do?
A working integration runs one short loop for every won deal, in this order:
- Receive the webhook. Pipedrive posts a
change.dealevent to your URL. Answer with a 2xx at once and queue the work. - Confirm it is a new win. Check that
data.statusiswonand that thepreviousblock carries a different status. Any other edit to a won deal is not a new sale. - Load the deal.
GET /api/v2/deals/{id}for the value and currency, andGET /api/v2/deals/{id}/productsif you sell line items. - Resolve the client. Read the linked person and organization, search Morning with
POST /clients/searchby email or name, and create the client withPOST /clientswhen nothing matches. - Issue the document.
POST /documentswithtype,lang,currency,vatTypeandincome- the five required fields. - Write back. Store the returned
numberand download URL on the deal withPATCH /api/v2/deals/{id}.
Which Pipedrive webhook should trigger the invoice?
Pipedrive has no dedicated "deal won" event. A webhook is defined by an event_action (create, change, delete or *) and an event_object such as deal, person or organization, so the invoice trigger is change.deal plus a status check in your code. Every edit to a deal, including a stage move or a rename, sends a change notification, and its previous block contains only the fields that changed.
Webhooks are created with POST /v1/webhooks, where version 2.0 is the default. Four details from Pipedrive's webhooks guide shape the design:
- The endpoint must answer within 10 seconds with a 2xx. Otherwise Pipedrive retries 3 more times, after 3, 30 and 150 seconds, and
meta.attempttells you which try you are looking at. - A webhook with no successful delivery on 3 consecutive days is deleted, so a broken receiver silently stops the whole flow.
- Each event is checked against the permissions of the webhook's
user_id. To see every won deal, create the webhook under an admin user. - The limit is 40 webhooks per user, and the endpoint can be protected with
http_auth_userandhttp_auth_password.
On the Pipedrive side, authentication is either an API token in the x-api-token header or OAuth 2.0 for a Marketplace app. The token belongs to one user, only one is active at a time, and regenerating it breaks every integration still using the old one.
How does the Morning side work?
Morning's API authenticates with OAuth 2.0 client credentials. You create an API key (an id and a secret) in Morning's developer settings, exchange it at POST https://api.morning.co/idp/v1/oauth/token with grant_type: client_credentials, and send the returned accessToken as a Bearer token. The token is valid for one hour and is scoped to the business that owns the key. Document calls go to https://api.greeninvoice.co.il/api/v1; the sandbox is https://sandbox.d.greeninvoice.co.il/api/v1, and each environment needs its own keys. Refreshing the token and telling a 401 from a 403 are covered in Morning API 401 and 403 errors.
According to Morning's help center, API keys are available on the Best plan and above. A key whose subscription does not include API access fails at the token endpoint with unauthorized_client.
This part is a technical description of the API, not accounting advice: which document your business issues for each kind of sale is a decision for your accountant. The document type is a number in the type field, and these are the codes a CRM sale usually touches:
| Code | Document | Where it appears in a CRM flow |
|---|---|---|
| 10 | Price quote | A deal reaches the proposal stage |
| 305 | Tax invoice | Deal won, payment expected later |
| 320 | Tax invoice-receipt | Deal won and already paid |
| 400 | Receipt | Payment arrives later against a 305 |
| 330 | Credit note | A won deal is reversed |
When a receipt follows an invoice, pass the invoice id in linkedDocumentIds and Morning closes the original invoice. One document holds up to 200 income and payment rows.
Mapping Pipedrive fields to a Morning document
Most of the mapping is direct. The tax id is the exception, because Pipedrive has no built-in field for it:
| Pipedrive (API v2) | Morning | Note |
|---|---|---|
| Deal title | income[].description | Or one row per deal product |
| Deal value and currency | income[].price, currency | 3-letter codes such as ILS, USD, EUR |
| Organization name, else person name | client.name | The only required field on POST /clients |
| Person emails | client.emails | Morning sends the document link to these |
| Custom field for the company or dealer number | client.taxId | Create it in Pipedrive before go-live |
| Custom field "Morning document" | Response number and url | Written back inside custom_fields |
In API v2, custom fields sit inside a custom_fields object, keyed by a 40-character hash that is different in every Pipedrive account. Copy each key from Company settings, Data fields, Copy API key, and keep the keys in configuration rather than code. person_id and org_id are plain ids in v2, so resolving the client costs two more calls. Store the Morning client id on the organization as well, and the next deal for the same customer skips the search entirely.
How do you stop one deal from producing two invoices?
A duplicate tax document cannot simply be deleted; it has to be reversed with a credit note. Duplicates come from four sources, and each needs its own guard:
- Pipedrive retries. A slow response means the same event arrives again. Key the job on the deal id and check your own store before calling Morning. The queue-and-worker pattern behind this is described in automating Morning (Green Invoice) documents.
- Your own write-back. Saving the document number on the deal fires another
change.deal. Itspreviousblock does not containstatus, which is how you tell it apart from a win. - Won, reopened, won again. A salesperson who reopens a deal and marks it won again produces a real status change. If the deal already carries a document number, route it to a person instead of issuing.
- Bulk edits.
meta.is_bulk_editflags events that came from a bulk change. Hold those for review rather than issuing dozens of invoices at once.
Rate limits matter less here than in a full sync, but they exist. Pipedrive gives each company a daily budget of 30,000 base tokens times a plan multiplier (Lite 1, Growth 2, Premium 5, Ultimate 7) times the number of seats, returns 429 once it is spent, and applies a burst limit per token on a rolling 2-second window: 20 requests for an API token on Lite, 40 on Growth. The v2 endpoints cost fewer tokens than their v1 versions.
What should you have ready before building?
- A Morning plan that includes API access and an API key. The secret is shown once, at creation.
- A sandbox account. Morning's help center says to set up a fictitious business there and make a fictitious Best purchase before a sandbox key can be created.
- Your accountant's written answer on which document type each deal outcome produces, and whether prices include VAT.
- Pipedrive custom fields for the client's tax id, the Morning client id and the Morning document number.
- An admin Pipedrive user to own the webhook, and a public HTTPS endpoint that answers in under 10 seconds.
If the invoice should be issued when money arrives rather than when a deal is won, the trigger belongs to the payment provider instead - see payment-to-invoice automation. For other CRM and invoicing combinations, see connecting invoicing software to a CRM.
Sources
Frequently asked questions
Can Pipedrive issue a Morning invoice automatically when a deal is won?
Yes, through a small integration. A Pipedrive webhook on change.deal reaches your server, the code checks that the status became won, creates the document with Morning's POST /documents, and saves the returned document number on the deal. Morning's integrations page does not list a ready-made Pipedrive connector.
Which Morning document type should a won Pipedrive deal create?
That is your accountant's decision, not a technical one. Technically, the type field takes a code: 305 is a tax invoice, 320 a tax invoice-receipt for a sale already paid, 400 a receipt and 330 a credit note. Put the chosen mapping in configuration so it can change without a code release.
Which Morning plan do I need to use the API?
Morning's help center says API keys are available on the Best plan and above. Without API access, the token request returns unauthorized_client. For testing, Morning offers a sandbox where you set up a fictitious business and a fictitious Best purchase, then create a separate sandbox key there.
Will the integration create duplicate clients in Morning?
Only if it creates a client for every deal. Search first with POST /clients/search by email or name, create with POST /clients only when nothing matches, and store the Morning client id in a custom field on the Pipedrive organization so the next deal for that customer reuses it.
How much does a Pipedrive to Morning integration cost to build?
It depends on the scope: a single won-deal trigger with a client lookup is a small project, while deal products, receipts linked to invoices and a review queue for reopened deals add work. The published ranges for integration projects like this one are on the pricing page at /pricing.
Keep reading
Related service
Custom CRM
A CRM built around your pipeline, connected to the tools you already use.
About the author
Yehonatan Saadia
Freelance automation, web & MVP developer
I'm Yehonatan Saadia, a senior developer who builds business automation, custom websites, and MVPs for small and mid-sized companies across the US, Europe, and Israel. These guides come from real client work, not theory.
Work with meHave a project like this?
Tell me what you're trying to automate or build. I reply within 24 business hours with a few targeted questions, then we walk through it on a free 30-minute call, with no commitment. You come away with a scope, a timeline and a fixed price - or a straight answer that it isn't worth building.
