TSGGLOBAL Support sign in
Skip to page content
Browse TNID API docs

TNID API documentation Spam Reporting Features Create Spam Report

Create Spam Report

On this page

Use this endpoint to create a spam report for an unwanted SMS, MMS or call (createSpamReport on /user).

Use this endpoint to create a spam report.

The User GraphQL API is accessible at /user

  mutation (
	$fromNumber: String!
	$toNumber: String!
	$channelType: SpamReportChannelType!
	$timestamp: NaiveDateTime!
	$issueType: SpamReportIssueType
	$userNote: String
	$messageContent: String
	$metadata: JSON
  ) {
	createSpamReport (
  	fromNumber: $fromNumber
  	toNumber: $toNumber
  	channelType: $channelType
  	timestamp: $timestamp
  	issueType: $issueType
  	userNote: $userNote
  	messageContent: $messageContent
  	metadata: $metadata
	) {
  	id
  	fromNumber
  	toNumber
  	userNote
  	messageContent
  	channelType
  	issueType
  	status
  	createdAt
  	updatedAt
  	timestamp
  	metadata
  	user {
    	id
  	}
	}
  }

Example Code

Python

from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport

# Please note that this basic example won't work if you have an asyncio event loop running.
# In some python environments (as with Jupyter which uses IPython) an asyncio event loop is created for you.
# In that case you should use instead https://gql.readthedocs.io/en/latest/async/async_usage.html#async-usage
def user_create_spam_report(bearer_token, from_number, to_number, channel_type, timestamp, issue_type=None, user_note=None, message_content=None, metadata=None):
    transport = AIOHTTPTransport(
        url="https://api.staging.v2.tnid.com/user",
        headers={"Authorization": f"Bearer {bearer_token}"}
    )
    client = Client(transport=transport, fetch_schema_from_transport=True)

    query = gql(
        """
        mutation (
            $fromNumber: String!
            $toNumber: String!
            $channelType: SpamReportChannelType!
            $timestamp: NaiveDateTime!
            $issueType: SpamReportIssueType
            $userNote: String
            $messageContent: String
            $metadata: JSON
        ) {
            createSpamReport (
                fromNumber: $fromNumber
                toNumber: $toNumber
                channelType: $channelType
                timestamp: $timestamp
                issueType: $issueType
                userNote: $userNote
                messageContent: $messageContent
                metadata: $metadata
            ) {
                id
                fromNumber
                toNumber
                userNote
                messageContent
                channelType
                issueType
                status
                createdAt
                updatedAt
                timestamp
                metadata
                user {
                    id
                }
            }
        }
        """
    )

    params = {"fromNumber": from_number, "toNumber": to_number, "channelType": channel_type,
              "timestamp": timestamp, "issueType": issue_type, "userNote": user_note,
              "messageContent": message_content, "metadata": metadata}

    try:
        response = client.execute(query, params)
        print(f"Response OK: {response}")
        return response
    except Exception as e:
        print(f"Exception: {e}")


# Example usage:
token = "your_user_token"
user_create_spam_report(token,
                        "15555555555",
                        "16666666666",
                        "MMS",
                        "2023-10-31 11:30:00",
                        "SPAM",
                        "Note about the report",
                        "Original message content",
                        {"customField": "custom value"})