rest – Should I return user data in an authentication endpoint using JWT?

I implement an auth endpoint which takes an email and password and returns a JWT token.
Inside the JWT there is a payload containing the user ID.
Does it matter from a REST/JWT standards perspective which of these approaches I take?

  1. return the token and let the client request the /users/user_id resource on a callback with the decoded user_id and the token
  2. return the entire user object with the token from the /auth endpoint for the convenience of the client.

(my question is implementation/library agnostic and about the api-design pattern)

REST API: upload media with advanced custom fields (ACF)


I am trying to upload media via the REST API. I have successfully got it working, except for with the ACF data.


The media uploads successfully, but the acf fields are blank.


    const route = `${API_URL}media`;
    const job = await getJobByCode(job_code); // {id: 127, acf: {job_code: 'ABC123'}, date: "2020-11-25T08:45:47", date_gmt: "2020-11-25T08:45:47", guid: {…}, modified: "2020-11-25T08:45:47", …}

    files.forEach(async (file) => {

        console.log(file); // File {uid: "rc-upload-1606293933971-10", name: "20201122_142537.jpg", lastModified: 1606015658320, lastModifiedDate: Sun Nov 22 2020 14:27:38 GMT+1100 (Australian Eastern Daylight Time), webkitRelativePath: "", …}

        const formData = new FormData();
        formData.append('file', file);
        formData.append('acf.job_object', job);
        // formData.append('fields.job_object', job);

        const res = await fetch(route, {
            method: 'POST',
            headers: {
                Authorization: `Bearer ${token}`,
            body: formData,

        const data = await res.json();

        console.log(data); // {id: 131, date: "2020-11-25T08:50:53", date_gmt: "2020-11-25T08:50:53", guid: {…}, modified: "2020-11-25T08:50:53", acf: (), …}

        if (data.errors) {
            throw new Error('Error fetching API');

        return data;

sharepoint online – What is the payload to be sent for “ViewFields” parameter as part of consuming the SPO REST API?

I am trying to create a SharePoint list view through the SharePoint REST API, with a defined set of columns to be part of the view. The endpoint i am using is below:



URL:‘ListName’)/views Headers:

‘Accept’ – ‘application/json;odata=verbose’
‘Content-Type’ – ‘application/json;odata=verbose’
Body (JSON):



I get a JSON error, since this payload does not seem to be right. Need help in understanding how to create a view with specific fields through the SharePoint REST API.

Thanks, Yesh

magento2 – Magento 2 REST Api For Place Order gives “transaction declined” error after successful Payment For Payfort Payment Gateway

I am using Payfort extension to process credit Card Payments online for Payfort Payment Gateway. For Website it’s working Fine and Placing an order after successful payment.

But when i am trying to place an order via API after successful payment via it’s iOs/Android SDK.
It’s giving me this Error.

Transaction has been declined. Please try again later.

This is How i am passing each information i received from Payfort after Successful Payment in this API.




“billingAddress”: {
“city”: “Dubai”,
“countryId”: “AE”,
“customerAddressId”: “2885”,
“customerId”: “3438”,
“fax”: “+971521231234”,
“firstname”: “Test”,
“lastname”: “User”,
“postcode”: “1111”,
“region”: “Dubai”,
“regionCode”: “DXB”,
“regionId”: “597”,
“street”: [
“Street 44, Oud Maitha”
“telephone”: “+971521231234”
“cartId”: “24361”,
“paymentMethod”: {
“additional_data”: {
“amount”: “29995”,
“authorization_code”: “614835”,
“card_number”: “411111******1111”,
“card_holder_name”: “Test User “,
“customer_email”: “”,
“customer_ip”: “”,
“expiry_date”: “2102”,
“fort_id”: “169996200000452654”,
“is_active_payment_token_enabler”: false,
“merchant_reference”: “XXXXXXXX”,
“payment_option”: “VISA”,
“sdk_token”: “c85bf903408b45a19a194710a941607a”,
“token_name”: “82f62b316c3246908ba29c8f2e683f45”
“method”: “md_payfort”

I am getting “True” in the response of this API call.

Then, I am using Create Order API of Magento to Place an Order.




“paymentMethod”: {
“method”: “md_payfort”
“shippingMethod”: {
“additionalProperties”: {},
“carrier_code”: “freeshipping”,
“method_code”: “freeshipping”

After debug, i found that this error is coming from this file.


And it’s because the “execute” method in this class is sending the Payment request again to Payfort and they recieve the “Signature mismatch” error from Payfort because of the unauthorized request. It should not send the Payment request again to Payfort.
I am not able to figure out how to prevent Magento to make this Payment request and just Place the Order.

If anyone can help me out to solve this problem and place an order successfully would be really appreciated.

javascript – Dynamic REST Statements

Is there a way to dynamically create a REST call and specifically I am referring to the data: section of the call. If I get the terminology incorrect by all means keep me honest. I tried some things with no success. I looked at the __metadata portion and thought this was a key/value pair and tried some substitution with no luck. Same for the field:value pairs. Been poking around on stack to try to find something with no luck so far.

So, in the following REST example is there a way to “break out” the information following the __metadata in the brackets and also the field:value immediately after the brackets.

    type: 'POST',
    url: odataUrl, 
    contentType: "application/json;odata=verbose",
    processData: false,
    headers: {
            "Accept": "application/json;odata=verbose",
            //"If-Match": "*", 
            //"X-HTTP-Method": "MERGE"
    data: JSON.stringify(
        __metadata :{
        modname:'no name'**


I tried using the following with no luck as an example setting the variables outside the REST statement and replacing the metadata statement with the following vars.

var typetest={"type":"SP."+TargetListName+"ListItem"};
var savetst={Title:"projname",ver:'test',modname:'browsertest'};
     data: JSON.stringify(
          __metadata :{typetest},savetxt

Thanks for the help.

list – SharePoint REST API Get Choice Dropdown Index

I have a dropdown with 5 string values.

I can use following request to get string values of the dropdown for every list item:


Result is returned with this property:


“Moderate” is at index 4 in the dropdown list, can I get that index instead of text value?

Magento 2: Create REST POST webapi to read uploaded xml

I need quick help related to creating a POST web API which will accept XML(Multipart/form-data) and read the uploaded XML.

sharepoint rest api – how to add value in document library look up column when button is clicked

function UpdateDocsDetails() {
  var def = jQuery.Deferred();
  var itemPayload = "";
  var restSource = _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/getByTitle('DMSDocs')/Items(" + lastItem + ")";
  itemPayload = { "__metadata": { "type": "SP.Data.DMSDocsItem" }, "RequestID": _reqID};
  var dfd = jQuery.Deferred();
      url: restSource,
      method: "POST",
      contentType: "application/json;odata=verbose",
      data: JSON.stringify(itemPayload),
        "Accept": "application/json;odata=verbose",
        "X-RequestDigest": jQuery('#__REQUESTDIGEST').val(),
        "X-HTTP-Method": "MERGE",
        "If-Match": "*"
      success: function (data) {
        // alert("Success");
      error: function (err) {
        // alert("Error:");
  return dfd.promise();

this function is need to update the lookup column RequestID

function SaveDeferred(action) {
    var dialog = bootbox.dialog({
      title: 'Saving.......',
      message: '<p>Saving... <i class="fa fa-spin fa-spinner"></i></p>',
      closeButton: false
    var c = CheckForAttachment();
    if (c == true) {
      var p = createItem(action);
      p.done(function (res) {
        if (UpdateFlag == 0) {
          _reqID = res.get_id();
        var d = UpdateDocsDetails();
        d.done(function (_reqID) {
          console.log('Item created successfully!');
          if (UpdateFlag == 0) {
            var _nextNo = GetNextNumber();
            _nextNo.done(function (result___nextNo) {
              var Series = result___nextNo.d.results(0).Series;
              var StartingValue = result___nextNo.d.results(0).StartingValue;
              var LastUsedValue = parseInt(result___nextNo.d.results(0).LastUsedValue);
              if (LastUsedValue == 0) {
                LastUsedValue = LastUsedValue + 1;
              } else {
                LastUsedValue = LastUsedValue + 1;
              var _update_Title = UpdateTitle(_reqID, Series, LastUsedValue);
              _update_Title.done(function (result__updated) {
                var _udp_NoSeries = UpdateNextNumber(Series, LastUsedValue);
                _udp_NoSeries.done(function (result___udp_NoSeries) {
                  var msg = "Your request Submitted successfully!!";
                  bootbox.alert(msg + " Your request No is " + result__updated, function () {
                    window.location.replace("/sites/" + siteName + "/SitePages/DMSApprovedRequests.aspx");
       (result__udp_NoSeries) {
                console.log("Your request sent successfully!! Your request No is " + result__updated);
     (result__updated) {
   (result___nextNo) {
          else {
            bootbox.alert("Your request sent successfully!!", function () {
              window.location.replace("/sites/" + siteName + "/SitePages/DMSApprovedRequests.aspx");
      }); (ex, error) {
        console.log(ex + " " + error);
    else {
      return false;

this function when item saved in SharePoint list but my Page is stuck on saving dialog after UpdateDocs Details() called but not going further to next number update in function

Which is better Rest or PWA for app development

There few screenshot image for mobile apps that i want to build as app.I want to know should i use PWA and make app using or just go with simple rest Api. I am novice in magento world.