Send a WhatsApp location message via API

Send a location pin through the CRPRO Hub: latitude and longitude as numbers, optional name and address, validation ranges and handling an incoming pin.

A location message drops a pin on the customer's map: a store, a pickup point, a meeting place. It is one of the simplest payloads in the API, and one of the easiest to get subtly wrong, because latitude and longitude are numbers with ranges, not strings. This tutorial sends a location through the CRPRO Hub, shows the validation the Hub applies, and explains what to do on the receiving side.

What is the payload for a location message?

Short answer: type is location, and the location object holds latitude and longitude as numbers, with an optional name and address.

Meta's location reference lists four fields: latitude and longitude in decimal degrees, and optional name and address. The Hub uses the same four. Unlike Meta's own payload, the Hub body does not include messaging_product or recipient_type; its schema is strict and refuses fields it does not define.

curl -X POST https://crprohub.com/api/v1/channels/CHANNEL_UUID/messages \ -H "Authorization: Bearer hub_pk_EXAMPLE_NOT_REAL" \ -H "Idempotency-Key: pickup-point-1042" \ -H "Content-Type: application/json" \ -d '{ "to": "5521999999999", "type": "location", "location": { "latitude": -22.9068, "longitude": -43.1729, "name": "Pickup point", "address": "Example Street 100, Rio de Janeiro" } }'

The reply is the standard 202 with a message_id and the status accepted. Delivery progress arrives later through message.status events, exactly as for text.

What does the Hub validate?

Short answer: latitude must be a number between -90 and 90, longitude a number between -180 and 180, and name and address may each be up to 1,000 characters.

FieldRequiredRule in the Hub schema
location.latitudeYesNumber, -90 to 90
location.longitudeYesNumber, -180 to 180
location.nameNoUp to 1,000 characters
location.addressNoUp to 1,000 characters

A coordinate sent as a string, for example '-22.9068', fails validation with 400 INVALID_MESSAGE. This happens easily when values are read from a form, a CSV or a database column typed as text, so convert them before building the payload. Swapped coordinates are a quieter problem: a latitude of -43.17 and a longitude of -22.90 are both inside the allowed ranges, so the request passes and the pin lands in the middle of the ocean. No validator can catch that, which is why the order should be fixed in one helper function and covered by a test.

// Build the payload in one place so the order never drifts function locationMessage(to, { lat, lng, name, address }) { const latitude = Number(lat) const longitude = Number(lng) if (!Number.isFinite(latitude) || latitude < -90 || latitude > 90) { throw new RangeError(`latitude out of range: ${lat}`) } if (!Number.isFinite(longitude) || longitude < -180 || longitude > 180) { throw new RangeError(`longitude out of range: ${lng}`) } return { to, type: 'location', location: { latitude, longitude, name, address } } }

How should name and address be filled?

Short answer: name is the title of the pin and address is the line below it. Fill both when the customer needs to recognise the place, and at least name when the address is long.

Both are optional, and a message without them shows only the coordinates and a map. For a store or a pickup point, the name gives the customer a label to tap in the chat, and the address gives readable text they can copy into another app. Keep the address in the format used locally; the field is free text, so the platform does not parse or check it. Remember that a customer on a slow connection may see the text before the map tile loads, so the text should stand on its own.

How does an incoming location reach your system?

Short answer: as a message.received event whose content block has type location and a populated location field. The raw Meta message is also included.

The Hub's normalized inbound event contains a content object with a location entry, next to text, media and interactive. When a customer shares a pin, that entry is filled in, so a handler that only reads the text field would treat the message as blank. Pick the branch by content.type, and read coordinates from the location entry. The payload modes and fields are described in the webhooks reference, including how meta_raw delivers Meta's untouched body for anyone who prefers it.

function handleInbound(event) { const c = event.data.content if (c?.type === 'location' && c.location) { // use the fields exactly as documented in the Hub webhooks reference return { kind: 'location', raw: c.location, from: event.data.from } } return { kind: 'other', text: event.data.text } }

How can a location helper be tested without sending anything?

Short answer: test the function that builds the payload, not the network call. Feed it a place whose coordinates you know and assert on the exact object it returns.

The failure modes of this message type are all on your side of the wire: strings instead of numbers, swapped axes and out-of-range values. Each of them can be caught by a handful of unit tests that never touch the API. One test asserts that numeric strings are converted, one that a latitude of 120 throws, and one that a known city lands at the expected pair in the expected order. Once those pass, a single live send to a test number confirms the pin looks right on a real phone.

import test from 'node:test' import assert from 'node:assert/strict' test('builds a numeric payload in latitude, longitude order', () => { const m = locationMessage('5521999999999', { lat: '-22.9068', lng: '-43.1729', name: 'Pickup point' }) assert.equal(m.location.latitude, -22.9068) assert.equal(m.location.longitude, -43.1729) }) test('rejects an out-of-range latitude', () => { assert.throws(() => locationMessage('5521999999999', { lat: 120, lng: 0 }), RangeError) })

A sensible Idempotency-Key for a location is the business reason for the pin, such as pickup-point-1042. If the pickup point changes and the customer must receive a new pin, include a version in the key, otherwise the retry protection replays the original response and sends nothing.

What else limits a location message?

Short answer: it is a free-form message, so it needs an open 24-hour window, and the Hub's general limits apply: 60 sends per minute per channel and 120 requests per minute per organization and credential.

Meta's location page also does not describe a location request message, so this tutorial does not cover one; if you need to ask a customer for their position, ask in text and handle the pin they send back. Outside the service window, a location cannot open a conversation. Use an approved template to reach the customer first, as explained in the quickstart for authenticated sends in general.

When is a location message the right choice?

Short answer: when the customer must find a physical place and you know its coordinates, such as a store, a pickup point or an event venue.

A pin removes the translation step from an address: the customer taps it and their maps application opens with directions. It is less useful when the place is approximate or when the customer needs a route description rather than a destination. In those cases, text with landmarks is clearer. A location message also pairs well with a short text that states the opening hours or the entrance to use, since the pin itself carries only a name and an address. Because it is a free-form message, plan the same window handling as for any other non-template message.

  • Use exact coordinates from a reliable source, not from a rounded value typed by hand.
  • Give the pin a recognisable name; do not leave it blank for public places.
  • Follow the pin with a short text for hours or access details.
  • Keep one source of truth for coordinates so branches do not drift.
  • Test on both major mobile platforms, because maps applications differ.

Frequently asked questions

Can latitude and longitude be sent as strings?

No. The Hub schema requires numbers, and a string value is refused with 400 INVALID_MESSAGE. Convert text input with Number() and check the range before sending.

Are name and address required?

No. Only latitude and longitude are required. Without name and address the customer sees the pin and a map, which is enough for a rough meeting point but weaker for a store.

Why does a location land in the wrong country?

Most often latitude and longitude were swapped. Both values pass range validation when they are small enough, so the API accepts the request. Centralise the payload construction and add a test with a known place.

Can a location be sent outside the 24-hour window?

Not as a free-form message. Outside the window only templates can start the conversation. After the customer replies, the location message is allowed again.

Fontes

Documentação oficial da Meta, conferida em 31 de outubro de 2026.