Example: Changing Languages

Spark API provides listing meta data labels in multiple languages (see the many "Listing Meta" pages in the API Services section). Supported languages vary per MLS.

  1. Authentication
  2. View available languages
  3. Retrieving a user's referred language
  4. Updating a user's preferred language

Step 1: Authentication

This example expects that you have already obtained an OAuth 2 authorization token to access a user's data. Read more on our Hybrid Authentication and OAuth 2 Authorization.

Step 2: View Available Languages

First, you'll need to consult the System Info: Languages service to see what languages are available for a given MLS, as any given language is not universally supported across all MLSs.
$ curl "https://sparkapi.com/v1/system/languages" -H "X-SparkApi-User-Agent: SparkAPIExamples" -H "Authorization: OAuth MY_OAUTH2_ACCESS_TOKEN" {} 
{
    "D": {
        "Success": true,
        "Results": [
          { 
              "en": {
               "Label" : "English"
              },
              "es": {
               "Label" : "Spanish"
              }
          }
        ]
    }
}

Step 3: Retrieving a user's preferred language

Next, we'll check out the Accounts: Locale subresource to see what the user currently has set for their preferred language. In this example, we find that the user will currently see English labels for their listing meta data.
$ curl "https://sparkapi.com/v1/accounts/20100000000000000000000000/locale" -H "X-SparkApi-User-Agent: SparkAPIExamples" -H "Authorization: OAuth MY_OAUTH2_ACCESS_TOKEN" {} 
{
    "D": {
        "Success": true,
        "Results": [
          { 
            "Language": "en"
          }
        ]
    }
}

Step 4: Updating a user's preferred language

Finally, we'll update the user's language to Spanish via the Accounts: Locale subresource.
$ curl "https://sparkapi.com/v1/accounts/20100000000000000000000000/locale" -H "X-SparkApi-User-Agent: SparkAPIExamples" -H "Authorization: OAuth MY_OAUTH2_ACCESS_TOKEN" {} -H 'Content-Type: application/json' -X PUT --data '{"D": { "Language": "esp" } }'
{
    "D": {
        "Success": true
    }
}