cancel
Showing results for 
Search instead for 
Did you mean: 

c# / vb.net magento 2.0.7 SOAP product creation problem

c# / vb.net magento 2.0.7 SOAP product creation problem

Dear colleagues!

When I try to create product in Magento 2.0.7 CE using SOAP, vb.net and "CatalogProductRepositoryV1SaveRequest" I get a message - "Unable to save product". In the same time I can read any product fields and attributes and change them if product exist. API only provide me DeleteEntity, GetList Entity, and Save Entity. Unfortunately, I did not find nothing useful in internet.


My code is here:

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim accessToken As String = "g7rvo6kkef82uwv5isvwokk3n2123456"
Dim request As ServiceReference1.CatalogProductRepositoryV1SaveRequest
Dim product As ServiceReference1.catalogProductRepositoryV1PortTypeClient
Dim hrmp As HttpRequestMessageProperty
Dim contextScope As OperationContextScope
Try
product = New ServiceReference1.catalogProductRepositoryV1PortTypeClient
product.Endpoint.Binding = New BasicHttpBinding
hrmp = New HttpRequestMessageProperty
hrmp.Headers.Add("Authorization", "Bearer " + accessToken)
'hrmp.Method = "POST"
contextScope = New OperationContextScope(product.InnerChannel)
OperationContext.Current.OutgoingMessageProperties(HttpRequestMessageProperty.Name) = hrmp
request = New ServiceReference1.CatalogProductRepositoryV1SaveRequest()
Dim t As New CatalogDataProductInterface()
'Dim t As New CatalogInventoryDataStockItemInterface()

t.attributeSetId = 4
t.attributeSetIdSpecified = True
t.createdAt = t.updatedAt = DateTime.Now.ToShortDateString()
t.id = 0
t.idSpecified = False
t.name = "тестовый продукт"
t.price = 111.11
t.priceSpecified = True
t.sku = "111111"
t.status = 1
t.statusSpecified = True
t.typeId = "simple"
t.visibility = 4
t.visibilitySpecified = True
t.weight = 0
t.weightSpecified = False

Dim m(15) As FrameworkAttributeInterface
m(0) = New FrameworkAttributeInterface
m(0).attributeCode = "description"
m(0).value = "some item for electric"
m(1) = New FrameworkAttributeInterface
m(1).attributeCode = "meta_title"
m(1).value = "Test product"
m(2) = New FrameworkAttributeInterface
m(2).attributeCode = "meta_keyword"
m(2).value = "Test product"
m(3) = New FrameworkAttributeInterface
m(3).attributeCode = "meta_description"
m(3).value = "some item for electric"
Dim p(4) As String
p(0) = "2"
p(1) = "46"
p(2) = "110"
p(3) = "47"
p(4) = "109"
m(4) = New FrameworkAttributeInterface
m(4).attributeCode = "category_ids"
m(4).value = p
m(5) = New FrameworkAttributeInterface
m(5).attributeCode = "options_container"
m(5).value = "container2"
m(6) = New FrameworkAttributeInterface
m(6).attributeCode = "required_options"
m(6).value = "0"
m(7) = New FrameworkAttributeInterface
m(7).attributeCode = "has_options"
m(7).value = "0"
m(8) = New FrameworkAttributeInterface
m(8).attributeCode = "msrp_display_actual_price_type"
m(8).value = "0"
m(9) = New FrameworkAttributeInterface
m(9).attributeCode = "url_key"
m(9).value = "111111"
m(10) = New FrameworkAttributeInterface
m(10).attributeCode = "tax_class_id"
m(10).value = "2"
m(11) = New FrameworkAttributeInterface
m(11).attributeCode = "kod_tovara_proizvoditelja"
m(11).value = "2222"
m(12) = New FrameworkAttributeInterface
m(12).attributeCode = "proizvoditel"
m(12).value = "227"
m(13) = New FrameworkAttributeInterface
m(13).attributeCode = "strana_proishozhdenija"
m(13).value = "230"
m(14) = New FrameworkAttributeInterface
m(14).attributeCode = "srok_postavki"
m(14).value = "12"
m(15) = New FrameworkAttributeInterface
m(15).attributeCode = "kolichestvo_na_sklade"
m(15).value = "10"
t.customAttributes = m
request.product = t

Dim MyRez As New ServiceReference1.CatalogProductRepositoryV1SaveResponse
MyRez = product.catalogProductRepositoryV1Save(request)

Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Attention!")
End Try
End Sub

 

Please help to solve problem.
Alexander.

1 REPLY

Re: c# / vb.net magento 2.0.7 SOAP product creation problem

Solved.

After commet this strings:

't.status = 1
't.statusSpecified = True

 

Product was created (unfortunately - without price - looks like not enough some data) - continue check.