Return Methods
There are multiple return methods that help you determine the status of your request.
Common Methods
These methods are supported across all methods
These methods are available in the base response class and commonly used across all response types.
-
isSuccess(): Checks if the operation was successful. This method should be implemented by subclasses to define what constitutes success for their specific response type. -
getFullResponse(): Returns the complete, raw JSON response from the API. Useful for debugging or accessing other data not directly exposed by this class's properties. -
getErrorMessage(): Retrieves a descriptive error message if the operation failed. It parses theerrorfield from the full response to return a human-readable message, or a generic message if no error is found. -
getErrorCode(): Gets the numeric error code from a failed operation. Returns thecodefield from the error object in the API response, or0if the operation was successful. -
getErrorType(): Gets the type of error from a failed operation. Returns thetypefield from the error object in the API response, or an empty string if the operation was successful. -
getErrorSubcode(): Returns the Graph API error subcode, ornullwhen the API did not include one. -
getFbtraceId(): Returns Meta'sfbtrace_idfor support requests, ornull.
Messages Methods
These methods are specific to other response types such as messaging, templates, etc.
-
getMessageId(): Returns the unique ID of the sent message. -
getContactId(): Returns the WhatsApp ID of the recipient contact.
Media Methods
These methods are specific to media-related operations such as uploading, getting, or deleting media.
-
getMediaId(): Returns the WhatsApp ID of the uploaded or retrieved media. -
getMediaUrl(): Returns the full URL of the media. -
getMediaMimeType(): Returns the MIME type of the media. -
getMediaSha256(): Returns the SHA-256 hash of the media. -
getMediaFileSize(): Returns the file size of the media. -
isDeleted(): Checks if the media was deleted successfully. This method is deprecated and should be replaced withisSuccess(). It returns the result of callingisSuccess(). -
isUploaded(): Deprecated. CallsisSuccess()and returns the result.
Media download methods
Available on the response from downloadMedia and downloadMediaById.
-
getBytes(): Returns the downloaded bytes asUint8List. -
getBytesCopy(): Returns a defensive copy of the downloaded bytes. -
getMimeType(): Returns the MIME type reported by the server. -
getFileName(): Returns the file name inferred from the media URL. -
getLength(): Returns the number of downloaded bytes. -
getStatusCode(): Returns the HTTP status code of the download.
Business Account Methods
These methods are specific to other response types such as messaging, business accounts, and user management.
-
getAbout(): Returns theaboutfield value or an empty string. -
getAddress(): Returns theaddressfield value or an empty string. -
getDescription(): Returns thedescriptionfield value or an empty string. -
getEmail(): Returns theemailfield value or an empty string. -
getProfilePictureUrl(): Returns theprofilePictureUrlfield value or an empty string. -
getVertical(): Returns theverticalfield value or an empty string. -
getWebsites(): Returns the list of websites, or an empty list.
Phone Number Methods
Available on the response from getPhoneNumber().
-
getId(): Returns the phone number ID. -
getDisplayPhoneNumber(): Returns the display phone number. -
getVerifiedName(): Returns the verified business name. -
getQualityRating(): Returns the quality rating (GREEN,YELLOW,RED). -
getPlatformType(): Returns the platform type. -
getCodeVerificationStatus(): Returns the code verification status. -
getNameStatus(): Returns the display-name status. -
isOfficialBusinessAccount(): Returns whether the number is an official business account. -
getThroughput(): Returns throughput details. -
getWebhookConfiguration(): Returns webhook configuration details.
Users Block/Unblock Methods
-
isSomeSuccess(): Returnstruewhen at least one user in the batch failed, indicating a partial result. -
getUsersList(): Returns the list of blocked users. -
getCursorBefore(): Returns the cursor for pagination to get the previous page of results. -
getCursorAfter(): Returns the cursor for pagination to get the next page of results.
Resumable Methods
-
getId(): Returns the id of created resumable upload session. -
getH(): Returns thehid of uploaded image. -
getFileOffset(): Returns the file size in bytes of created resumable upload session.
Exceptions
Non-2xx responses throw typed exceptions instead of returning an error response:
WhatsAppAuthenticationException: HTTP 401/403 or Graph error code 190.WhatsAppValidationException: Invalid request parameters.WhatsAppRateLimitException: HTTP 429 or rate-limit error codes.WhatsAppServerException: HTTP 5xx responses.WhatsAppException: Any other API error. ExposesstatusCode,errorCode,errorSubcode,fbtraceIdanddetails.NetworkException: DNS, socket, TLS, timeout or browser CORS failures.JsonFormatException: The API returned an unexpected body.