/ /

Upload user profile images via B2B API

Updated 18 days ago

Overview

This guide walks you through uploading a profile photo or cover image for a user using Simpplr's B2B API. You will generate an access token, request an upload URL, upload the image file, and then attach it to the user's profile.

Note: You do not need to be a developer to follow along, but you will need access to Postman (or a similar API tool) and the Client ID and Client Secret for your integration.

Before you start:

As you go through the steps, you will collect a few important values. Keep a notepad open and save each one as you get it:

  • Client ID

  • Client Secret

  • Access Token

  • User ID (from the user's profile image URL)

  • File ID (returned after uploading the image)

⚠️Important: The access token expires after a period of time, and the upload URL is only valid for 5 minutes. Plan to complete the upload shortly after generating each one.

Step 1: Sign in and find your credentials

First, you'll need to sign in and find your Client ID and Client Secret.

  1. Log in through the Extensibility Center.

  2. Navigate to B2B APIs and open the Authorization section.

  3. From here, you can generate an access token directly.

Tip: The Client ID and Client Secret can also be found in your client application under: Application Settings > Application > Integration > Client Application

Step 2: Get an access token via Postman

If you'd prefer to generate your token using Postman instead of the Extensibility Center, follow these steps.

  1. Open Postman and create a new POST request to:

    https://platform.app.simpplr.com/v1/identity/oauth/token

  2. In the request body, add the following, replacing the placeholders with your own Client ID and Client Secret:

    {
      "grant_type": "client_credentials",
      "scope": "everything",
      "client_id": "Paste your Client ID from Client Application",
      "client_secret": "Paste your Client Secret from Client Application"
    }
    
  3. Click Send.

  4. The API will return an Access Token. Save this token securely, you'll need it in the upcoming steps.

Note: Every request from this point forward must include this token as a Bearer Token in the Authorization header.

Step 3: Generate an upload URL for the image

Next, you'll ask the API to generate a temporary upload URL for the user's photo or cover image.

  1. In Postman, create a new POST request to:

    https://platform.app.simpplr.com/v1/b2b/identity/users/files

  2. Under Authorization, add your Bearer Token from Step 2.

  3. In the request body, add the following, replacing the placeholder values with your own:

    {
      "useFor": "photo",
      "userId": "Paste the user id from user profile image url",
      "mimeType": "image/png",
      "size": 14197
    }
    
    • Set useFor to "photo" for a profile picture, or "coverImage" for a cover image.

    • userId is the ID found in the user's profile image URL.

    • mimeType should match the actual file type you're uploading (for example, image/png or image/jpeg).

    • size is the file size in bytes.

  4. Click Send.

  5. The response will include an upload URL and a file ID. Save both, you'll need the upload URL in the next step and the file ID in Step 5.

⚠️Important: The upload URL returned in this response is only valid for 5 minutes. Move on to the next step right away.

Step 4: Upload the image to the URL

Now you'll upload the actual image to the URL you just received.

  1. In Postman, create a new PUT request using the upload URL from Step 3.

  2. Under Authorization, add your Bearer Token.

  3. Attach your image file as the request body.

  4. Click Send.

Note: If the upload fails, check whether the 5-minute window has expired. If it has, repeat Step 3 to generate a new upload URL and try again.

Step 5: Apply the image to the user profile

Finally, attach the uploaded image to the user's profile.

  1. In Postman, create a new PATCH request to update the user (using the User Update API).

  2. Under Authorization, add your Bearer Token.

  3. In the request body, set one of the following fields using the file ID returned in Step 3:

    • photoFileId — for a profile photo

    • coverImage — for a cover image

  4. Click Send.

Once this completes successfully, the user's profile will display the new photo or cover image.

You're done! The user's profile image has been updated via the B2B API.

Important reminders

  • Include the Bearer Token in the Authorization header of every request.

  • The upload URL from Step 3 expires after 5 minutes.

  • Make sure the mimeType and size in Step 3 match the actual file you upload in Step 4.

Troubleshooting

The upload URL has stopped working

  • What happened: Upload URLs expire 5 minutes after they're generated.

  • What to do: Repeat Step 3 to request a new upload URL, then complete Step 4 right away.

Getting an authorization error

  • What happened: Your access token may be missing, expired, or incorrectly formatted in the request header.

  • What to do: Generate a new access token using Step 1 or Step 2, and make sure it's included as a Bearer Token in every request.

The profile image isn't appearing

  • What happened: This usually means the User Update API call in Step 5 didn't complete, or the wrong field (photoFileId vs. coverImage) was used.

  • What to do: Confirm you used the correct file ID from Step 3, and that you set the right field for what you're uploading.

Getting a 400 Bad Request error

  • What happened: This is usually caused by a missing or incorrectly formatted parameter in the request body, such as an invalid mimeType, a size value that doesn't match the actual file, or a malformed userId.

  • What to do: Double-check the JSON body against the required fields in Step 3, and confirm the values are accurate before sending the request again.

The Client ID or Client Secret isn't working

  • What happened: These credentials may have been copied incorrectly, contain extra spaces, or the client application may no longer be active.

  • What to do: Go back to Application Settings > Application > Integration > Client Application and re-copy the Client ID and Client Secret carefully, then generate a new access token.

The uploaded image doesn't match what you expected (wrong file or corrupted image)

  • What happened: This can happen if the file sent in Step 4 doesn't match the mimeType or size declared in Step 3, or if the file was altered before the PUT request was sent.

  • What to do: Confirm the file you're uploading matches the exact mimeType and size values submitted in Step 3, and repeat Steps 3 and 4 with the correct file if needed.

Frequently asked questions

Q: What does this API actually do? Ans: It allows you to upload and set a profile photo or cover image for a user using Simpplr's B2B API, without needing to use the Simpplr UI.

Q: How long is the access token valid? Ans: The exact duration can vary. To avoid issues, generate a fresh token before starting a new upload session.

Q: How long do I have to upload the image after requesting the upload URL? Ans: 5 minutes. If it expires, simply request a new upload URL and try again.

Q: Where do I find the Client ID and Client Secret? Ans: In your client application, under Application Settings > Application > Integration > Client Application.

Q: Where do I find the User ID? Ans: From the user's profile image URL.

Q: Can I upload both a profile photo and a cover image for the same user? Ans: Yes. Repeat Steps 3 through 5 once for the photo (useFor: "photo", then photoFileId) and once for the cover image (useFor: "coverImage", then coverImage).

Q: Which HTTP method do I use to upload the image itself? Ans: A PUT request to the upload URL returned in Step 3.

Was this article helpful?
Subscribe to receive updates on this article