Update a MassPay user

Building the update request

When building your Update request you'll need to use 1 out of these 5 fields:

  • walletId - The identifier for the wallet
  • name - Updated identifier for the user
  • callbackUrl - Updated child wallet callback url
  • notes - Updated notes about the user
  • verificationData - Updated KYC information about the user

Api Endpoint

https://api.sendwyre.com/v2/wallet/{walletId}/update

Params

keytypedescriptionrequired
walletIdStringID of wallet to updatetrue
nameStringUpdated identifier for the userfalse
callbackUrlStringUpdated callbackfalse
notesStringUpdated notesfalse
verificationDataObjectUpdated KYC informationfalse
{
	"firstName":"{users-first-name}",
  "middleName":"{users-middle-name}",
  "lastName":"{users-last-name}",
  "ssn":"0000",
  "passport":"https://s3.amazonaws.com/100175/735051/PassPortFINAL.pdf",
  "birthDay":"1",
  "birthMonth":"1",
  "birthYear":"1970",
  "phoneNumber":"+15555555555",
  "address": {
    "street1":"1 Market Street",
    "street2":"Suite 420",
    "city":"San Francisco",
    "state":"CA",
    "postalCode":"94109",
    "country":"US"
  }
}
curl -v -XPOST 'https://api.sendwyre.com/v2/wallet/{wallet-id}/update' \
	-H "Content-Type: application/json" \
  -H "X-Api-Key: {api-key}" \
  -H "X-Api-Signature: {signature}" \
	-d '{"name":"{your-unique-identifier}","notes":"Updated notes about the sub account"}'
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.Integer;
import java.lang.String;
import java.lang.StringBuffer;
import java.net.HttpURLConnection;
import java.net.URL;

public class Main {
	public static void main(String[] args) {
		String accountId = "k3f48j0rb2rp65c0sdog67vi43u80jas";
		String apiKey = "fll36l3t35udalcqlh4ng6bm4qpbgher";
		String secretKey = "tr3epinbk3maist0n3ijk18bm6dikrq6";
	
    String walletId = "{wallet-id}";
    
		String url = "https://api.sendwyre.com/v2/wallet/"+ walletId +"/update";
		String method = "POST";
		String data = "";

		String result = excuteWyreRequest(url, "", method, apiKey, secretKey);
		System.out.println(result);

		data = "{" +
				"  \"name\":\"{your-unique-identifier}\"," +
				"  \"notes\":\"Updated notes about the user\"" +
				"}";
		result = excuteWyreRequest(url, data, method, apiKey, secretKey);

		System.out.println(result);
	}

	public static String excuteWyreRequest(String targetURL, String requestBody, String method, String apiKey, String secretKey) {
		URL url;
		HttpURLConnection connection = null;
		try {

			targetURL += ((targetURL.indexOf("?")>0)?"&":"?") + "timestamp=" + System.currentTimeMillis();

			//Create connection
			url = new URL(targetURL);
			connection = (HttpURLConnection)url.openConnection();
			connection.setRequestMethod(method);
			System.out.println(connection.getRequestMethod());

			connection.setRequestProperty("Content-Type", "application/json");
			connection.setRequestProperty("Content-Length", Integer.toString(requestBody.getBytes().length));

			//Specify API v2
			connection.setRequestProperty("X-Api-Version","2");

			// Provide API key and signature
			connection.setRequestProperty("X-Api-Key", apiKey);
			connection.setRequestProperty("X-Api-Signature",computeSignature(secretKey,targetURL,requestBody));

			//Send request
			if(method.equals("POST")) {
				connection.setDoOutput(true);
				connection.setRequestMethod(method);

				DataOutputStream wr = new DataOutputStream(
						connection.getOutputStream());

				wr.writeBytes(requestBody);
				wr.flush();
				wr.close();
			}

			//Get Response
			InputStream is = connection.getInputStream();
			BufferedReader rd = new BufferedReader(new InputStreamReader(is));
			String line;
			StringBuffer response = new StringBuffer();
			while((line = rd.readLine()) != null) {
				response.append(line);
				response.append('\r');
			}
			rd.close();
			return response.toString();

		} catch (Exception e) {

			e.printStackTrace();
			return null;

		} finally {

			if(connection != null) {
				connection.disconnect();
			}
		}
	}

	public static String computeSignature(String secretKey, String url, String reqData) {

		String data = url + reqData;

		System.out.println(data);

		try {
			Mac sha256Hmac = Mac.getInstance("HmacSHA256");
			SecretKeySpec key = new SecretKeySpec(secretKey.getBytes(), "HmacSHA256");
			sha256Hmac.init(key);

			byte[] macData = sha256Hmac.doFinal(data.getBytes());

			String result = "";
			for (final byte element : macData){
				result += Integer.toString((element & 0xff) + 0x100, 16).substring(1);
			}
			return result;

		} catch (Exception e) {
			e.printStackTrace();
			return "";
		}
	}
}
#dependencies:
#python3
#pip3 install requests

import json
import hmac
import time
from requests import request

class MassPay_API(object):
    def __init__(self, account_id, api_version, api_key, api_secret):
        self.account_id = account_id
        self.api_url = 'https://api.sendwyre.com/{}'.format(api_version)
        self.api_version = api_version
        self.api_key = api_key
        self.api_secret = api_secret

    #authentication decorator. May raise ValueError if no json content is returned
    def authenticate_request(func):
        def wrap(self, *args, **kwargs):
            url, method, body = func(self, *args, **kwargs)
            params = {}
            timestamp = int(time.time() * 1000)
            url += '?timestamp={}'.format(timestamp)
            bodyJson = json.dumps(body) if body != '' else ''
            headers = {}
            headers['Content-Type'] = 'application/json'
            headers['X-Api-Version'] = self.api_version
            headers['X-Api-Key'] = self.api_key
            headers['X-Api-Signature'] = hmac.new(self.api_secret.encode('utf-8'), (url + bodyJson).encode('utf-8'), 'SHA256').hexdigest()
            print(headers['X-Api-Signature'])
            resp = request(method=method, url=url, params=params, data=(json.dumps(body) if body != '' else None), json=None, headers=headers)
            if resp.text is not None: #Wyre will always try to give an err body
                return resp.status_code, resp.json()
            return 404, {}
        return wrap

    @authenticate_request
    def update_user(self, walletId, name, callbackUrl, notes, verificationData):
        url = self.api_url + '/wallet/' + walletId + '/update
        method = 'POST'
        body = {'name':name}
        if callbackUrl:
            body["callbackUrl"] = callbackUrl
        if notes:
            body['notes'] = notes
        if verificationData:
          	body['verificationData'] = verificationData
        return url, method, body 

#USAGE Example
account_id = "YOUR_ACCOUNT_ID_HERE" #optional
api_key = "YOUR_API_KEY_HERE"
secret_key = "YOUR_SECRET_KEY_HERE"
api_version = "2"

#create Wyre MassPay API object
Wyre = MassPay_API(account_id, api_version, api_key, secret_key)

#create user and print result
http_code, result = Wyre.update_user(
  															"{wallet-id}",
                                "{your-unique-identifier}", 
                                None, #callbackUrl
                                "Updated notes for user",
                                None #verification data
																)
print(result)
users_srn = result['srn'] #grab our srn identifier for the user
Language